Amazon Dynamo
Read first: Quorums and leaders, Partitioning and sharding
The 2007 Dynamo paper is a shopping-cart store that accepts writes during a network partition. It places replicas with consistent hashing, uses quorums with hinted handoff, and asks the client to merge versions that vector clocks mark as concurrent. DynamoDB came later and instead uses a primary per partition and conditional writes.
A shopping cart has one requirement that makes the storage design: the customer can add an item while some replicas cannot talk to each other. The 2007 Dynamo paper is Amazon’s design for that store. It was published at SOSP by DeCandia and others. DynamoDB is a later product. It picks a primary for each partition and uses conditional writes. The paper and the product share a name and then diverge. Read this page as the paper.
The problem
The cart is a small piece of state with an ugly failure mode. The shopper is mid-click. A network partition has separated some of the replicas that hold that cart. If you refuse the write until every replica agrees, the click fails and the shopper leaves. If you accept the write on whichever replicas you can reach, those replicas can disagree, and somebody has to put the cart back together.
That is the availability choice in CAP. During a partition you can keep answering, or you can keep a single up-to-date copy. You cannot promise both. Dynamo chooses the answer. The write is accepted. Convergence happens afterward. Eventual consistency here means the replicas come together once they can communicate again. It says nothing about what a read returns while they still disagree.
The data model has to tolerate two truths at once. Two adds, on two sides of a partition, are both real. A storage system that keeps only the last byte it saw will drop one of them. A storage system that keeps both has to show the client that they conflict, and the client has to decide what the cart means. The paper’s pain, written down with the design, is that those version markers grow and that the client is the one who merges.
A five-person shop with one database does not have this problem yet. Dynamo is the design you study when “the write must land” is a real requirement and you can say, in one sentence, how two conflicting carts become one.
The design
The ring. Keys and nodes sit on a consistent-hash ring, the structure from partitioning. A key belongs to the nodes that follow it around the ring. Each physical machine is inserted several times, as virtual nodes, so one machine owns many short arcs instead of one long arc. The long arc is how an unlucky machine becomes hot. The short arcs are how the same machines stay balanced.
The preference list for a key is the N replicas that should hold it: N distinct machines, walking the ring. Virtual nodes that belong to a machine you already picked do not count as extra replicas. N copies on one box would not survive that box dying. Replication here is leaderless. No replica is the primary for the key. Any of the N can take a read or a write.
Adding a machine should not reshuffle the world. The course states the consistent-hashing result as: adding a node moves about 1/N of the keys. Modulo hashing moves almost every key. The 30 below is an illustration of that statement, not a size from the paper.
illustration only, N = 30 nodes on the ring
fraction of keys that move when you add a node ≈ 1/N = 1/30 ≈ 3%
modulo hashing would move nearly all of them
The quorum. A write waits for W replies. A read waits for R replies. The quorum rule you already have is R + W > N. Then a read set and a write set share a replica, in the case where both sets landed on the preferred N. That shared replica is how the reader sees the write.
These numbers are a teaching assumption so the arithmetic is visible. They are not a published Amazon configuration.
assumed N = 3, R = 2, W = 2
R + W = 4, and 4 > 3, so the sets overlap
one replica can be slow or down and a write of W = 2 still returns
With W = 2 you can ignore the slowest of the three. That is the whole point of a quorum smaller than N. You paid for it by accepting that one replica can be stale until a later read or a later repair touches it.
Sloppy quorum and hinted handoff. A strict quorum of the preferred N cannot be formed when too many of those machines are unreachable. The cart would reject the add, which is the failure the paper set out to avoid. Sloppy quorum writes to fallback machines instead, enough of them to gather W acknowledgements. The write succeeds. The fallback is not a member of the preference list. It holds the value and a hint that says who the value was meant for.
Hinted handoff is the fallback sending that write home once the preferred machine is back. Until the hint lands, a read of the preferred replicas can miss the write. The overlap you counted on was an overlap of the preferred set. A write that lives on a fallback is outside that set. Availability was the goal. The overlap guarantee is weaker until handoff finishes. Say that when you draw the arrow, or you have drawn a quorum you do not actually have.
Finding divergence. After a partition, replicas differ in more places than one hint can cover. A Merkle tree is a tree of hashes over ranges of keys. Two replicas compare the root. Equal roots mean those ranges match. Unequal roots mean they compare children, and they exchange only the ranges whose hashes differ. Gossip is how a node learns membership: it exchanges, with peers, its view of who is in the ring. There is no separate membership service to lose. The paper uses both.
Vector clocks. Each version carries a vector clock: one counter per replica. On a write, the replica that takes it grows its own counter. On a merge, you take the max of each entry. A clock dominates another when it is greater or equal on every entry and greater on at least one. Two clocks where neither dominates are concurrent. Both writes happened. Neither is “the later one.”
Walk a cart. This is a teaching trace of those rules, not a log line from the paper.
start: empty clock
replica A takes "add milk"
clock becomes A:1
replica B cannot see A, takes "add eggs"
clock becomes B:1
compare A:1 and B:1
A is missing B's increment, B is missing A's
neither dominates
the client receives two siblings and must merge
A client that next writes the merged cart, “milk and eggs,” takes the max of the two clocks and then increments its own counter. That new clock dominates both siblings. A reader that sees it can drop the earlier ones. The client did the merge. The database did not know that milk and eggs can coexist. A counter that both sides incremented is a harder merge than a cart, and the paper does not spare you from writing that function. The versions and the clocks are metadata on the value. As more replicas appear in a value’s history, the vector gets longer. That growth is the pain they wrote down, next to the fact that clients must merge.
flowchart LR
client[Shopping cart client]
ring[Hash ring with virtual nodes]
pref[Preference list of N]
quorum[Quorum acknowledgements]
fallback[Fallback holding a hint]
repair[Merkle comparison]
client --> ring --> pref --> quorum
pref --> fallback
pref --> repair
The happy path is the top row. The fallback exists so a write still gathers acknowledgements when a preferred replica is gone. The Merkle comparison is the slow path that finds ranges the hints did not cover.
What they traded
| Choice | What you gain | What you spend |
|---|---|---|
| Accept the write during a partition | The cart click succeeds while replicas are split | Two versions of one cart, and a merge you had to design |
| Quorum with W and R below N | You wait for the fastest W, not for every replica | A replica that did not take the write is stale until repair |
| Sloppy quorum and hinted handoff | A write still completes when preferred nodes are down | The overlap guarantee waits until the hint gets home |
| Merkle trees plus gossip | Replicas find divergent ranges and learn membership without a central directory | Background repair, and a view of membership that is only as fresh as gossip |
| Vector clocks | Concurrent writes are visible instead of silently dropped | The clock grows, and the client must merge |
| Virtual nodes on the ring | Balance, and a join that moves about 1/N of the keys | More positions to track for each machine |
The failure worth rehearsing is the one the quorum arithmetic hides. Preferred replicas A, B, and C. C is unreachable. The write of “add eggs” is acknowledged by A and by a fallback F. W is satisfied. The client is happy. A later read asks B and C, after C has returned and before F has handed off. Neither B nor C has the eggs. R is satisfied and the cart is wrong. Nothing in R + W > N caught it, because that inequality assumed the write landed inside the preferred set. Hinted handoff closes the hole later. “Later” is a duration you do not get to call zero.
The second failure is the merge you postponed. Two adds succeed, the clocks are concurrent, and the client that reads them is a phone that only knows how to display one cart. If the merge code is missing, the phone picks one sibling and the other add disappears. The paper pushed that decision to the client on purpose. Shipping the system without the merge is how you get the availability of Dynamo and the data loss of a last-write-wins race.
DynamoDB is the contrast to keep straight while you talk about either failure. A primary per partition orders the writes for that partition. A conditional write succeeds only when a predicate on the current row is still true, for example that a version the client read is still current. Conflicts become rejected writes instead of sibling values. You can build a cart on that. You cannot point at the 2007 paper and claim you did.
What to steal
Steal the question before you steal the ring. Do you need this write to succeed while replicas cannot talk, and can you write the merge? If both answers are yes, the paper is a parts list: a ring so a join moves about 1/N of the keys, a quorum so you do not wait for the slowest replica, a deliberate weakening of that quorum when the preferred nodes are gone, and a clock that tells the client when it is looking at a conflict rather than an overwrite.
Steal the sentence about overlap. A quorum guarantees a shared replica only for the nodes that actually stored the write. The moment you accept a fallback, you have scheduled a repair, and reads in the gap can miss the value. Interviewers listen for that sentence more than they listen for the word “Dynamo.”
Leave the rest on the shelf until a partition is a real part of your availability goal. A team of five with one database should take the cart write to that database. If the database is down, the click fails and the client retries. Vector clocks, gossip membership, and Merkle anti-entropy are machinery for a fleet that already diverges. Standing them up in front of a single primary is how a small system grows a distributed-systems hobby and still loses carts to a missing merge function.
When you want one order of writes and a way to say “only if the version is still this,” you want the later product’s choices, or any primary-plus-conditional-write store. You do not want the 2007 paper with the name DynamoDB painted on it. Say which one you are using. Then say who merges.
Check yourself
With N of 3, R of 2, and W of 2, a preferred replica is down and the write is acknowledged by one preferred replica and one fallback. Will a later read of two preferred replicas necessarily see that write?
No. R + W greater than N overlaps when both quorums hit the nodes that hold the write. The fallback is outside the preferred set until hinted handoff delivers the value. A read of the preferred replicas can miss it in that gap. The numbers above are a teaching assumption, not a published Amazon setting.
A read returns two cart versions with clocks A:1 and B:1. Why can the client not keep the maximum clock and drop the other?
Neither clock dominates. A:1 has no B entry, and B:1 has no A entry. The writes are concurrent, which is the definition you use when neither vector is greater or equal on every component. The client has to merge the two carts. Dropping one drops a write that succeeded.
You add one machine to a consistent-hash ring that already has 30. About what fraction of keys move, and what would modulo hashing have done?
Using the course statement that an added node moves about 1/N of the keys, 1/30 is about 3 percent. The 30 is an illustration, not a Dynamo cluster size. Modulo hashing would move almost every key, which is why the ring exists.
A teammate says DynamoDB stays writable during a partition and reconciles carts with client-side vector clocks, because it is Dynamo. What did they mix up?
The 2007 paper is the leaderless cart store: quorums, sloppy quorum, hinted handoff, and client merges driven by vector clocks. DynamoDB is a later product with a primary per partition and conditional writes. Same name, different conflict story. The teammate described the paper and attributed it to the product.
Based on: Dynamo, SOSP 2007, DeCandia and others.