AlgoViz

Dynamo: Amazon's highly available key-value store

medium 35 min

Amazon's shopping cart had to accept every add, even while servers and links failed.

When it comes up

The moments this idea belongs in a design interview, and the moments it does not.

Signals

When to bring Dynamo up

You hearSayBecause
"Must stay writable during outages"Leaderless replication, sloppy quorum, hinted handoffNo leader election blocks writes
"Shopping cart" or "wish list"Accept writes, merge carts by union with remove markersA duplicate item is cheaper than a lost add
"Tune latency against freshness"N, R, W per use caseR + W > N for overlap, lower for speed
"How do replicas catch up?"Read repair, hinted handoff, Merkle anti-entropyEach covers a different failure length
"Bank balance" or "seat booking"Not Dynamo: use a leader or consensusConcurrent versions are not acceptable there

When the interviewer pushes back

  1. Interviewer

    Your design merges carts by union. A user deletes an item, and it shows up again. What happened?

  2. You

    During a failure two versions diverged. One still had the item, the other had removed it. Their clocks were concurrent, so the read returned both, and union kept the item.

  3. Interviewer

    So how do you fix it?

  4. You

    Record removals as data. Each item carries the clocks of its adds and removes, and the merge keeps an item only if an add is not covered by a remove. That is the idea behind an observed-remove set.

  5. Interviewer

    What does that cost?

  6. You

    Metadata per item that grows until we can clean it up, plus code in every client. If that is too much, I would accept the rare returning item and show it clearly, since the paper reports that over 99.9% of cart reads see one version.

How should a cart store handle a write during a network split?

BreaksSingle primary, refuse while failing over
How
All writes go to one primary. During failover the cart returns an error.
Limit
Every split or crash loses adds, exactly what Amazon could not accept.
Choose when
Data where a refused write is better than two versions, not carts.
WorksReplicas with last write wins
How
Accept writes anywhere, keep the version with the latest timestamp.
Limit
Two concurrent adds: one silently disappears. Clock skew picks the wrong winner.
Choose when
Session data or settings where the latest value is good enough.
StrongDynamo-style: sloppy quorum, clocks, app merge
How
N = 3, W = 2, R = 2 on a ring, hinted handoff, vector clocks, siblings merged by union with remove markers, Merkle repair.
Limit
Stale reads possible, merge code in clients, metadata for removals.
Choose when
Carts, wish lists, any data where losing a write is worse than merging.