Scaling Reads
Read scaling is a sequence of decisions about cost and freshness.
What, why, when and how
What is it?
Scaling reads increases useful read capacity while preserving the required freshness and authorization behavior.
Why is it needed?
Popular queries can saturate storage through repeated work, large payloads or expensive joins.
When should I use it?
Use it after measurements identify read work as the bottleneck and different read paths have clear freshness needs.
When should I choose something else?
Do not add replicas to fix an oversized response or missing index. Asynchronous replicas are unsuitable for a read that must immediately observe a write unless the design supplies that guarantee.
How do I use it?
Reduce fetched columns and rows first, add indexes, then evaluate caching, replicas and materialized projections. Route strict reads to a suitable authority.
Can you show a concrete example?
A notice-list endpoint needs IDs, titles and status, not every recipient JSON object. Removing unused payloads reduces transfer and memory pressure before any cache or replica is added.
Read the diagram
List endpoint loads unused recipient payloads; Select only required columns; paginate rows; Less transfer and memory before adding replicas
Follow the detailed diagrams below to trace the additional state changes and failure cases behind these answers.
Read scaling is a sequence of decisions about cost and freshness. Begin by finding what each request actually does. A slow query, repeated identical work, and a geographically distant database require different fixes. Adding replicas before understanding the query can copy the same expensive work to more machines without solving its cause.
Learning goals
Measure expensive reads; optimize queries; indexes; replicas; cache layers; materialized views; read-your-writes; overload protection.
Reduce work before distributing it
An inbox query scans 10,000 rows to return 50. A suitable tenant/order index may let it visit a bounded range instead. First inspect predicates, result size, plans and row distribution. Adding a cache to an accidental unbounded query hides its cost until a miss or rebuild.
Consider primary version 8, replica version 7 and cache version 6. A public description may tolerate version 6 for a minute; a read immediately after the caller edits may need version 8. Route that session to the primary, wait for an applicable replication watermark, or explicitly return a stale representation. Merely adding read replicas cannot meet read-your-writes if the routing ignores lag.
edit committed: primary v8
ordinary browse: permitted bounded stale view
read-after-edit: primary or verified watermark >= 8
purchase: authoritative conditional reservation, regardless of display versionRead the diagram
edit committed: primary v8; ordinary browse: permitted bounded stale view; read-after-edit: primary or verified watermark >= 8; purchase: authoritative conditional reservation, regardless of display version
Denormalization/materialized views move repeated joins or aggregation to write-time work and need replay, delete and repair semantics. Bigger hardware can be cheaper than sharding when one store still fits. Replicas spread eligible reads; caches avoid repeated source work; partitioning can address dataset/owner pressure but adds fanout. Choose the next step from measured limits rather than applying every layer.
Show answer and explanation
Answer: With 100,000 reads/s and 99% hits, normal origin reads are 1,000/s; cache loss exposes 100 times that load. A 2,000/s source budget requires admission, coalescing and permitted degradation. This gate remains necessary even if the application has many replicas.
Step-by-step reasoning
1. Remove unnecessary work
Measure the expensive query, selected columns, number of round trips, and access plan. Fix N+1 lookups and add an index that matches the filter and ordering. Limit result sizes. A well-shaped query can delay a distributed redesign and simplifies every later layer.
2. Separate fresh reads from tolerant reads
Read replicas can serve browsing and reporting when bounded lag is acceptable. A user reading immediately after a successful write may need leader routing or a session consistency mechanism. Replica lag is time-varying, so a fixed delay is not a proof that every replica has caught up. State what happens when lag exceeds the product budget.
3. Cache repeated answers
Cache at the browser, edge, application, or object level according to who may share the answer. Include authorization context in keys where needed. Coalesce misses and bound origin concurrency so losing the cache does not destroy the primary store. Choose TTL and invalidation based on a freshness contract.
4. Precompute expensive projections
A materialized catalog or feed can move joins and ranking off the request path. Keep the authoritative data and the projection distinct. Record a watermark or version, make consumers replayable, and plan a backfill that does not mix incompatible schemas. Projection lag should be visible to both operators and, when relevant, users.
Contracts and state
The following sketch makes the decision boundary concrete. Field names and capacity assumptions are illustrative; adapt them to the stated product contract.
Read classes
A: account change confirmation -> authoritative owner
B: public catalog -> cache, then replica
C: daily report -> materialized projection
All classes: bounded deadline and bounded origin concurrencyWorked example
A catalog gets 10,000 reads/s and 100 writes/s. First index category and sort order. Then cache popular category pages for 30 seconds if the product permits it. Route the owner’s post-edit confirmation to the leader so their change is visible immediately. Add replicas for cold reads once measurement shows the leader’s read load is still the bottleneck. Each step has a named reason.
Failure walkthrough
A replica falls minutes behind while remaining reachable. A load balancer that checks only TCP health will continue routing stale reads to it. Monitor replay lag and remove unsuitable replicas from the fresh-read pool. Avoid sending all failed replica traffic to the leader without a limit; degrade optional pages or apply admission control instead.
Read the diagram
User commits profile edit → Replica has older version → Session carries write context → Route confirmation to owner → Later reads use caught-up replica
Decisions and trade-offs
| Mechanism | Reduces | Freshness implication |
|---|---|---|
| Index | Rows and pages examined | Same transactional source |
| Replica | Primary read load | May lag |
| Cache | Repeated computation | TTL/invalidation contract |
| Projection | Online join work | Asynchronous update lag |
Check your understanding
A profile update succeeds, but the next read shows the old name. Which read should be rerouted?
Show answer and explanation
Answer: The post-write confirmation read should use the authoritative owner or a replica proven to have applied the relevant write. Sending every read to the leader may be unnecessary, while waiting an arbitrary fixed interval does not prove catch-up.
Transfer to a new scenario
Move a frequently read catalog through increasingly costly scaling options, stating when each becomes justified.
A replica returns old data after a successful write. Which request should go to the leader?
Continue the connection
Study PostgreSQL and explain which guarantee from this lesson carries into that topic.
Choose the cheapest useful read path
Begin with the actual query plan and the shape of the response. An index, smaller result, or precomputed count can eliminate work before distributing it. Add read replicas when the workload tolerates their freshness behavior; route a read that must observe a recent write to an appropriate authority or use a version-aware mechanism.
A cache is worthwhile when requests reuse results. A million unique queries may have almost no hits and still consume memory. Materialized views move work from read time to update time, which helps repeated complex reads but introduces lag and rebuild responsibilities. CDN caching works particularly well for immutable public bytes; personalized responses need careful cache keys and authorization.
Estimate the amplification at each layer. A page that makes twenty internal calls can produce a large backend load even at modest page QPS. Batch compatible reads, bound fanout and avoid turning one slow dependency into a full-page timeout.
Read the diagram
Mechanism / Reduces / Freshness implication; Index / Rows and pages examined / Same transactional source; Replica / Primary read load / May lag; Cache / Repeated computation / TTL/invalidation contract; Projection / Online join work / Asynchronous update lag
Operational sketch
profile read -> indexed primary query
repeat-heavy profile read -> cache-aside
large dashboard join -> maintained projection
recent write requiring freshness -> authoritative readA tempting mistake
Replicas do not reduce write work and can amplify storage cost. A cache outage must have a bounded fallback; otherwise the normal high hit rate hides an origin that cannot survive misses.
Transfer exercise
When should you avoid adding a cache?
Show answer and explanation
Answer: When reuse is low, freshness requirements make invalidation disproportionately complex, or a straightforward query/index change already meets the target.
A profile update succeeds, but the next read shows the old name. Which read should be rerouted?
Your design draft
Clarify assumptions, explain your approach, and test the difficult cases. Save your draft, then compare it with the study notes.
Self-review checklist
Self-guided practice. Automated AI feedback and code execution are not connected.