Skip to content
All problems

Design a distributed key-value store

depth · 45 min · senior/staff

Setting

Several internal teams need a shared, horizontally-scalable key-value store for session data and small cached objects — simple GET/PUT/DELETE by key, no query language, but it has to survive node failures without losing data or serving stale writes to the wrong client.

The ask

Design the storage layer: how keys are partitioned across nodes, how data is replicated, and how the system behaves when a node fails or the cluster is resized.

Constraints & scale

  • ~10K nodes at target scale, values up to 1 MB, ~1M ops/sec cluster-wide
  • Tunable consistency: callers can ask for strong reads on some keys and accept eventual consistency on others
  • A single node failure must not cause data loss or a client-visible outage; the cluster must keep serving during a rebalance
  • Adding or removing nodes should move a bounded, small fraction of keys, not reshuffle the whole keyspace
  • p99 GET latency < 10 ms

What a strong answer covers

Requirements → partitioning scheme (and why) → replication/consistency model → high-level diagram → 1–2 deep dives → trade-offs. Likely probes: consistent hashing and rebalancing cost, how you detect and handle a failed node, and what "tunable consistency" actually changes on the read/write path.

A 45-minute plan

  1. 0-5 min · Requirements
  2. 5-10 min · Estimates/API
  3. 10-25 min · High-level
  4. 25-40 min · Deep dive
  5. 40-45 min · Wrap

What to cover, in order

  1. Requirements
  2. Partitioning scheme (and why)
  3. Replication/consistency model
  4. High-level diagram
  5. 1–2 deep dives
  6. Trade-offs

Where the follow-up questions go

Pick one of these for your deep dive before the interviewer picks for you.

  • Consistent hashing and rebalancing cost
  • How you detect and handle a failed node
  • What "tunable consistency" actually changes on the read/write path

Key trade-offs

Decisions a strong answer weighs, and what pushes each one either way.

  • Consistency level and latency. Waiting for a majority of replicas on every read and write gives strong guarantees and pays the slowest replica in the quorum on each request. Reading or writing one replica is fast and can return stale data. Offering the choice per request lets callers pick, and makes you explain what each setting guarantees.
  • Replica count. Three copies survive one failure and a rebalance at a time with reasonable cost. Five tolerate more and cost more storage and write traffic. The number should follow how long a failed node stays down and how often a second failure overlaps.
  • Conflict resolution. Last-write-wins with timestamps is simple and silently drops one of two concurrent writes when clocks differ. Version vectors detect the conflict and push resolution to the application or a merge rule. Single-leader-per-key avoids conflicts and makes failover your problem.
  • Virtual nodes. Giving each machine many ring positions smooths load and makes moves small, and also makes membership state larger and rebuilds touch many peers at once. Fewer tokens are simpler and balance worse.
  • Failure detection and repair. Aggressive detection restores redundancy quickly and misfires on a slow network, causing needless data movement. Slow detection leaves less redundancy for longer. Repair can be on read, in the background, or by buffering writes for a down node, and each has a different cost and window of exposure.

Common mistakes

What goes wrong most often on this problem, and why it hurts.

  • Partitioning with a hash modulo the node count. Adding or removing one node reassigns nearly all keys, which is exactly what the resize requirement rules out.
  • Saying "replicate it" without naming a read and write rule. Without a quorum or leader rule, you cannot say what a reader sees after a write or after a failure.
  • Trusting clocks for ordering writes. Skew of tens of milliseconds is routine, so a later write can lose to an earlier one without anyone noticing.
  • Ignoring hot keys. Hashing spreads keys evenly, not traffic. One popular key can saturate its replicas while the rest of the cluster is idle.
  • Skipping the failure path. If you cannot say what happens to writes during a node outage and how the replacement catches up, durability is an assertion, not a design.

Graded on

Requirements & scoping · Estimation · API & data model · High-level architecture · Deep dive · Scalability & performance · Reliability & consistency · Trade-offs · Operability · Communication & drive

Ready to run this one for real?

Try this problem free

Your first session is free. Sign in, and you land on this brief, ready to start.