PAXOS
Consensus in two phases
Paxos runs in two phases: prepare(n) asks acceptors to promise ballot n, then accept(n, v) asks them to accept value v at that ballot. Three acceptors; X is already chosen: A1 and A2 accepted (1, X). P2, which wants Y, sends prepare(2) to A2 and A3 and gets both promises. What does P2 send?
Paxos lets a set of acceptors agree on one value even when proposers race and messages are lost. A proposer picks a ballot n and sends prepare(n). Each acceptor promises to ignore lower ballots and reports any value it already accepted. With a majority of promises the proposer sends accept(n, v). A value is chosen once a majority accepts the same ballot.
The rule people drop: v is not the proposer’s choice. If any promise reports an accepted value, v must be the one with the highest ballot. That value may already be chosen. Any two majorities overlap, so the next proposer always hears from an acceptor that holds it, and the highest-ballot value it hears is that chosen value.
Single-decree Paxos
PHASE 1 proposer picks a ballot n, unique and higher than any it has used
-> prepare(n) to the acceptors
acceptor: if n > promised:
promised = n
reply promise(n, accepted) // accepted = (n', v') or none
else reject
PHASE 2 with promises from a majority:
v = value of the highest-numbered accepted (n', v') among the promises
or, if none reported one, the proposer's own value
-> accept(n, v)
acceptor: if n >= promised:
promised = n; accepted = (n, v); reply accepted
else reject
CHOSEN a majority accepted the same (n, v)
Safety any two majorities share an acceptor, so a later proposer
always hears about a chosen value and must re-propose it.
Liveness not guaranteed: duelling proposers can pre-empt each other
forever. Multi-Paxos elects a stable leader to stop the duel. Watch the “chosen” line in the ACCEPTORS box. BROKEN: IGNORE PROMISES ends with X and Y both chosen. FIX: ADOPT HIGHEST runs the same messages and ballot 2 re-chooses X. DUELLING PROPOSERS never breaks safety. Ballots climb 1, 2, 3 (P1 takes odd numbers, P2 even, so P1’s next is 5). No accept reaches a majority. A1’s lone acceptance of (1, X) is why the stable leader’s ballot 5 re-proposes X.
P2 runs the buggy proposer: it sends its own value Y no matter what the promises report. Every message is a step. Order them so that both X and Y end up chosen.
GOAL: X and Y are both chosen
Return { onPrepare, onAccept, chooseValue }. An acceptor is { promised, accepted } with accepted = { n, value } or null. onPrepare(acc, n) promises if n is higher than anything promised and returns { ok, accepted }. onAccept(acc, n, value) accepts unless it promised a higher ballot, and returns true or false. chooseValue(promises, myValue) gets a majority of promises and returns the value to propose. The grader replays two proposers against your rules.
Google Chubby and Spanner (Multi-Paxos), Apache ZooKeeper (Zab, a close relative), Cassandra lightweight transactions (Paxos per partition), and every Raft cluster, which is Multi-Paxos with the leader election made explicit. Bugs live in the recovery path: a new leader that does not adopt in-flight values from the old one.
“Walk me through Paxos. Why does it need two phases?” Explain prepare and promise, accept and chosen, why the proposer must adopt the highest-numbered accepted value, why two majorities guarantee it hears about a chosen value, and why duelling proposers threaten liveness but not safety. Compare to Raft's leader election and log matching.