Back to the map

Module 13 · Distributed fundamentals · Lesson 12 of 18

Paxos

The original consensus algorithm, explained as two phases with ballot numbers: prepare and promise, accept and accepted. Why a proposer must adopt any value a majority may already have accepted, how that preserves safety.

DeepNice-to-knowSenior 13 minVideoPro Updated Nov 2026

The video walkthrough is part of Pro.

See what Pro includes
Video walkthrough · 2:56 · narrated, with captions

Why it matters

Paxos is the proof that consensus is achievable with crash failures and an asynchronous network, and every production consensus system is either Paxos, a Paxos variant, or Raft, which was designed as a more teachable Paxos. Interviewers rarely ask you to implement it; they ask whether you understand the one idea that makes it safe, because that idea recurs in every coordination protocol: a proposer must learn what may already have been decided before proposing anything new.

The idea

Paxos has three roles, usually all played by every node: proposers suggest values, acceptors vote, learners find out what was decided. Agreement on a single value proceeds in two phases, each needing a majority of acceptors. Every proposal carries a unique, increasing ballot number (a counter plus the proposer's id).

  1. 1

    Phase 1a: prepare

    A proposer picks a ballot n higher than any it has used and sends prepare(n) to the acceptors.
  2. 2

    Phase 1b: promise

    An acceptor that has not promised a ballot higher than n replies promise(n), including the highest-ballot value it has previously accepted, if any, and commits to ignore any proposal with a ballot below n.
  3. 3

    Phase 2a: accept

    Once the proposer has promises from a majority, it must propose the value from the highest-ballot accepted value among the promises, if any acceptor reported one; only if none did may it propose its own value. It sends accept(n, value).
  4. 4

    Phase 2b: accepted

    An acceptor that has not promised a higher ballot accepts and records (n, value), and tells the learners. When a majority has accepted the same ballot, the value is decided.
Proposerballot 7Acceptor AAcceptor BAcceptor Cprepare(7)promise(7, accepted: (5, x))prepare(7) / accept(7, x)promise / acceptedA had accepted x at ballot 5 → proposer must propose x, not its own value
Two phases, each to a majority. The promise phase reveals any value that might already be decided; the proposer must adopt it, which is what makes Paxos safe.

Why the adoption rule keeps it safe

Suppose value x was accepted by a majority at ballot 5 (so it is decided, even if nobody has learned it yet). Any later proposer at ballot 7 collects promises from a majority, which must overlap the earlier majority in at least one acceptor, and that acceptor reports (5, x). The rule forces the proposer to propose x again. So once a value could have been decided, every subsequent ballot can only re-propose it: no second value can ever be decided. That is agreement, and it holds regardless of crashes, delays or how many proposers compete.

Liveness and duelling proposers

Two proposers can keep outbidding each other with higher ballots so that neither completes phase 2: a livelock. Paxos sidesteps it with randomized backoff or by electing a distinguished proposer. Nothing unsafe happens during the duel; the system simply does not decide, which is FLP's unavoidable price.

Multi-Paxos: a stable leader

Running both phases for every log slot is slow. Multi-Paxos elects a leader that runs phase 1 once for an entire range of slots and then runs only phase 2 (one round trip) per command. The leader proposes commands in order into successive slots; followers accept; a majority acceptance commits. When the leader fails, a new one runs phase 1 again, discovering any slots with possibly-decided values and re-proposing them. This is the shape of every production system described as "Paxos-based": Chubby, Spanner's per-group Paxos, Megastore.

 Single-decree PaxosMulti-PaxosRaft
DecidesOne valueA log of valuesA log of values
Round trips per commandTwoOne with a stable leaderOne with a stable leader
LeaderOptional (distinguished proposer)Elected via phase 1 ballotsElected via terms and votes; log must be up to date to win
Log gapsn/aAllowed; filled laterNot allowed; log is contiguous
SpecificationPrecise but sparse; many details left to implementersFew complete published descriptionsComplete: election, replication, membership, snapshots

Why Raft exists

Paxos's published form is a single-value protocol plus a sketch of Multi-Paxos; the parts that matter in production (leader election, log compaction, membership change) were left as exercises, and teams built subtly different and sometimes incorrect systems. Raft, next lesson, is Multi-Paxos reorganised around a strong leader with a contiguous log and fully specified mechanics, which is why most new systems choose it. Conceptually they are equivalent: both achieve consensus with majorities and the rule that a new leader must learn what may already have been decided.

Paxos · Backplane