Skip to main content...
Distributed Systems Fundamentals
30 min

Day 43: Consensus: Raft election by hand; Paxos conceptually

Consensus: getting multiple machines to agree

Consensus means a group of machines agrees on a single value or sequence of events, even if some of them fail or messages are delayed — the foundation under leader election, replicated logs, and distributed locks alike.

Raft: walk through an election by hand

  1. All nodes start as followers. Each has a randomized election timeout
  2. If a follower hears nothing from a leader before its timeout fires, it becomes a candidate, increments a "term" counter, votes for itself, and requests votes from every other node
  3. Other nodes vote for the first candidate they hear from in that term (one vote per term each) — the first candidate to get votes from a majority becomes leader
  4. The new leader sends periodic heartbeats; followers reset their election timeout on each heartbeat
  5. If the leader goes silent (crashes, network partition), followers time out again and a new election begins with a higher term number

Why "majority" and randomized timeouts matter

Requiring a strict majority (not just 'most votes') guarantees at most one leader can be elected per term — two candidates can't both win a majority of the same fixed group. Randomized timeouts reduce the odds of a split vote (multiple nodes becoming candidates simultaneously and splitting the vote); if a split does happen, the next round's random timeouts almost always resolve it.

Paxos, conceptually

Paxos solves the same problem as Raft but is famously harder to reason about and implement correctly — it doesn't have a strong, persistent leader concept the way Raft does; instead any node can propose a value and nodes vote in numbered rounds. Raft was explicitly designed afterward specifically to be more understandable while providing the same guarantees — which is exactly why almost every modern system (etcd, Consul) chooses Raft.

Key terms

Consensus
Multiple nodes agreeing on a value despite failures and network delays.
Term (Raft)
A logical, monotonically increasing "epoch" number used to detect stale leaders and order elections.
Majority quorum
More than half of all nodes — required to elect a leader or commit a value, guaranteeing at most one winner per term.

Why does Raft require a strict majority of votes to become leader, rather than just the most votes?

We use cookies

We use cookies to enhance your browsing experience, serve personalized content, and analyze our traffic. By clicking "Accept All", you consent to our use of cookies. Learn more

    Day 43: Consensus: Raft election by hand; Paxos conceptually | RBTechIconX