Lesson 23 / 32
Scaling Reads and Partitioning Strategies
Scale reads with replicas and handle replication lag, then compare range, hash and directory partitioning strategies.
Read replicas
Adding read replicas off a single primary scales read throughput cheaply — but replication lag means a replica read can be milliseconds to seconds stale. Route read-your-own-write requests to the primary.
Partitioning strategies
Range partitioning (by date or ID range) keeps related rows together for range scans but risks hotspots on the latest range. Hash partitioning spreads load evenly but scatters range queries across shards. Directory-based partitioning uses a lookup service for full flexibility at the cost of an extra hop.
Branch libraries vs one warehouse
Read replicas are branch libraries holding copies of the same books — convenient, but a just-published book might not have reached every branch yet. Partitioning is splitting one huge warehouse into regional ones, each fully responsible for its own slice of inventory.
Quick check: Reading data you just wrote, immediately after, is most at risk of appearing missing when reading from:
- The primary
- A local cache you just wrote
- A read replica
- The CDN edge
Answer
A read replica — Replication lag means a replica may not yet have the write that just committed on the primary.