Lesson 23 / 32

Scaling Reads and Partitioning Strategies

Read replicas for read load; partitioning strategies for write load.

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 read replica
  • A local cache you just wrote
Answer

A read replica — Replication lag means a replica may not yet have the write that just committed on the primary.