Video in progress

Design a Dynamo-style distributed key-value store: how is data partitioned and replicated, and what happens when nodes fail?

Keys are partitioned on a consistent hashing ring with virtual nodes, each key is replicated to N different nodes, and reads and writes use configurable quorums W and R. Failures are covered by hinted handoff, read repair and anti-entropy with Merkle trees, and conflicts are resolved with versions.

📖 Answer

I pin down the requirements: get(key)/put(key, value), values up to 1 MB, high availability, writes almost never rejected, a few seconds of eventual consistency is fine. This is a system on the AP side. If you need strict consistency, the design is different (Raft groups, the etcd or TiKV route).

Partitioning. Consistent hashing, with hundreds of virtual points per physical node. When a node is added, only the neighboring ranges move. The ring map spreads by gossip; the client talks to any node, which acts as coordinator and forwards the request to the owners.

Replication. A key is written to the N next distinct physical nodes after it on the ring. They must be in different zones, otherwise with N=3 you lose the key together with one zone.

Quorum. N=3, W=2, R=2: reads and writes keep working even if one node is down, and because W+R>N a read sees the last acknowledged write. Where latency matters, use R=1 and accept staleness. This is chosen per request.

Temporary failure. If one of the owners doesn't respond, the write goes to the next healthy node with a "hint" (sloppy quorum) and is handed to the owner when it returns. Write availability is kept, but the quorum guarantee gets weaker in the meantime.

Repairing differences. Read repair updates a stale copy during a read. Anti-entropy compares ranges in the background using Merkle trees and exchanges only the pieces that differ.

Conflicts. Two coordinators wrote the same key in parallel. Last-write-wins is simple, but one write is silently lost (Cassandra does this). Or keep the concurrent versions with a vector clock and leave the merge to the client (the original Dynamo did this for the shopping cart). I usually take LWW with a hybrid logical clock, and CRDTs for the types that need merging.

Inside a node there's an LSM-tree (like RocksDB): writes are sequential and fast, deletes use tombstones, and compaction cleans up.

Membership. Gossip and a phi-accrual failure detector. It's better to make fully removing a node a separate step that a human confirms, otherwise a short network blip starts moving terabytes of data.

At the end I say: you won't write such a store yourself, since Cassandra, ScyllaDB and DynamoDB exist. But to configure them correctly you need to understand these parts.