Q17 · How do you design read-heavy workloads for maximum throughput?
Back to 24 Architecture Questions.
The question is not “add a cache”. The axis it turns on: where the read is answered from, and what the invalidation costs. Every layer between the write and the read buys throughput by selling staleness and by charging an invalidation fee on every write. The design is the routing table between them.
What the answer should contain
Make reads cheap where they are born before adding layers. Indexes that match the query, covering indexes that answer it, projections that select the page’s shape instead of the entity. The cheapest read is the one the database does not have to work for.
Route each read class to the cheapest layer inside its staleness tolerance. The tolerance comes from the product: profile pages tolerate minutes, prices tolerate seconds, payment status tolerates nothing. The routing table is the design; the infrastructure is just the enforcement of it.
Caches serve the shared and the hot. Shared answers (catalogs, configs, rendered fragments) and hot keys, with one request refreshing the key while the rest wait, and TTLs jittered so a fleet never expires together. Per-request data does not belong here no matter how read-heavy the system is.
Replicas serve everything that tolerates lag. They cost nothing in invalidation logic: lag is automatic, measurable, and routed around. Most read-heavy systems under-use their replicas because their read path never split its classes.
Read models serve the queries whose shape is far from the write shape. Search, feeds, dashboards: prebuilt, denormalized views fed by events from the service that owns the data. The invalidation cost is the pipeline itself: a rebuild is a replay, not a scramble. This is where the heaviest read paths end up, and it is the honest version of CQRS without the ceremony word.
Measure the ladder, not just the hit rate. p99 per read class, hit rate with a staleness check, and origin QPS as the number you defend. A cache with a 95% hit rate that serves a stale price is a liability with good statistics.
Ideas worth mentioning out loud
- “Read-heavy design is a routing problem: every read class has a staleness tolerance, and the architecture is the table that maps tolerances to layers.”
- The write path pays the invalidation bill that the read path collects. If the write rate is also high, the cache may cost more than it saves: run the arithmetic.
- The strongest move is often changing the question: serving a precomputed answer instead of computing one per request.
Follow-ups to expect
- What about read-your-writes? Route the user’s next read to the layer that has their write: the primary, or a replica that has caught up past the write’s position.
- Denormalization means update anomalies? Yes: that is the price, paid in the projection pipeline instead of at read time. It is the right trade for read-heavy.
- When does a read need the primary? Money and invariants: anything a decision then writes against, which takes a conditional write to stay safe.
Red flags in an answer
- Every read hits the primary.
- One cache key space with no per-class tolerance or invalidation story.
- A read model with no rebuild path.
- Throughput numbers quoted without the staleness tolerance they were bought with.
Sources
- Scaling Memcache at Facebook, Nishtala et al., NSDI 2013: the read ladder operated at the largest scale, including the lookaside and write-through choices made per data class.
- CQRS, Martin Fowler: the read-model pattern, with the counterweight this answer borrows: Fowler warns it fits specific read shapes and is harmful as a default. The heaviest-read-paths bullet should be read with that caveat attached.