Dynamo: Amazon's Highly Available Key-value Store
2007 · SOSP · ~12 min read
Read the original paperA key-value store that keeps accepting writes during failures and hands conflicting versions to the application. Read it to see exactly what “eventually consistent” costs, measured in production.
The Dynamo paper describes a key-value store that accepts writes even when replicas cannot talk to each other, and then shows how to cope with the conflicting versions that result. Reading it lets you reason about a question every distributed store faces: when the network splits, which failure should the user see, a refused write or two versions of their data?
Amazon’s answer for its shopping cart was fixed by the business. A customer who clicks “add to cart” must succeed, even if a disk, a server or the link to a data centre has just failed. Werner Vogels, one of the authors, has written that the work began after the 2004 holiday season, when the relational databases behind several services reached their scaling limits. Most of what those services did was look up a value by its primary key. They did not need joins or multi-row transactions, and paying for them in availability made no sense.
The paper is also precise about what “fast” means. Amazon’s internal agreements were stated at the 99.9th percentile, with the paper’s example being a response within 300 milliseconds for 99.9 per cent of requests at a peak of 500 requests a second. A page could fan out to more than 150 services, so an average hides the customers whose requests were slow. Every design choice in the paper is measured against that tail.
Choosing which failure the customer sees
When a network partition separates replicas, a store can refuse writes on the side that cannot reach a quorum, or accept them on both sides and live with divergence. Brewer’s CAP conjecture had framed this choice. Dynamo takes the second option on purpose and calls itself always writeable. It makes no attempt to stop two replicas accepting different writes to the same key. It keeps both versions, notices the conflict when the key is next read, and hands the versions to the application.
For a cart, the merge is a union of items. Nothing a customer added is ever lost. The paper is candid about the price: an item the customer removed can come back. That is a product decision expressed in storage. A spurious item in a cart costs a moment of the customer’s attention; a lost item costs a sale. Other services made other choices. The paper notes that some used a simple “last write wins” rule based on timestamps, which is fine for data such as session state where losing a concurrent update does not matter.
Where a key lives: the ring
Our running example is the key cart:alice. Dynamo hashes the key with MD5 onto a ring of possible hash values. Each storage node is assigned positions on the same ring. The key belongs to the first node clockwise from its position, which acts as coordinator, and is replicated to the next N − 1 distinct nodes after it. With N = 3, cart:alice might live on nodes A, B and C. That ordered list of nodes is the key’s preference list.
The point of consistent hashing is what happens when membership changes. Add a node and it takes over only the keys between itself and its predecessor; every other key stays where it was. With a plain hash(key) mod n scheme, changing n moves almost every key. Dynamo goes further and gives each physical node many virtual nodes, so a node owns many small arcs scattered around the ring rather than one large one. When a node fails, its load spreads across many survivors instead of falling on one neighbour, and a more powerful machine can simply be given more virtual nodes.
Keys hash to a point on the ring and belong to the next N distinct nodes clockwise. Virtual nodes spread each physical node around the ring so that load and recovery are shared evenly.
| key | owners (clockwise) | |
|---|---|---|
| cart:alice | B → D → E | — |
| cart:bob | D → E → C | — |
| cart:carol | D → E → C | — |
| cart:dan | E → C → A | — |
| cart:erin | E → C → A | — |
| cart:frank | D → E → C | — |
| cart:gina | E → C → A | — |
| cart:hal | D → E → C | — |
With R + W > N, any read set and any write set share at least one node, so a read returns the newest version on some replica. Dynamo lets you pick: W = 1 makes writes fast and available, R = 3 then pays for it on reads.
The paper is honest that the first scheme was not good enough. Section 6.2 describes three partitioning strategies they ran in turn. Random token positions made bootstrapping a new node slow, because it had to scan other nodes for its keys, and made Merkle trees expensive to rebuild. The final strategy divides the ring into a fixed number of equal partitions and assigns whole partitions to nodes. It balanced load best and made membership changes cheaper. Most summaries describe only the first scheme.
Following two writes to one cart
Dynamo’s interface has two calls. A get returns either one value or a list of conflicting versions, together with an opaque context. A put must pass that context back. The context carries a vector clock: a list of (node, counter) pairs, one per node that has coordinated a write to this key.
(values, context) = get("cart:alice")
cart = merge(values) # application's rule, e.g. union of items
cart.add("shoes")
put("cart:alice", context, cart)Now follow Alice’s cart. Node A coordinates her first write, a book, and stamps it [A:1]. Her next write adds a pen, again through A: [A:2]. Since [A:2] is greater than or equal to [A:1] in every position, it supersedes it and the old version can be discarded. So far there is one version.
Then two things happen concurrently. On her laptop, Alice adds shoes; that write lands on node B with context [A:2], producing [A:2, B:1] and the cart book, pen, shoes. On her phone, reading the same [A:2] version, she removes the pen and adds a lamp; that write is coordinated by C, producing [A:2, C:1] and the cart book, lamp. Compare the two clocks. The first is ahead in B, the second is ahead in C. Neither dominates, so the writes were concurrent and both versions are kept.
The next read returns both versions. The cart service takes the union, book, pen, shoes and lamp, and writes it back with a context that covers both clocks, so the new version dominates both and they can be discarded. Notice the pen. Alice removed it on her phone, and the union put it back. That is the cost the paper accepted, appearing in a four-step example.
Compare what a timestamp rule would have done with the same two writes. Last write wins keeps whichever version has the later wall-clock time and discards the other without telling anyone. If the phone’s write is stamped later, the shoes vanish; if the laptop’s is, the lamp vanishes, and the pen removal is lost as well. Which one survives depends on the clocks of two different machines, which is exactly the comparison Lamport showed cannot be trusted. Vector clocks cost more space and push work onto the application, but they never silently drop a write that nobody saw.
Change one fact: Alice’s phone reads the cart after the laptop’s write of shoes has landed. The phone write still removes the pen and adds the lamp. How many versions does the next read return, and is the pen in the cart?
Show the worked answer
One version, without the pen. The phone now reads [A:2, B:1] and its write produces [A:2, B:1, C:1], which is at least as large as the laptop’s clock in every position. The store knows the phone’s write saw the shoes, discards the older version, and the removal of the pen stands. Vector clocks only report a conflict when one writer genuinely did not see the other’s write.
R, W, and what a quorum stops promising
Each operation is tuned by three numbers. N is the number of replicas, W the number that must acknowledge a write before it is reported successful, and R the number that must answer a read. The coordinator writes locally, sends the write to the other replicas on the preference list, and replies once W − 1 of them have answered. If R + W > N, every read set overlaps every write set in at least one node. The common configuration in the paper is (3, 2, 2): any two of three nodes overlap any other two.
| N, R, W | what it improves | what the design must also handle |
|---|---|---|
| 3, 2, 2 | reads and writes both survive one slow or dead replica; read and write sets overlap | the overlap only holds while the preference list is the real one |
| 3, 1, 3 | fast reads from any single replica | a write fails or waits if any replica is unreachable |
| 3, 3, 1 | writes succeed if one node is up | reads wait on every replica; a lost node blocks reads |
| 3, 1, 1 | lowest latency for both | no overlap: reads can miss recent writes until repair runs |
Here is the change that matters. Nodes B and C become unreachable from the coordinator. A strict quorum would fail the write, since only A is left of the three. Dynamo uses a sloppy quorum instead: it walks further round the ring and writes to the first N healthy nodes, say A, D and E. D’s copy carries a hint that it really belongs to B. D keeps it in a separate local store and hands it to B when B returns. This is hinted handoff, and it is why the cart write succeeds.
Now read the cart from a client that can reach B and C but not A. With R = 2 it gets two answers, from B and C, and neither has the latest write. The arithmetic of R + W > N assumed the read and write would use the same N nodes. Under a sloppy quorum they did not. Many readers take Dynamo’s quorums as a consistency guarantee. They are a tuning knob for latency and durability; under failure, the store promises only that the replicas will converge eventually.
Convergence needs a background process for the cases hinted handoff misses, such as a hint holder that itself dies. Replicas compare Merkle trees, hash trees over their key ranges, starting at the root. If the roots match, the ranges are identical and nothing more is sent. If not, they descend only into the subtrees that differ. Membership and failure information spreads by gossip, with administrators adding and removing nodes explicitly. There is no central coordinator anywhere, which fits the system’s priorities and also makes it harder to operate.
Reads also repair. When a coordinator collects responses for a get and finds that one replica returned an older version that another version supersedes, it writes the newer version back to the stale replica. Keys that are read often converge quickly this way; keys that are rarely read rely on the Merkle tree comparison. The paper also places each key’s preference list across multiple data centres, so the loss of a whole data centre leaves replicas elsewhere, at the price of some writes crossing the wide-area network.
What production taught them
Section 6 is the part of the paper most worth rereading. Over a 24-hour period on the shopping cart service, 99.94 per cent of requests saw exactly one version, and only a tiny remainder saw two or more. The authors write that the rise in divergent versions was usually caused not by failures but by concurrent writers, and that these were mostly automated client programs rather than people. The mechanism built for partitions was mostly handling robots.
They also traded durability for latency where a service could tolerate it. An optional in-memory write buffer, flushed by a background writer, reduced 99.9th percentile write latency by a factor of five during peak traffic, at the risk of losing buffered writes if a server crashed. To limit that risk, one of the N replicas performs a durable write. Vector clocks have a size problem too: if many nodes coordinate writes for a key, the list grows. Dynamo truncates it past a threshold by dropping the oldest entry, which can make it impossible to prove that one version descends from another. The paper reports this had not been a problem in production; it is a correctness shortcut with a known failure mode.
Finally, they moved coordination into the client. Instead of sending a request to a random node that forwards it, a client library can learn the membership and send directly to the coordinator. The paper reports this lowered latency at the 99.9th percentile as well as on average. It removed a network hop from every request.
What DynamoDB kept and what it dropped
Dynamo was internal software that each team ran for itself, and it asked a lot of application developers. Vogels has written that many Amazon teams preferred the simpler SimpleDB despite its limits, because running Dynamo and writing merge logic was hard. When Amazon launched DynamoDB as a service in 2012, it kept the partitioned, replicated, key-value shape and the obsession with predictable latency, and dropped the parts developers struggled with. DynamoDB does not return conflicting versions. Its 2022 USENIX ATC paper describes each partition being replicated with Multi-Paxos, with a leader replica that serves writes and strongly consistent reads. Global tables, which replicate across regions, resolve concurrent writes with last writer wins.
Others took different paths. Cassandra, built at Facebook by one of Dynamo’s authors, combined the ring with Bigtable’s data model and used timestamps rather than vector clocks. Riak followed the paper closely, kept vector clocks, and later adopted dotted version vectors to stop sibling versions multiplying under concurrent clients. The reconciliation Dynamo left to applications was later formalised as conflict-free replicated data types, which merge automatically with rules defined by the data type rather than by each service.
When should you not use this design? When an operation cannot be undone or merged: taking payment, decrementing stock that must never go negative, assigning a unique username. For those, a refused or delayed write is the correct answer during a partition, and the design you want is consensus, which is the next paper.
How to read the original
Read Section 2 first, especially the subsections on service level agreements and design considerations; they explain why the system looks the way it does. Then Table 1 in Section 4, which lists each problem with the technique chosen for it and its advantage. Use it as a map for the rest of Section 4: read 4.3 (replication), 4.4 (versioning, with the paper’s own vector clock example) and 4.5 to 4.7 (quorums, hinted handoff, Merkle trees) closely, and skim the rest. Section 5 on implementation can be skimmed. Section 6 is the evaluation and is the best part: look at the latency graphs for the buffered write experiment, the three partitioning strategies, and the divergent-version counts. There is no formal correctness argument, and none is claimed; read it as an experience report.
Dynamo chose availability and handed conflicts to the application. Raft makes the opposite choice. It gets a cluster to agree on one order of writes and refuses to make progress without a majority, and its paper is mostly about making that agreement understandable enough to build correctly.
The original. Read it after this page; the explainer above is a map, not a substitute.
The CTO who co-authored the paper on what it got right, what changed, and how it became DynamoDB.
The sequel: what fifteen years of running the idea as a service taught the team.