100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Architecture

Consensus Algorithms

Consensus algorithms let a group of distributed nodes agree on a single value or ordered log despite failures and network delays, underpinning leader election and replicated state machines.

Distributed Systems TheoryAdvanced11 min readJul 9, 2026
Analogies

Consensus Algorithms

Consensus is the problem of getting a set of distributed nodes to agree on a single value, or a single ordered sequence of values, even though nodes can crash, restart, or experience arbitrary network delays. It sounds simple, but the FLP impossibility result (Fischer, Lynch, Paterson, 1985) proves that no fully asynchronous consensus algorithm can guarantee both safety and termination if even one node may fail — so every practical consensus algorithm makes some timing assumption (like using timeouts) to make progress in practice, while still guaranteeing safety (never agreeing on two different values) under all conditions. Consensus is the foundation underneath distributed locks, leader election, configuration stores, and replicated logs — anywhere a cluster needs a single, agreed-upon source of truth despite individual node failures.

🏏

Cricket analogy: Third umpire reviews must reach a final verdict despite conflicting camera angles and signal delays; if the feed freezes mid-review, the umpire still can't declare two different outs for the same ball — a single, safe decision is non-negotiable even when technology stalls.

Paxos: The Original, Notoriously Hard Algorithm

Paxos, introduced by Leslie Lamport, was the first widely studied consensus algorithm proven correct under partial synchrony. It works in two phases: a 'prepare' phase where a proposer asks a majority of acceptors to promise not to accept any proposal older than the one it's about to send, and an 'accept' phase where the proposer sends its actual value and acceptors accept it if they haven't promised otherwise in the meantime. Paxos guarantees safety (only one value is ever chosen) as long as a majority of nodes are reachable, but it is famously difficult to implement correctly and even harder to extend to a continuously replicated log (Multi-Paxos), which is why it earned a reputation for being conceptually elegant but practically painful — most engineers encounter it via derivative systems (like Chubby or Spanner) rather than implementing it directly.

🏏

Cricket analogy: Paxos is like a captain first sending a runner to check with a majority of teammates that no one has already agreed to a different batting-order change, then only locking it in once that majority confirms — elegant but so fiddly most players only see it via the umpire's simplified final call.

Raft: Designed for Understandability

Raft, published by Diego Ongaro and John Ousterhout in 2014, was explicitly designed to be easier to understand and implement than Paxos while providing equivalent guarantees. Raft decomposes consensus into three clearly separated subproblems: leader election (nodes use randomized timeouts to elect a single leader when the previous one fails or none exists), log replication (the leader appends entries to its log and replicates them to followers, committing an entry only once a majority have stored it), and safety (mechanisms ensuring a newly elected leader always has all previously committed entries, so committed data is never lost or overwritten). Because the leader is the single point that orders all writes during its term, clients get a strong, easy-to-reason-about model: all state changes flow through one leader at a time, and Raft's leader election guarantees at most one leader can be active per term. Raft powers etcd, Consul, and CockroachDB's metadata layer, among many others.

🏏

Cricket analogy: Raft splits captaincy into clear jobs: randomized coin-toss-style timeouts elect a new captain when one steps down, the captain alone calls every shot during the innings, and rules ensure a newly appointed captain always knows the prior overs bowled, so no delivery's record is ever lost.

text
Raft leader election (simplified):

1. All nodes start as Followers with a randomized election timeout.
2. Follower's timeout expires without hearing from a Leader ->
   it becomes a Candidate, increments its term, votes for itself,
   and requests votes from all other nodes.
3. Each node votes for at most one Candidate per term (first-come,
   first-served), then resets its own timeout.
4. If a Candidate gets votes from a MAJORITY of nodes -> becomes
   Leader for that term, starts sending heartbeats.
5. If no Candidate gets a majority before timeouts expire again ->
   new election starts with a higher term (randomized timeouts
   make this eventually converge).

Log replication once a Leader exists:
[Client] -> [Leader] appends entry to its log
            [Leader] -> replicate to Follower A, Follower B
            Once a MAJORITY (Leader + 1 Follower of 3) have
            stored the entry -> Leader commits it and responds
            to the client, then notifies Followers to commit too.

Google's Chubby lock service (built on a Paxos-derived protocol) and its open-source descendants ZooKeeper (ZAB protocol, Paxos-inspired) and etcd (Raft) are the classic real-world consensus deployments: they don't store application data at scale, but they provide the small, highly-consistent 'source of truth' — locks, leader pointers, configuration — that the rest of a much larger, eventually-consistent system relies on to avoid split-brain scenarios.

Consensus vs. Coordination-Free Systems

Consensus is expensive: it requires a network round-trip to a majority of nodes for every committed decision, which adds latency and limits throughput compared to systems that avoid coordination entirely (like AP/eventually-consistent stores). This is why well-designed systems use consensus sparingly — for a small amount of critical metadata (leader pointers, cluster membership, configuration) — rather than routing every single application write through a consensus protocol. Databases like CockroachDB and Spanner use consensus (Raft or Paxos variants) per data shard/range, so consensus overhead is bounded and parallelized across many independent groups rather than being a single global bottleneck. This is also why production clusters are almost always sized 3, 5, or 7 nodes: a cluster survives f failures with 2f+1 total nodes, and an even-sized cluster (like 4) tolerates no more failures than the next smaller odd-sized one (3), so the extra node adds cost without added fault tolerance.

🏏

Cricket analogy: Running DRS for every single delivery would grind a match to a halt, so it's reserved for close calls only; likewise a franchise fields exactly 11 (not 12) starters because an extra player adds cost without letting the team survive any more injuries than 11 already does under the rules.

  • Consensus lets distributed nodes agree on a single value or ordered log despite crashes and network delays.
  • The FLP impossibility result means no purely asynchronous algorithm can guarantee both safety and termination; practical systems use timeouts to make progress.
  • Paxos was the original proven consensus algorithm but is notoriously hard to implement and extend correctly.
  • Raft achieves equivalent guarantees with an explicit focus on understandability, splitting the problem into leader election, log replication, and safety.
  • Consensus requires a majority (quorum) of nodes, which is why clusters are typically sized 3, 5, or 7 (odd numbers) rather than even.
  • Because consensus adds latency, production systems apply it narrowly (metadata, leader election, per-shard coordination) rather than to every write.

Practice what you learned

Was this page helpful?

Topics covered

#Architecture#SystemDesignStudyNotes#SoftwareEngineering#ConsensusAlgorithms#Consensus#Algorithms#Paxos#Original#StudyNotes#SkillVeris