~20 minutes · Day 76 · system design · caching
Caching is the first serious move in many system-design interviews. The interviewer says, “reads are slow” or “the database is hot,” and a cache sounds obvious. The real interview is whether you can name the trade: faster reads, but more decisions about stale data, writes, misses, and evictions.
A cache trades freshness for speed — so decide explicitly what happens on a miss, on a write (write-through vs write-back), and on eviction (LRU vs LFU).
That sentence is the design. Do not just say “put Redis in front.” Say what the cache stores, when it is trusted, when it is refreshed, and what happens when memory is full.
System design uses the same script every time: requirements → estimate scale → API → data model → high-level boxes → deep-dive the bottleneck → failure modes. For caching, apply it like this:
GET /products/{id}. Writes look like PATCH /products/{id} from an internal admin service.product:{id}. Value: serialized product summary plus updated_at. Add a TTL so forgotten keys expire.This is a cache-aside shape: the application checks the cache first, reads the database on a miss, then fills the cache. AWS describes cache-aside and write-through as common database caching patterns in its Redis caching strategies whitepaper.
In a caching interview, the interesting component is the policy around the cache. Make three decisions out loud:
| Decision | Option | Trade-off |
|---|---|---|
| Miss | Cache-aside | Simple and cheap: only requested data enters cache. First request is slower because it hits both cache and database. |
| Write | Write-through | Update database, then update or evict cache. Safer freshness, but every write does extra work. |
| Write | Write-back | Write cache first and flush later. Faster writes, but more danger if the cache fails before flush. |
| Eviction | LRU | Evict least recently used keys. A strong default when recent access predicts near-future access. |
| Eviction | LFU | Evict least frequently used keys. Better when a few hot products are repeatedly requested. |
For product pages, a conservative answer is: cache-aside on reads, database-first write-through or cache invalidation on writes, TTLs for bounded staleness, and LRU unless metrics show stable hot keys. Redis documents LRU and LFU as built-in eviction policies; the important interview move is choosing based on the access pattern.
| Figure | Why you say it | Source |
|---|---|---|
| Hit rate = hits / (hits + misses) | This is the first health metric. If hit rate is low, the cache is not protecting the database. | Redis INFO stats |
| 80% hit rate at 10,000 reads/sec | The database now sees about 2,000 reads/sec instead of 10,000. That arithmetic is the point. | Derived from hit rate |
| Sub-millisecond cache reads | Memory-backed caches can make common reads much faster than disk-backed database reads. | AWS caching overview |
| ~200 microseconds network latency | A remote cache is fast, but not free. Too many round trips can erase part of the win. | Redis latency guide |
| Hundreds of thousands of requests/sec | A side cache can absorb hot reads that would otherwise overload the database. | AWS caching overview |
1. A product key is absent from cache. What should cache-aside do next?
2. Which write policy keeps the database authoritative?
3. Celebrity product pages keep getting reread daily. Which eviction choice protects them best?
4. The cache is down during a read-heavy spike. What is the safest first response?
Redraw the architecture diagram from memory on paper: client, application, cache, database, hit path, miss path, write path. Then explain the design out loud in 5 minutes as if to an interviewer. Your explanation must include these exact decisions: miss policy, write policy, eviction policy, and one failure mode.
For the encode step in your Notion tracker, write the invariant from this page in your own words. Keep it to one sentence.
Read AWS — Database Caching Strategies Using Redis: Caching patterns after your redraw, as the compare step. Focus on cache-aside and write-through; those are the two policies interviewers expect you to reason about first.
Stuck or curious? Ask your teacher (the agent) — that's what it's for.