Design a Distributed Cache
How the interviewer asks it
“Design an in-memory cache cluster used by many services: sharding, eviction, replication and hot keys.”
Want the full answer? Watch lesson 5 of the free system design course: a 21-minute video walkthrough of this question.
Typed drills are free and unlimited: the AI scores your answer against the outline below.
What the interviewer is looking for
- Caching patterns: cache-aside, read-through, write-through, write-behind, and which fits.
- Sharding with consistent hashing, and client-side versus proxy routing.
- Eviction policy (LRU or LFU) and TTLs.
- Stampede protection: request coalescing, jittered TTLs, stale-while-revalidate.
- Hot keys: local caches, key replication or splitting.
How to structure your answer
- 01
Requirements
Sub-millisecond reads, terabytes of data, eviction under memory pressure, survive node loss without a database meltdown.
- 02
Node design
Hash table plus LRU list per node, memory limits, TTL expiry.
- 03
Cluster
Consistent hashing ring; clients route directly or through a thin proxy.
- 04
Replication
Primary and replica per shard, asynchronous replication, failover by a coordinator.
- 05
Consistency with the database
Cache-aside with invalidate-on-write; explain the race and how a short TTL limits the damage.
- 06
Stampedes and hot keys
Single-flight on misses, jittered TTLs, and a small in-process cache for the hottest keys.
Best answers from candidates
No candidate answers yet. Type yours, and if it scores 6 or more you can show it here without your name.
Answers are shared by candidates, without names, after a privacy check. Add yours
Common mistakes
- Updating the cache on write instead of invalidating, and caching stale data in a race.
- Every key expiring at the same moment.
- Treating the cache as the source of truth.
Follow-up questions to expect
- One key gets a million reads a second.
- Add a second region.
Now answer it out loud
Max will ask you this exact question, listen to your answer, push on the weak spots with follow-ups like the ones above, and score you when you finish.
Practice with MaxFree: a 5-minute voice round and unlimited typed drills, with scored feedback. No card, and your camera is never recorded.
More system design interview questions
Preparing for this round? Read how to practice for a system design interview.