Distributed Systems10h estimated

Consensus Algorithms

Difficulty
Importance

The problem

Multiple machines sometimes need to agree on a single value or decision — who's the leader, what's the next entry in a log — even though messages can be lost or delayed and any individual machine might fail mid-decision. Consensus algorithms are provably correct protocols for reaching that agreement anyway.

Why now

Distributed consistency models established that machines need to agree on data, but not the actual mechanism for reaching that agreement under failure. Concurrency and synchronization already solved a related problem (coordinating access) using locks on a single machine; consensus is the much harder version of coordination when there's no single machine to hold the lock on at all.

Mental model

Consensus is a structured voting process: a proposal is put forward, a majority of nodes must acknowledge it before it's considered committed, and the majority requirement is exactly what tolerates some nodes being down or unreachable — as long as more than half are alive and can talk to each other, the system can keep making progress and never disagree with itself.

Requires

Unlocks

Related

Used in

Projects

  • Trace through a simplified Raft election by hand: five nodes, one crashes, walk through how the remaining four agree on a new leader
  • Explain why a consensus algorithm requires a strict majority (not just 'some') of nodes to agree, using a split-brain scenario as the failure case being prevented

Examples

  • etcd (which Kubernetes relies on for its own cluster state) uses Raft consensus to keep its data consistent across multiple nodes
  • A 5-node Raft cluster can tolerate 2 node failures and still make progress, because 3 remaining nodes still form a majority

Resources

Mastery checklist