The System Design Newsletter

The System Design Newsletter

System Design Interview Question: Design a Distributed Key-Value Store

#208: Hash ring, quorums, and storage engine behind every distributed database, explained step by step

Hayk Simonyan's avatar
Neo Kim's avatar
Hayk Simonyan and Neo Kim
Dec 03, 2026
∙ Paid

Get my AI engineering playbook for FREE on newsletter signup:

  • Share this letter & I’ll send you some rewards for the referrals.


This letter will help you prepare for the system design interview.

Amazon built Dynamo so customers could keep adding items to their shopping cart while disks failed, servers crashed, and networks split.

The paper behind it came out in 2007, and its ideas still run inside Cassandra, Riak, and countless interview answers. Yet “design a key-value store” is one of the trickiest prompts you’ll get. The API fits on a sticky note, so the interviewer spends the entire hour on what happens when things break.

In this letter, you’ll design one from a single server to a multi-region cluster, in the same order you’d use in the interview.


If you want to achieve 99.99% uptime, read this:

Building reliable software starts with reliable infrastructure.

Synteq is a cloud compute provider built for high availability, with a 99.99% uptime target and its own data centers, racks, hardware, and network.

Here’s what you get:

  • High availability: VPS, bare metal, and GPU cloud designed to keep workloads running.

  • Predictable pricing: Flat monthly bills with no unexpected egress charges.

  • Fast deployment: Deploy in minutes using the portal or CLI.

  • Expert support: Get help directly from engineers, not ticket triage.

If you’re designing systems to survive failures, run them on infrastructure built with availability in mind.

CLAIM YOUR FREE MONTH ON SYNTEQ →

Exclusive to readers of this newsletter: Get your first month FREE!

(Thanks to Synteq for partnering on this newsletter.)


I want to reintroduce Hayk Simonyan as a guest author.

He’s a lead software engineer who helps engineers with 3+ years of experience move into senior, staff, and lead roles.

If you want to master system design and land a senior role, I highly recommend checking out Hayk’s YouTube channel, where over 150,000 engineers already learn it.


Here’s what’s inside:

  • Requirements and numbers first. How 10 billion carts turn into a 64-node cluster, and why throughput decides the size before storage does.

  • A hash ring to spread the keys. Consistent hashing and virtual nodes, so adding a node moves a sliver of the data instead of almost all of it.

  • Consistency you tune per request. Quorums, R + W > N, and why overlap alone still doesn’t give you linearizability.

  • Conflicting writes, resolved. Last-write-wins, vector clocks, and compare-and-swap, with what each one gives up.

  • A disk format built for writes. The write-ahead log, memtables, SSTables, Bloom filters, compaction, and the tombstones behind every delete.

  • Failures as the normal case. Gossip, hinted handoff, Merkle trees, and multiple data centers, then how Dynamo, Cassandra, and DynamoDB each chose differently.

Let’s dive in!


Requirements

The interviewer opens with one line: “Design a distributed key-value store.”

That’s all you get. So you spend the first 5 minutes turning it into something you could build. Pick one use case and keep it in front of you the whole time: shopping cart service of a large online store, where each key is a cart ID like cart:42, and each value is the cart’s contents.

Every decision below comes back to that cart.

Functional Requirements

  • Store a value under a key with put(key, value).

  • Read it back with get(key).

  • Remove it with delete(key).

  • Expire a key after a time-to-live (TTL), so abandoned carts clean themselves up.

  • Update a key only if nobody changed it since you read it (compare-and-swap).

  • Let the caller pick the consistency level on each request.

Keys are strings up to 256 bytes. Values are opaque bytes up to 1 MB, and the store never parses them.

Non-Functional Requirements

  • Availability: 99.99%, and writes keep working during node and network failures. A customer who can’t add to their cart leaves.

  • Latency: p991 under 10ms for reads and writes inside one region.

  • Scale: 10 billion keys, with room to grow without downtime.

  • Durability: acknowledged write survives the loss of any single node or availability zone.

  • Tunable consistency: eventual by default, stronger when the caller asks for it.

Out of scope: range scans, secondary indexes, and transactions across keys.

Say this out loud early! It saves you 10 minutes of follow-up questions.

Now let’s put numbers on it…


Back-of-the-Envelope Estimates

Start with storage:

  • 10 billion keys × (50-byte key + 1 KB average value) ≈ 10 TB of raw data

  • × 3 replicas = 30 TB

  • + 50% for commit log, indexes, Bloom filters & compaction headroom ≈ 45 TB

Then traffic:

  • 200,000 reads/s and 50,000 writes/s on average

  • Peak at 3x: 600,000 reads/s and 150,000 writes/s

  • Each write lands on 3 replicas: 450,000 replica writes/s

  • Each quorum read touches 2 replicas = 1.2 million replica reads/s

Then bandwidth:

  • Writes: 150,000 × 1 KB × 3 ≈ 450 MB/s between nodes

  • Reads: 600,000 × 1 KB ≈ 600 MB/s out to clients

And finally, the node count:

  • At 2 TB of data per node, with half the disk kept free for compaction and rebalancing: 45 TB ÷ 2 TB ≈ 23 nodes

  • At about 40,000 replica operations/s per node (an assumption you’d benchmark on your own hardware): 1.65 million ÷ 40,000 ≈ 42 nodes

  • To survive the loss of 1 of 3 availability zones at peak: 42 ÷ (2/3) ≈ 63, so plan for 64 nodes

These numbers shape the entire design.

Throughput sizes this cluster, and storage comes second. Neither fits on one machine, so the data has to be split across many nodes. And failure headroom adds 50% more hardware, which is the price of staying up when a whole zone goes dark.

Disk speed isn’t the bottleneck either.

If 20% of reads miss memory, you get 240,000 disk reads/s across 64 nodes, or under 4,000 per node, which any NVMe SSD handles with ease.

Now let’s turn those numbers into components…


High-Level Design

A request moves through 4 hops:

Client → Load Balancer → Request Coordinator → Storage Nodes

Each piece has one job.

Let’s walk through them.

1. Client and Load Balancer

The client sends every get and put to a load balancer.

The load balancer spreads requests across nodes and stops sending traffic to any node that fails its health checks.

A faster option is a partition-aware client library. It caches the partition map and sends each request straight to a replica, which saves one network hop. Cassandra’s drivers work this way with token-aware routing.

But the cost is freshness…Every client has to refresh its map when ownership changes, or it keeps knocking on the wrong door.

2. Request Coordinator

The coordinator runs every request from start to finish:

  1. Hash the key to find its partition.

  2. Look up the replicas that own the partition.

  3. Send the request to them and wait for enough answers.

  4. Pick the newest version and return it.

You could run coordinators as their own stateless tier. They hold no data, so you can scale them separately from storage, but every request adds an extra hop.

Dynamo and Cassandra put the coordinator inside every storage node instead.

Any node takes any request; there’s one fewer tier to run, and if the node is also a replica for the key, it skips a network call. This design does the same.

3. Storage Nodes

Every storage node owns many small key ranges and serves reads & writes for them.

Each node keeps its data in a log-structured merge (LSM2) tree. (This is covered in the storage deep dive.)

All nodes are identical. So there’s no special node to lose, and adding capacity means adding more of the same box.

Cluster Membership and Metadata

Every node needs 2 answers at all times: which nodes are alive, and who owns which key range.

Liveness travels by gossip3. Every second, each node swaps what it knows with a few random peers, and news reaches the whole cluster in a handful of rounds. The partition map lives in a small, strongly consistent metadata store (a 3 or 5 node cluster running etcd, ZooKeeper, or Raft4 inside the database), because 2 nodes disagreeing about ownership would send writes to the wrong place.

Gossip scales to thousands of nodes.

The metadata store stays small because the map changes only when you add, remove, or rebalance nodes.

Control Plane and Data Plane

Split the system into 2 planes:

  • Control plane: membership, partition map, rebalancing, configuration, and rolling upgrades. It changes a few times a day.

  • Data plane: every get and put. It runs hundreds of thousands of times per second.

Keep them apart. If the control plane goes down, nodes keep serving traffic from their cached partition map; you just can’t add nodes until it’s back.

Leaderless or Leader-Based

This is the biggest architecture choice you’ll make:

  • Leader-based: each partition has one leader. Every write goes through it, and followers copy its log. Ordering is simple and strong consistency comes naturally, but a dead leader pauses writes for its partitions until a new one gets elected.

  • Leaderless: any replica accepts writes and the coordinator sends each write to all replicas at once. The system stays writable during failures, and conflicts get resolved later.

The cart wants availability above all, so start leaderless with tunable consistency, like Dynamo and Cassandra. (The consistency deep dive shows how to add a leader-based path for the few keys needing strict ordering.)

Next, the API your cart service calls…


API Design

Use 2 protocols.

Nodes and partition-aware clients talk over gRPC (binary encoding, HTTP/2 multiplexing, and generated clients in every language).

Everyone else gets a simple REST layer, shown here because it’s easier to read.

Write a value:

Read a value:

GET /v1/keys/{key}?consistency=QUORUM

200 OK
{ “value”: “<base64 bytes>”, “version”: “b91d07” }

Delete a value, or batch several operations:

DELETE /v1/keys/{key}     → 204 No Content

GET /v1/keys?ids=cart:42,cart:43

PATCH /v1/keys   { “items”: [{ “key”: “cart:42”, “value”: “...” }] }

A few details carry most of the weight here:

  • Versions are opaque. The client gets a version token back and sends it with its next write. Inside, it holds a vector clock5 or a timestamp, and the client never parses it.

  • Conflicts come back as siblings. When replicas hold concurrent versions, a read returns all of them with 300 Multiple Choices, the way Riak does, and the client merges them.

  • Timeouts are ambiguous. A write timeout doesn’t mean the write failed; it could have landed on 1 replica. So the client retries with the same Idempotency-Key6, and replicas drop the duplicate.

  • Batches aren’t transactions. The coordinator splits a batch by partition, runs the parts in parallel, and returns a result per key.

  • Errors map to clear codes. 404 for a missing key, 412 when the If-Match version is stale, 413 for a value over 1 MB, 429 with Retry-After for a tenant over quota, and 503 when too few replicas answer in time. Every error has one shape: {”error”: {”code”: “VERSION_MISMATCH”, “message”: “...”, “details”: [...]}}.

Key names follow one pattern, tenant:type:id, like shop1:cart:42. The prefix keeps tenants apart and makes hot key reports readable.

Behind that API, every record looks the same.


Data Model

Every record on disk holds 6 fields:

  • key: string the client sent

  • value: opaque bytes

  • version: a vector clock, or a timestamp under last-write-wins

  • expires_at: when the TTL runs out

  • tombstone: flag marking a delete

  • checksum: to catch corrupted bytes on read

There’s no schema beyond this. The cart service decides what the bytes mean, and the store only decides where they live and how long they survive.


System Workflow

With the pieces in place, here’s how a request moves through them.

Take one customer adding a pair of shoes to cart:42.

Write Path

  1. The client sends PUT /v1/keys/cart:42 with consistency QUORUM.

  2. Load balancer forwards it to any healthy node, which becomes the coordinator.

  3. Coordinator hashes cart:42 and finds its 3 replicas, one in each availability zone.

  4. It sends the new value and version to all 3 replicas in parallel.

  5. Each replica appends the write to its commit log, adds it to its memtable, and acknowledges.

  6. After 2 acknowledgments (W = 2), the coordinator returns success to the client.

  7. The third replica finishes on its own. If it’s down, a neighbor keeps a hint and delivers the write once it’s back.

  8. Later, each replica flushes its full memtable to an SSTable7 on disk.

Read Path

  1. The client sends GET /v1/keys/cart:42 with consistency QUORUM.

  2. Coordinator finds the same 3 replicas.

  3. It asks the fastest replica for the full value and a second replica for a digest (a hash of the value).

  4. Each replica checks its memtable first, then uses Bloom filters8 to skip SSTables without the key, then reads the rest from newest to oldest.

  5. If the value and the digest match, the coordinator returns the value.

  6. If they differ, it fetches the full value from both, returns the newest version (or every sibling), and writes the winner back to the stale replica. This is read repair.

Putting It All Together

Here’s the full add-to-cart flow, end to end:

  1. The cart service reads cart:42 and gets the items plus version b91d07.

  2. Then it adds the shoes to the list in memory.

  3. It writes the new cart back with If-Match: b91d07.

  4. If nobody changed the cart in between, the write succeeds with a new version.

  5. If the customer’s phone and laptop both write without If-Match at the same moment, the store keeps both versions as siblings. With If-Match, one write wins and the other gets 412 and retries.

  6. The next read returns both siblings, the cart service merges them into one list, and writes the merged cart back.

That covers the happy path.

The deep dive covers everything the interviewer pushes on next, starting with where the keys live.


Reminder: this is a teaser of the subscriber-only newsletter, exclusive to my golden members.

When you upgrade, you’ll get:

  • High-level architecture of real-world systems.

  • Deep dive into how popular real-world systems work.

  • How real-world systems handle scale, reliability & performance.

Unlock Full Access

(If this newsletter has helped you become a better software engineer, consider subscribing to support my work.)


Data Partitions and Hash Ring

Keep reading with a 7-day free trial

Subscribe to The System Design Newsletter to keep reading this post and get 7 days of free access to the full post archives.

Already a paid subscriber? Sign in
© 2026 Neo Kim · Publisher Privacy
Substack · Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for writing, podcasting, and media founders.