SD System Design In Depth
0%
lesson system-designcoordination

Consensus

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

Kleppmann's consensus lecture explains what consensus guarantees, why FLP rules out a deterministic asynchronous solution, and how partial synchrony and leaders make it practical. It is the lesson's exact scope.

0:00 / --:--

Concrete scenario

Three metadata nodes replicate a log; one crashes and messages between the remaining nodes are delayed.

Mechanics

Consensus protocols such as Raft and Paxos maintain safety through terms or ballots, quorum intersection, and durable log rules. Liveness requires assumptions stronger than a fully asynchronous network, commonly eventual synchrony plus fair scheduling; randomized election timeouts reduce repeated split votes but do not by themselves defeat FLP.

Failure mode

Without a majority, a safe cluster cannot commit new entries. A stale leader may still contact external systems, membership changes can break quorum assumptions if done incorrectly, and snapshots or log repair can prolong recovery.

Trade-off

Consensus is a foundation for replicated state, leader election, and coordination, not a complete solution for atomic external side effects or application invariants. It adds write latency and operational discipline in exchange for a durable agreed order.

Worked example: quorum sizing and latency

A Raft group replicates a metadata log. A commit needs acknowledgements from a majority, counting the leader.

Cluster size NMajorityFailures toleratedWrite latency (leader in site 1)
3 (one zone)21About 1 ms: one fast LAN round trip plus fsync
3 (three zones, same region)21 (or one zone)About 2 to 3 ms
5 (three regions: 2+2+1)32 (or one region)Round trip to the nearest other region, about 30 to 80 ms
431Same fault tolerance as 3 but slower. Avoid even sizes

Each commit also needs a durable fsync on each acknowledging node. On cloud SSDs that is typically 0.5 to 2 ms, which is why etcd's documentation stresses low-latency disks.

What consensus guarantees

  • Agreement: no two nodes decide different values for the same log slot.
  • Validity: the decided value was proposed by someone.
  • Termination: guaranteed only when the network is stable enough. FLP (1985) proves no deterministic protocol can guarantee it in a fully asynchronous system with even one crash.

Paxos, Raft and friends

ProtocolKey ideaWhere it runs
Multi-PaxosA stable leader skips phase 1 for successive slotsChubby, Spanner (per split), many Google systems
RaftA strong leader, term numbers, and a log-matching property. Designed for understandabilityetcd, Consul, CockroachDB, TiKV, Kafka KRaft
ZabPrimary-backup atomic broadcast with epochsZooKeeper
Viewstamped ReplicationView changes, predating Paxos's publicationAcademic, and the basis for some storage systems
PBFT / HotStuffByzantine tolerance with 3f+1 nodesPermissioned blockchains

Failure modes seen in production

  • Disk stalls make the leader miss heartbeats, which triggers election churn.
  • Membership changes done by editing config files on each node can create two disjoint majorities. Use joint consensus or single-server changes.
  • Log growth without snapshots makes restarts replay millions of entries.
Check yourself Question 1 of 3
Randomised timeouts' role recall
From: Mechanics

What do Raft's randomised election timeouts actually achieve?

Raft Consensus (3 Nodes)
Architecture Challenge: Raft & Paxos Quorum Math
Staff Level
Context / Scenario: Cluster size N = 5. Majority quorum rule applies.
Problem: A Raft consensus cluster consists of 5 nodes. What is the minimum number of healthy nodes required to elect a leader and commit write entries?
A All 5 nodes must agree unanimously
B 3 nodes (floor(N/2) + 1)
C 2 nodes
D 4 nodes

Key Takeaways

Consensus safety uses ballots or terms, durable state, and quorum intersection.
Liveness depends on timing and scheduling assumptions stronger than full asynchrony.
Consensus does not make external side effects or application invariants automatic.
Was this lesson helpful? Spot an issue or have a suggestion? Let us know on GitHub.
Report an issue