Scaling reads: replicas, caches, CDNs and precomputed views
A city's tourist office has one expert who records every change in the archive, and a queue of visitors asking the same few things. It can add signs at the station, a walking-tour leaflet made once from many records, a card of top answers the desk clerk checks first, and assistants with copies of the archive. Each is faster than the expert, and each goes out of date in its own way.
Visitors are reads, the clerk is your server and the expert is the database leader; the rest are the CDN, the precomputed view, the cache and read replicas. Interviewers hear "add a cache" all day and listen for what each copy saves and how stale it gets. The move: answer each read from the cheapest copy that's fresh enough, so only its misses travel inwards.
The photo app at peak: 50,000 feed views a second, each with 10 thumbnails. 95% of them are already at the nearby CDN edge.
1 / 5When to reach for it
Thresholds are rules of thumb.
- Reads outnumber writes, 10 to 1 or more: a copy then rarely goes stale, though only the rate below says you need one.
- Reads approach what a database serves. A replica serves ~20,000 indexed lookups a second (a conservative planning figure; measure yours). Above ~2,000 a second at peak, a tenth of that, work the numbers out (Estimates that change the design).
- A latency target a database can't meet: p99 under 50 ms when a page makes several 10–20 ms reads.
- Far-away users, or bytes in bulk. Europe to California is ~150 ms a round trip, against ~15 ms to an edge that serves shared bytes.
- One read costs many lookups: a feed merging 200 accounts.
- A staleness the product accepts, stated as a time.