SD System Design In Depth
0%
lesson system-designreplicationdurability

Replication

Module 3.2: Distributed Coordination, Consensus & Leases Updated Sep 17, 2026
📄 Cheat Sheet
Distributed Systems 5.1: Replication
Martin Kleppmann Distributed Systems 5.1: Replication Watch on YouTube ↗

Kleppmann's replication lecture covers leader-based and leaderless replication, retries and idempotence, and why concurrent writes need version metadata. It is directly on topic.

0:00 / --:--

Concrete scenario

A primary acknowledges an order and fails while one replica is caught up, another lags, and a read-only region is partitioned.

Mechanics

Single-leader replication orders writes at a leader; multi-leader accepts writes in several domains and needs conflict handling; leaderless systems contact configurable replica sets. Synchronous modes wait for a defined set of durable acknowledgments—not necessarily every replica. Read and write quorums overlap only under the actual routing and failure assumptions.

Failure mode

Acknowledging one replica does not guarantee zero loss under correlated failure, nondurable acknowledgment, or promotion of a stale node. W + R > N alone is insufficient with sloppy quorums, concurrent writes, failed writes, or weak version resolution.

Trade-off

More acknowledgments improve durability and freshness but add latency and may reject writes during faults. Asynchronous replicas improve latency and read scale while exposing lag and recovery-point risk.

Worked example: what failover actually loses

A primary handles 5,000 writes per second, replicating asynchronously to two replicas. Replica A lags by 50 ms and replica B by 2 seconds, because it is in another region. The primary's disk dies.

  • Promote A: about 5,000 x 0.05 = 250 acknowledged writes are lost.
  • Promote B: about 10,000 acknowledged writes are lost.
  • With semi-synchronous replication to A (the primary waits for A to acknowledge receipt before acknowledging the client), promoting A loses nothing that was acknowledged, but every commit pays the round trip to A, roughly 0.5 to 1 ms in the same region.

Now add a network blip. If A is slow to acknowledge, MySQL semi-sync by default falls back to async after rpl_semi_sync_master_timeout (10 seconds). Your zero-loss guarantee quietly degrades exactly when you need it. That is why Raft-based systems require a majority acknowledgement with no fallback.

Topologies compared

TopologyWrite availabilityConflictsRead freshnessExamples
Single leader, asyncLeader onlyNoneReplicas lagMySQL and Postgres defaults
Single leader, consensusNeeds a majorityNoneLinearizable through the leaderetcd, CockroachDB ranges, Kafka KRaft metadata
Multi-leaderEvery regionMust be resolvedRegionalBDR for Postgres, CouchDB, collaborative editors
Leaderless quorumAny W nodesMust be resolved (vector clocks, LWW, CRDTs)Tunable through R and WCassandra, Riak, DynamoDB internals

Quorum arithmetic and its limits

With N = 3, W = 2 and R = 2, every read quorum overlaps every write quorum in at least one node, so a read can see the latest acknowledged write. It still breaks when:

  • Sloppy quorums and hinted handoff accept writes on nodes outside the key's home set, so the overlap is lost.
  • A failed write that reached one node is not rolled back. Later reads may or may not see it.
  • Concurrent writes resolved by timestamp can drop one write silently.

Failure modes

  • Split brain: the old primary comes back and accepts writes. Fence it (STONITH, epoch numbers) before promoting a new one.
  • Replication lag spikes from a long transaction or a schema migration. Alert on lag in seconds, not just bytes.
Check yourself Question 1 of 3
What synchronous means recall
From: Mechanics

A Postgres primary has four standbys, one of which is configured as the synchronous standby. When the primary acknowledges a commit, what is guaranteed?

Replication Consistency

Primary DB

V=0

Replica DB

V=0

Key Takeaways

Synchronous replication waits for a defined durable set, not necessarily all replicas.
One replica acknowledgment does not universally guarantee zero data loss.
W + R > N requires routing, versioning, and failure assumptions to provide freshness.
Was this lesson helpful? Spot an issue or have a suggestion? Let us know on GitHub.
Report an issue