Consensus Engines · Raft ∕ Paxos 6 acts · distributed systems
SCENE 01 — THE PROBLEM
Machines must agree
5 NODES · CRASH-RECOVER · ASYNCHRONOUS NETWORK
N1 v = 42 N2 v = ? N3 v = 42 N4 v = 42 N5 v = ?
QUORUM Q =N + 12= 3

Any two quorums share a node — so no two decisions can disagree.

SCENE 02 — PAXOS
Two phases, one value
PREPARE → PROMISE → ACCEPT → ACCEPTED
PROPOSER ACCEPTOR A1 ACCEPTOR A2 ACCEPTOR A3 LEARNERS Prepare(n) Promise(n, v′) Accept(n, v) Accepted(n, v) learn v PHASE 1 PHASE 2 COMMIT
PROMISE ∀ a ∈ Qpromise : a.promised ≥ n

Prepare blocks anything older; Accept commits the value once a majority agrees.

SCENE 03 — THE COST OF PAXOS
Correct, and famously hard
MULTI-PAXOS · LOG GAPS · OVERLAPPING PROPOSALS
▸A gap is an instance that never chose a value.
▸A later leader must fill every gap it inherits.
▸Plus leader election, truncation, and membership change.
01 — NO SINGLE SPEC

Papers describe variants. Two engineers can both “know Paxos” and still disagree on the wire format.

02 — DUELING PROPOSERS

Overlapping proposals can livelock; guaranteed progress needs randomised backoff on top.

03 — GREEK TO MANY READERS

Lamport’s own 2001 paper opens by noting the original presentation was “Greek to many readers.”

MULTI-PAXOS instance i → vi  ·  or  ·  ⊥ (gap)

Correct, but hard to teach — and much harder to extend into a full replicated log.

SCENE 04 — RAFT ELECTION
Terms, timeouts, and votes
FOLLOWER → CANDIDATE → LEADER
TERM 1 TERM 2 — ELECTION TERM 3 RequestVote(t, lastIndex, lastTerm) N1 N2 N3 N4 N5 FOLLOWER FOLLOWER CANDIDATE LEADER · TERM 2 FOLLOWER FOLLOWER ✓ ✓ ✓
ELECTION TIMEOUT · 150–300 ms randomised
TERM = monotonic logical clock
QUORUM = ⌊5∕2⌋ + 1 = 3 votes
ELECTION |votes| ≥ ⌊N2⌋ + 1 = 3

A randomised timeout turns a silent follower into a candidate; a majority of votes makes it leader.

SCENE 05 — RAFT REPLICATION
One log, appended only
APPENDENTRIES · MATCHINDEX · COMMITINDEX
AppendEntries commitIndex = 6
RAFT SAFETY INVARIANTS
  • ELECTION SAFETYAt most one leader per term — a candidate needs a majority, and two majorities always overlap.
  • LEADER APPEND-ONLYA leader never overwrites its own log; it only appends new entries.
  • LOG MATCHINGSame index and same term implies every preceding entry is identical.
  • STATE MACHINE SAFETYNo two nodes apply different commands at the same log index.
COMMIT RULE matchIndex ≥ ⌊N + 12⌋ ⇒ commit

Followers only accept an entry if their log matches the leader’s previous entry — so logs never diverge.

SCENE 06 — THE COMPARISON
Same guarantee, different design
SAFETY IS SHARED · UNDERSTANDABILITY IS THE SPLIT
CRITERION
PAXOS
RAFT
CORE MODEL
Two phases per decision: prepare, then accept.
Three sub-problems: elect, replicate, commit.
LEADERSHIP
Optional — Multi-Paxos bolts one on afterwards.
Required — heartbeats plus randomised timeouts.
LOG
One instance per slot; gaps are permitted.
One contiguous, append-only log.
SAFETY ARGUMENT
Quorum intersection alone.
Quorum intersection plus log matching.
RUNS IN
Chubby, and Spanner’s Paxos groups.
etcd, Consul, TiKV, CockroachDB.
SHARED INVARIANT SAFETY ⟺ |Q₁ ∩ Q₂| ≥ 1

Both are safe. Raft trades theoretical minimality for a design you can actually read.