Case study V.13Advanced

Design a Distributed Key Value Store Like Dynamo

The advanced classic, modeled on Amazon’s Dynamo paper. Every technique from Part IV shows up here, combined, and the interviewer will ask what each one costs.

The short answer

Requirements. put and get for values under 10 KB across hundreds of nodes, with consistency tunable per request; petabytes of data, nodes added with no downtime, writes that succeed even during failures, and low latency at the 99th percentile.

Copies
N = 3on separate machines, racks and zones
Quorum
R + W > Nevery read overlaps the latest write
Values
under 10 KBput and get by key

The design. Keys sit on a consistent hashing ring with virtual nodes, and each key is copied to the next N distinct nodes clockwise. A coordinator writes to W replicas and reads from R; with R + W > N every read overlaps the latest write, and each request can trade freshness for latency. Vector clocks detect concurrent writes to one key so the reader can merge them. A down replica’s writes go to a stand in with a hint, Merkle trees resync replicas that drifted, gossip spreads who is alive, and an LSM tree makes every write a sequential append.

Interview prompt

Design a key value store like Dynamo or Cassandra: put(key, value) and get(key) across hundreds of nodes, always writable.

Requirements and estimates

Functional requirements

  • put and get for values under 10 KB.
  • Tunable consistency per request.

Non-functional requirements

  • Petabytes of data, horizontal scaling, no downtime to add nodes.
  • High availability: writes succeed even during failures.
  • Low latency at the 99th percentile.

Every technique, and what it solves

ProblemTechniqueWhat it gives you
Data larger than one machineConsistent hashing with virtual nodesEven spread; adding a node moves only its share
Node lossReplicate to the next N distinct nodes clockwiseCopies on separate machines, racks and zones
Freshness against latencyQuorums N, R, WChoose per request
Concurrent writes to one keyVector clocks or last write winsDetect conflicts, then resolve them
Temporary failureSloppy quorum and hinted handoffWrites succeed while a replica is down
Permanent failure, driftAnti-entropy with Merkle treesReplicas resync, moving only what differs
Knowing who is aliveGossip protocolNo central monitor; news spreads in O(log N) rounds
Fast writesLSM tree: commit log, memtable, SSTablesSequential disk writes only

Partitioning and replication use exactly the ring from IV.3: pick a key there to see its three replicas.

Simulator: quorum reads and writes

Presets
Consistency
Writes survive
Reads survive

Whiteboard

What you sketch in the first five minutes: where a key lives, then how many copies must answer.

1. Where a key lives

Say: hash the key onto a ring; its three copies are the next nodes clockwise.

ABCDEFkeyclockwise:B, C, DN = 3 copieson 3 different nodesC is down:E keeps the writewith a hint for CC is back:E hands it over
  1. Hash the key to a point on the ring of virtual nodes.
  2. Walk clockwise: the first 3 distinct nodes hold its copies.
  3. One of them is down? The next healthy node keeps the write with a hint and hands it back later.

Next question: how do you add a node with no downtime? It takes its virtual positions and streams only the key ranges it now owns.

2. N, R and W

Say: with three copies, how many must answer is a choice per request.

coordinatorBhas the writeChas the writeDstaleW = 2R = 2reads any two:one is always newR + W > N2 + 2 > 3lower R or W for speed, raise them for freshnesschosen per request
  1. A key lives on N = 3 replicas.
  2. A write waits for W of them, a read asks R of them.
  3. With R + W > N, say W = 2 and R = 2, every read overlaps the latest write.

Next question: two clients write the same key at once. Vector clocks show the writes were concurrent, and the next reader merges them.

Conflicts and vector clocks

With W below N, two clients can update the same key on different replicas at once. A vector clock is a list of [server, counter] pairs attached to each version. If one version’s counters are all greater or equal, it descends from the other and wins. If neither dominates, the writes were concurrent and the system keeps both for the client to merge.

D3 and D4 conflict. Each has a counter the other lacks (Sy versus Sz), so neither descends from the other. The next reader receives both, merges them (for a shopping cart, the union of items) and writes D5, which dominates both. Last write wins would have silently dropped one.

Failures

Detecting them

Every node keeps a membership list with heartbeat counters and gossips it to a few random peers each second. If a node’s counter stops rising for a while, peers mark it down. News reaches every node in about log N rounds, with no single monitor to fail.

Surviving them

Hinted handoff: if a replica is down, the write goes to the next healthy node with a note naming the real owner, and is handed back when it returns. Merkle trees let two replicas compare hashes of key ranges and sync only the branches that differ.

Why writes are fast. A write is one sequential append to the commit log plus an in memory insert; the memtable is flushed to an immutable sorted file when full. Reads check the memtable first, then use bloom filters to skip SSTables that cannot contain the key. Background compaction merges SSTables.

What the interviewer probes next

Why not just use last write wins?

It is simple but silently discards one of two concurrent writes, and clock skew between servers makes the choice arbitrary. Fine for caches and full overwrites; wrong for carts or counters where both updates should survive.

How does a read find the latest version?

The coordinator reads R replicas and returns the newest version, or all concurrent ones. Replicas that returned stale data are fixed in the background (read repair).

How do you add a node with no downtime?

The new node takes its virtual positions on the ring, streams the key ranges it now owns from their current owners, then starts serving. Only neighboring ranges move.

How do you place replicas across data centers?

Walk the ring but skip nodes in a rack or zone that already holds a copy, so N replicas land in N failure domains. Cassandra calls this a network topology strategy.

Building blocks used here

Want to run this as a mock interview? See interview prep.

© 2026 Arman Ajabkhani · armantik.com · Privacy