Skip to the guide

Design a distributed cache

IntermediateCase study12 pages

Here you build the cache itself, the service other teams put in front of their databases. It's a fleet of memory servers that answers in about a millisecond, where a dead machine costs misses, never data. Think of a cloakroom with many attendants, where every ticket says which one has your coat.

It's also asked as "design Memcached at scale", "design Redis Cluster" or "design a caching service". The closest page is Distributed caches at scale, which sizes a fleet a team uses; here you build that fleet, and this page continues its numbers. Interviewers like it because the API is a few calls, so the round goes straight to the hard parts. Where does a key live, what does a dead node cost the database, and what about the key everybody wants? The Key-value store is the durable cousin; here, losing a key only costs a miss.

Below is a full mock interview following the seven steps of the framework. You're the candidate: at each Guess before you read on, stop and answer first.

Step 1 · Clarify the features and cut the scope

Minutes 0–5 · How this step works

Interviewer: Design a distributed cache for our company.

You: Who uses it? One application, or many teams with their own databases?

Interviewer: Many teams. It's a platform.

You: Plain keys and values, or data structures like lists and sorted sets?

Interviewer: Keys and values with a TTL. Structures can come later.

You: Does the cache load from the database on a miss, or do the apps do that?

Interviewer: The apps. You don't know their databases.

You: And when a team's data changes, who tells the cache?

Interviewer: Most teams publish their database's change stream. Some delete keys themselves.

You: Then I'll cover get, set and delete with TTLs, routing, replication and failover, eviction per node, hot keys and invalidation from change streams. Out: persistence, data structures, cross-region replication of cached values and billing. OK?

Interviewer: Go ahead.

Each answer shapes the design: many teams mean pools with their own memory, and change streams give one place to drive deletes from.

Step 2 · Non-functional requirements

Minutes 5–8 · How this step works

You: Take the large social app's numbers from Distributed caches at scale: 1 million reads a second at peak, about 400,000 on average, 3 TB of hot data and a 99% hit rate. A get answers within 5 ms at p99 at the client: about 1 ms from the node's own zone, 2–3 ms from the other two. The cache answers, hit or miss, 99.99% of the time. A delete reaches every copy of a key within about 2 seconds, with the TTL as the backstop. Nothing is durable, but losing a node must never push the database past what it's built for.