Dev Skills

Design a distributed key-value store

Design a distributed key-value store. Get and put by key, data larger than one machine, survives machines failing, and configurable durability. You are building the database, not choosing one.

About this problem

“Design a distributed key-value store” is a hard-level problem in the building the storage itself family. You are not using a database. You are being asked to design one.

The key challenge: The slack here is not in the request path at all: a caller is waiting on every get and every put. All the slack lives in the background work, and the design succeeds by moving as much as possible into it.

Time budgets: Reads: milliseconds. Writes: milliseconds. Repair and rebalancing: hours.

The worked solution for Key-value store goes through why those budgets shape the design, stage by stage.

Before you start

You will work this in five timed stages. Here is what each one asks you to think about. None of it is the answer; the answers unlock in the workspace below once you have written your own.

  1. Stage 1 · Requirements · 5 min
    • Which operations? Get and put is a very different system from range scans.
    • What is the durability promise? That is the biggest decision here.
    • Is this one region or several?
  2. Stage 2 · Actors and lifecycle · 6 min
    • What has to happen on disk before you can say "committed"?
    • What does the system decide without being asked?
    • A node comes back after being away for an hour. What state is it in?
  3. Stage 3 · Numbers · 6 min
    • How many machines does 300 TB need, with replication?
    • What does waiting for a majority add to a write, in milliseconds?
    • How long does it take to rebuild one failed node?
  4. Stage 4 · High-level design · 12 min
    • How does a client find the node holding a key?
    • What does one node look like inside — what is on disk, and in what shape?
    • Where does agreement about membership live?
  5. Stage 5 · Deep dive and tradeoffs · 14 min
    • Two clients write the same key at once. Who wins, and how do you know?
    • A node fails. Walk through the next 18 hours.
    • What does adding 50 machines to a live cluster involve?
Prefer to read first? The worked solution, end to end →

Work it through

Five stages, gated. You write your answer for each stage before its model answer unlocks. That is the core of the method.

Loading your progress…

Done all five? The diagrams, numbers, trade-offs and follow-ups for this problem are on the worked solution page, to check your own design against.

Before you leave
Try this problem again in a week without reading anything. Comparing what you write then with what you wrote today shows you what stuck.
Stuck, or new to this?Read the full worked solutionAll five stages end to end, with the diagrams and the costs, written out the way you would say it. Best read after you have had a go.Read it →

How it is really built

Write your own answer first. Then read how teams who run this at scale describe it. Their constraints were real, and the write-ups often say what their choices cost.