LOAD-BEARINGfree
High-level designTier 4 · unit 6 of 7 · 12 min read

Replica or cache: choosing, not collecting

This tier taught you caching in 4.02 and read replicas in 4.04, and then did what most material does: left you holding two tools that solve the same sentence — "reads are too expensive" — with no way to pick. They are not interchangeable, and the choice is usually decidable in about a minute once you know what to ask.

They store different things

Start here, because everything else follows from it. A replica stores your data. A cache stores an answer.

A replica is the same schema, the same rows, a full second copy — so it can serve any query you have not written yet. A cache holds the result of a specific computation under a specific key, which may be a query result, or a joined and rendered object, or something that took four services and a template to produce. That is a capability a replica does not have at all.

The comparison that decides it
Read replicaCache
HoldsAll the data, same shapeOne answer per key, any shape
ServesAny queryOnly the keys you thought of
StalenessReplication lag, database's jobTTL and invalidation, your job
MissNo such conceptFull-cost read, plus the write
CostA full copy of everythingMemory for the hot set only
Losing itLost read capacity, degrade gracefullyStampede onto the origin

The bottom row deserves attention, because it is the one that shows up at 3am. A replica falling over removes capacity — the remaining nodes take more load and you notice. A cache falling over sends every request to the origin simultaneously, at a moment when the origin has been sized on the assumption that it would not have to. Lesson 4.02 named this the stampede; here it is the deciding factor in whether a cache is a load reduction or a load concentration waiting to happen.

The questions, in order

  1. Is the same answer requested repeatedly? The entire economics of a cache is hit rate. A hundred requests for one key is a cache. A hundred requests for a hundred different keys is a cache that costs memory and returns nothing — you paid for a miss every time and added a write. Check the shape of the distribution before you check anything else.
  2. Is the answer a query result, or something computed? If it is the product of a join across services, a rendered fragment, or an aggregate no single database can express, a replica cannot help you. That is cache-only territory.
  3. Are the queries known in advance? Ad-hoc queries, admin screens, support tools and reporting all want a replica. You cannot cache a query nobody has written.
  4. Does a cold start have to be survivable? After a deploy, a restart, or an eviction storm, a cache is empty and the origin takes everything. If the origin cannot survive that for thirty seconds, a cache has not reduced your risk — it has hidden it behind a hit rate.
  5. Which staleness is easier to reason about? Replication lag is bounded, measurable, and mostly the database's problem. Cache staleness is bounded by whatever invalidation logic you wrote, and invalidation is the failure mode people underestimate for their entire careers.

Usually both, in this order

The common production shape is not a choice at all: replicas for query capacity, a cache in front for the hot keys. The replica gives you the long tail and the queries nobody anticipated; the cache absorbs the handful of keys that would otherwise dominate. That combination is not a compromise or a sign of indecision — it is what a system looks like once both problems are real.

And two options people forget they have, both of which beat either tool when they apply:

  • Compute it at write time. A materialised view, or a denormalised column maintained on write (3.05). Reads become free and correctness is the database's problem rather than an invalidation policy you maintain. Right whenever writes are much rarer than reads.
  • Do not read at all. The fastest query is the one the screen no longer needs. Worth ten seconds of thought before adding infrastructure.

The honest way to frame the cost

Both tools hand you a class of bug, permanently, and it is fair to choose on that basis alone. A cache gives you invalidation: stale reads, thundering herds, and the special misery of a bug that only reproduces when the entry happens to be warm. A replica gives you lag: a user who writes and then does not see their own change, which Tier 4 named read-your-own-writes and which the database will help you with. Pick the one your team can debug at 3am, and be aware you are picking.

The trap

Adding a cache to fix a slow query. If the query is slow because an index is missing, the cache does make the dashboard green — and it also guarantees that the next cold start sends the full, unindexed load at the origin, at whatever moment the cache happened to empty. That is a deploy, or an eviction, or a Redis failover: exactly the moments when you have the least slack. Fix the query, then add the cache to reduce load. A cache is a multiplier on a system that already works, never a patch over one that does not.