Scaling Reads
Most systems are read far more than they are written. A product is listed once and viewed millions of times; a profile is edited monthly and opened every minute. This lesson is for software engineers preparing for system design interviews. It gives you an order of moves for a read-heavy system, from the cheapest to the most complex, so you can explain where reads go, what each step costs, and when to stop.
The building blocks have their own lessons: Caching in Depth, Choosing and Scaling a Database and Scaling Data. This lesson is about sequencing them under load.
Start with the numbers
Read scaling only makes sense once you know the read rate, and interviewers notice when you skip this step. A quick estimate for an online store:
2,000,000 daily active users x 30 product views each = 60,000,000 views/day
60,000,000 / 86,400 seconds ~ 700 views/s on average
peak at 5x average ~ 3,500 views/s
8 database queries per product page ~ 28,000 queries/s at peakThat last number is the one that matters. A single relational database on a large machine can serve tens of thousands of simple indexed lookups per second, and far fewer of the joins and sorts a real product page runs, so 28,000 per second of mixed queries is at or past the edge of one machine. The estimate tells you the problem is real, and it gives you a target to check each step against.
The order of moves
Apply these in order. Each one is cheaper to build and operate than the next, so you take the next step only when the numbers say the previous one is not enough. The order is by cost, not by payoff: a missing index fixed can be worth more than a fleet of replicas, which is exactly why it comes first.
1. Fix the queries before adding machines
Most slow reads are slow queries, not a lack of hardware. Three checks come first:
Index the access path. A product page that looks up reviews by
productIdneeds an index onreviews(productId, createdAt), so the database reads the newest 20 reviews directly instead of scanning the table. A composite index ordered to match the query's filter and sort is often a 100x improvement on its own.Remove the N+1 pattern. Loading 20 reviews and then querying each reviewer separately is 21 round trips. One join, or one
WHERE id IN (...)query for all reviewers, is two.Fetch only what the page shows. Selecting a 50 KB description column for a list view that shows titles wastes I/O and cache memory.
In the store example, collapsing 8 queries per page into 3 cuts peak load from 28,000 to about 10,500 queries per second without adding a server.
2. Denormalize what you read together
If every product page computes AVG(rating) and COUNT(*) over all reviews, store ratingAverage and reviewCount on the product row and update them when a review is written. You trade a slightly more complex write (a transaction that inserts the review and updates the product) for a read that touches one row. The cost is consistency you now maintain in code: if a review is deleted and the counter is not adjusted, the two disagree. A nightly job that recomputes the totals and corrects drift is a cheap safety net, and saying so out loud earns credit.
3. Add read replicas
Replicas copy the primary's data and serve reads, so read capacity grows roughly linearly with their count. The catch is replication lag: a replica is usually milliseconds behind, and seconds behind under heavy write load. That breaks read-your-writes. A user edits a product, refreshes, and sees the old price.
Two standard fixes: route a user's reads to the primary for a short window (say 10 seconds) after they write, or record the write's log position and only read from a replica that has caught up to it. Name one; interviewers ask about lag every time replicas appear. The mechanics are in Scaling Data.
4. Cache in front of the database
A cache absorbs repeated reads of the same data. If 95 percent of product reads hit the cache, the database sees 5 percent:
10,500 queries/s at peak x 5% miss rate = 525 queries/s reach the databaseOne cache cluster now shields the database almost entirely. The hard parts are invalidation and stampedes, covered in Caching in Depth. Static assets and public pages go one level further out, to a CDN, so many requests never reach your servers at all.
5. Precompute expensive reads
Some reads are expensive no matter how they are cached because each one aggregates a lot of data: "best sellers in this category this week", a user's personalized home page, a leaderboard. Compute them ahead of time. A job rebuilds the best-sellers list every minute and writes the result to a cache key or a small table; the page reads one precomputed row. The trade-off is freshness: the list is up to a minute old, which is fine for best sellers and wrong for a bank balance. State the staleness budget for each precomputed view.
6. Shard only when the data itself outgrows a machine
Replicas multiply read capacity but every replica still holds all the data. When the dataset or the write rate no longer fits on one primary, partition it. That is a write and storage problem more than a read one, so treat it as the last resort for reads. Scaling Writes covers it.
Hot keys: when one item gets all the traffic
Averages hide the real failure. A product goes viral, or a celebrity's profile is shared everywhere, and one key receives 100,000 reads per second. Every one of those reads lands on the single cache node that owns that key, and that node saturates while the rest of the cluster idles.
Two fixes, which combine well:
Local in-process cache with a short TTL. Each application server keeps the hottest keys in memory for one second and lets only one request per key refresh it. With 200 application servers, the cache cluster sees about 200 requests per second for that key, one per server per second, instead of 100,000. The price is up to one second of staleness per server, and servers can briefly disagree with each other.
Replicate the key. Store copies under
product:42#0toproduct:42#9and read one at random, spreading the load over ten cache nodes. Reads get ten times cheaper per node, but every update now writes ten keys, so use it for keys that are read constantly and changed rarely.
Detecting a hot key matters as much as handling it. Sampling request keys at the cache client and promoting any key above a threshold to the local cache is a strong, concrete answer.
Worked example: a product page during a flash sale
Prompt: "Our store's product page is slow at peak, and a flash sale next month will send 50 times normal traffic to ten products. Make it fast."
Weak answer: "Add Redis in front of the database and more replicas." It is not wrong, but it names tools without numbers, ignores the ten hot products, and says nothing about stale prices during a sale.
Strong answer, step by step:
Numbers. Normal peak is 3,500 page views per second. Fifty times that on ten products is 175,000 views per second, about 17,500 per product.
Queries first. Index reviews by
(productId, createdAt), batch reviewer lookups, and drop the description from list queries: 8 queries per page become 3.Denormalize rating and review count onto the product row.
Cache the product page data with cache-aside and a 5-minute TTL, deleting the key whenever the product is edited. At a 95 percent hit rate the database sees a few hundred queries per second outside the sale.
Hot keys. For the ten sale products, each application server holds the product data in process for one second, so the cache cluster sees about one request per server per second per product.
Separate stock from the page. Price and description can be a second old; the stock count cannot oversell. The page shows cached product data and fetches "in stock / low stock" from a separate, lightly cached endpoint, while the authoritative stock check happens at checkout against the primary. That keeps the read path fast without lying about inventory at the moment it matters.
CDN for images and the static page shell.
Against the scored dimensions: step 1 is requirements (scale pinned down before any box is drawn), steps 2 to 5 and 7 are deep dive and scalability (each move checked against a number, including the hot-key case averages hide), and step 6 is trade-offs (stock has a different freshness requirement from everything else on the page, so it gets a different path). The weak answer names the same tools and scores on none of them.
Follow-ups to expect
"A user changes a price and still sees the old one." Replica lag or a stale cache. Read from the primary for that user for a few seconds after a write, and delete the cache key on update.
"The cache cluster goes down. What happens?" Every miss hits the database at once. Rate-limit cache-miss queries, serve stale data where acceptable, and keep the database sized to survive a reduced, not full, load.
"How stale can this be?" Answer per field: seconds for a price, minutes for best sellers, zero for a bank balance.
"Why not just add replicas forever?" Each one adds replication load on the primary, cost, and another place lag shows up. Caching usually buys more per dollar for repeated reads.
What changes with seniority
A mid-level candidate is expected to name indexes, replicas and a cache, and to mention replication lag when asked. A senior candidate leads with the estimate, applies the moves in order, handles hot keys and read-your-writes without prompting, and sets a freshness budget per piece of data. A staff-level candidate adds operations: how you detect a hot key, how you warm a cache before a planned sale, and what the system does when the cache fails.
Mistakes that cost points
Reaching for a cache before fixing the query. A missing index cached is still a missing index on every miss.
Adding replicas without addressing lag. The first follow-up will be "the user doesn't see their own change".
Treating every field as equally fresh. Price, stock and best sellers have different budgets; one TTL for everything is a design smell.
Ignoring hot keys. Averages look fine until one item gets all the traffic.
Practice it
Spend 15 minutes estimating the read rate for an app you use daily, then list the order of moves you would apply and the freshness budget for its three most-read pieces of data. Then try Design a URL Shortener, a read-heavy problem where redirect traffic dwarfs link creation.
Practise this in a mock interview
Try what this lesson covers out loud: the AI interviewer asks one of these questions, follows up, and scores your answer.
- Design a URL ShortenerSystem Design · Medium
- Design a Rate Limiter ServiceSystem Design · Medium
- Design Live Score Alert FanoutSystem Design · Medium
- Design a Video Upload and Transcoding PipelineSystem Design · Medium
Read next
- Scaling Writes
Raise write capacity by writing less, splitting latest state from history, batching behind a durable log, sharding by the write key and splitting hot counters, and size bursts and backpressure with real arithmetic.
8 min read
- Real-Time Updates
Choose between polling, long polling, server-sent events and WebSockets, route each update to the server holding the recipient's connection, and handle ordering, reconnection, missed messages and presence.
7 min read
- Dealing with Contention: When Everyone Wants the Last Seat
Work out how many updates per second a hot row can take, then pick and defend the right fix: pessimistic or optimistic locking, atomic conditional updates, expiring holds, fenced distributed locks, queues or split stock.
8 min read
- Multi-Step Processes and Long-Running Jobs
Design flows that span services so they finish or cleanly undo themselves, with sagas, compensations, idempotent retries, the outbox pattern and durable workflows, and run long jobs with status, heartbeats and dead-letter queues.
8 min read
