01 / 11
Raft vs Paxos
Distributed systems · consensus protocols

Raft vs Paxos

How a cluster of unreliable machines agrees on a single ordering of events.

?
?
?
?
?
A replicated state machine is only as correct as its log.
Every distributed system faces the same question.
How does a cluster agree on one ordering of events?
02 / 11
The problem

The hard part is not agreement

It is that messages arrive late, machines fall silent, and the network can split in two. A split brain leaves each side convinced that the other is gone.

A
B
believes it is the leader
C
D
E
also believes it is the leader
A silent machine may be dead — or merely slow. The network cannot tell you which.
The difficulty is not the agreement itself.
Messages arrive late, and the network can split in two.
03 / 11
Quorums

Quorum: strictly more than half

Q₁ = {1, 2, 3}
1
2
3
4
5
Q₂ = {3, 4, 5}
1
2
3
4
5

Any two majorities must overlap in at least one machine.

|Q| > n2   ⇒   Q₁ ∩ Q₂ ≠ ∅
Both protocols answer this with quorums.
Any two majorities overlap — so a value cannot be forgotten.
04 / 11
Paxos

Paxos — Lamport, 1998

Three roles, and agreement in two round trips.

PROPOSER

Picks a ballot number and drives a value toward a decision.

ACCEPTORS

Five of them. Each remembers the highest ballot it has promised, and the value it last accepted.

LEARNER

Learns the chosen value once a majority has accepted it.

phase 1 · prepare  →  phase 2 · accept
Paxos splits the cluster into three roles.
Proposers, acceptors, and learners — two round trips.
05 / 11
Paxos · protocol

Prepare, then accept

PROPOSER
ballot n = 7
prepare(7)
promise(7, —)
accept(7, v)
accepted · majority
ACCEPTORS
Phase 1 promises never to accept an older ballot. Phase 2: a majority accepts, and the value is chosen.
Phase one: prepare. Acceptors promise not to accept anything older.
Phase two: accept. A majority accepts, and the value is chosen.
06 / 11
Paxos · the cost

The safety proof is short. The engineering is not.

LIVENESS
Progress needs a distinguished proposer. Two proposers can duel forever and starve the protocol.
THE LOG
Single-decree Paxos chooses one value. A replicated log needs multi-Paxos, which the paper does not specify.
GAPS
Leaders crash mid-slot, leaving holes in the log. Filling them safely is left to the implementer.

Google's Chubby team described the result plainly: the protocol has a poor reputation for being difficult to understand, and the gap between paper and running system is where the bugs live.

specification ≠ implementation
The safety argument is beautiful, and short.
Liveness needs a distinguished proposer — and the log is unspecified.
07 / 11
Raft

Raft — Ongaro & Ousterhout, 2014

Designed for understandability, by decomposing consensus into three separate problems.

01
Leader election
02
Log replication
03
Safety
term 1one leader
term 2one leader
term 3one leader
term 4one leader
Time is divided into numbered terms. Each term begins with an election, and has at most one leader.
Raft was designed for understandability.
Three problems: election, replication, and safety.
08 / 11
Raft · election

One leader per term

A follower that hears nothing starts an election, after a randomized timeout that breaks ties.

♛
C
leader · term 3
♛
A
vote ✓
♛
B
vote ✓
♛
D
partitioned
♛
E
timeout 217 ms

Votes from a majority make a candidate leader. The randomization makes split votes rare.

randomized timeout ∈ [150, 300] ms  ·  majority of votes wins the term
One leader per term, chosen by a majority of votes.
Randomized timeouts break ties, so split votes stay rare.
09 / 11
Raft · replication

Log replication and log matching

index12345
leader x = 1term 1 y = 7term 1 z = 4term 2 w = 2term 3 v = 9term 3
follower A x = 1term 1 y = 7term 1 z = 4term 2 w = 2term 3 —
follower B x = 1term 1 y = 7term 1 z = 4term 2 w = 2term 3 pending

Committed through index 4: a majority has stored it. Index 5 exists only on the leader, so it is not yet committed.

same index + same term  ⇒  identical prefix
The leader appends every command and replicates it.
Same index and term means an identical prefix.
10 / 11
Raft · safety

Two invariants do the real work

LEADER COMPLETENESS
A leader holds every entry committed in any previous term. To win an election you must be at least as up to date as a majority — and a majority holds the last committed entry.
STATE MACHINE SAFETY
No two servers apply a different command at the same index. Entries flow in one direction, so a state machine that starts identical stays identical.

A stale leader can still send appends — but its entries cannot reach a majority, so it cannot commit.

commitIndex advances only on a majority acknowledgement
Leader completeness: a leader holds every committed entry.
State machine safety: no two servers diverge at an index.
11 / 11
Comparison

Side by side

PAXOSRAFT
UnderstandabilityCompact proof, subtle to implementDecomposed into three sub-problems
LeaderOptional — needed only for livenessRequired — exactly one per term
LogMulti-Paxos, gaps, unspecifiedLog matching, no gaps, indexed
Membership changeLeft to the implementerJoint consensus, one server at a time
Running in productionChubby, Spanneretcd, Consul, CockroachDB, TiKV, Kafka KRaft
Safety belongs to the algorithm. Liveness belongs to the timeout.
Raft runs in etcd, Consul, TiKV, and Kafka KRaft.
Paxos runs in Chubby and Spanner. Liveness belongs to the timeout.