Leaderless Replication (Dynamo-Style)

Any replica takes reads and writes, and quorums decide success. How W + R > N works, how stale replicas catch up, how concurrent writes are handled, and where quorums fall short.

Overview

In leaderless replication there is no leader to order writes. A write is sent to several replicas at once, and it succeeds when enough of them confirm. A read also asks several replicas and takes the newest answer. Amazon's Dynamo paper (2007) described this design, and Apache Cassandra follows the same model.

Without a leader there is no failover: when a replica is down, the others keep answering. The price is that replicas can disagree for a while, and the system needs extra machinery to find the newest value and to repair the copies that fell behind.

Quorums: W + R > N

Each key is stored on N replicas. A write succeeds when W of them confirm it. A read asks the replicas and waits for R answers. If W + R > N, every read set shares at least one replica with every write set, so at least one of the answers comes from a replica that has the latest successful write. The reader uses version numbers or timestamps to pick it.

The Dynamo paper reports (N, R, W) = (3, 2, 2) as a common setting. The latency of an operation is set by the slowest of the W or R replicas it waits for, which is why W and R are usually below N. You can check the overlap rule by brute force.

With N = 3, each choice of W and R trades write availability against read availability. Writes survive N - W replicas down, and reads survive N - R.

  • N = 3, W = 2, R = 2: writes and reads each survive 1 replica down. This is a balanced default.
  • N = 3, W = 3, R = 1: writes survive 0 down and reads survive 2 down. It suits read-heavy data with rare writes.
  • N = 3, W = 1, R = 3: writes survive 2 down and reads survive 0 down. It puts write availability first.
  • N = 3, W = 1, R = 1: writes and reads each survive 2 down. It is built for speed, but reads may be stale, because 1 + 1 = 2 is not greater than 3 and the sets need not overlap.

Key concepts

  • N, W, R
  • Quorum overlap
  • Read repair
  • Anti-entropy repair
  • Merkle tree
  • Sloppy quorum
  • Hinted handoff
  • Vector clock
  • Last write wins

Interview questions

  • In Cassandra, what is the difference between consistency levels ONE, QUORUM, and ALL?
  • Why does W + R > N not guarantee strong consistency?
  • How do replicas that missed writes catch up?
  • Two clients write the same key at the same moment. What happens?
  • How would you choose N, W and R for a service?

Sign up free to read the full topic

More DDIA topics

Start free on Cariara · Coding problems · System design studio