Design a Distributed Cache

HardInfrastructureConsistent HashingEvictionReplicationConsistencyAbout 45 minutes

Design a distributed in-memory cache like Memcached or Redis Cluster that application servers use to cut database load: get, set with TTL, and delete. Plan for 1M operations per second, 2 TB of data, and sub-millisecond latency, with nodes added and removed without a big miss storm.

How the interview goes

Five phases, and questions the interviewer is likely to ask in each.

  1. 1. Requirements

    • Is losing cached data acceptable?
    • How stale may a cached value be?
    Show a hint

    Ask whether the cache may lose data, because that changes everything about replication.

  2. 2. High-level design

    • Client-side routing or a proxy?
    • How does the app use the cache relative to the database?
    Show a hint

    Clients need a stable way to map a key to a node.

  3. 3. Deep dive

    • What fraction of keys move when you add a node, and why?
    • How do you implement TTL expiry efficiently?
    Show a hint

    Think about how many keys move when the node count changes.

  4. 4. Scaling

    • A popular key expires and 10k requests miss at once. What happens?
    • How do you replace a dead node?
    Show a hint

    Many clients missing the same key at the same moment is its own problem.

  5. 5. Trade-offs

    • Replicate cache nodes or not?
    • Cache invalidation on write versus short TTLs?
    Show a hint

    Stale data and extra database load are the two costs to balance.

Practice this with an AI interviewer

Write your design doc with live diagrams while the interviewer asks one question at a time and pushes on your choices. Get a scored debrief with what to study next.

Start this interview