Paxos Consensus Algorithm
Paxos is a family of consensus algorithms for achieving agreement in distributed systems despite failures, pioneered by Leslie Lamport.
Paxos chooses a value through prepare and accept phases over a fixed set of acceptors. Proposal numbers must be unique and totally ordered; acceptors promise not to accept lower-numbered proposals and report their highest accepted proposal. Any two majorities overlap, which preserves safety when each new proposer carries forward the highest accepted value it learns. Paxos does not guarantee progress under arbitrary message delays: a majority must remain reachable, communication must resume, and a proposer must stay active long enough to complete the protocol.
Introduction
Paxos is a family of consensus algorithms for achieving agreement in distributed systems despite failures. Leslie Lamport first published the algorithm in 1998, though he had developed it years earlier in the 1980s. The name comes from a fictional legislative consensus protocol on the island of Paxos, which Lamport used to illustrate how a group of nodes could agree on a value even when some nodes fail or messages get lost.
The problem Paxos solves: how do you get a collection of nodes to agree on a single value when the network is unreliable and nodes can crash? This comes up everywhere from choosing a leader to replicating state across a database cluster.
Core Concepts
Paxos operates in two distinct phases, each serving a specific purpose.
Safety, liveness, and model assumptions
This walkthrough uses a fixed set of acceptors and assumes crash failures, not malicious (Byzantine) behavior. Messages can be lost, duplicated, reordered, or delayed for an arbitrary time. Each proposal number must be unique and totally ordered across proposers; a pair such as (counter, proposer ID) can provide that order. Acceptors must durably remember their highest promise and accepted proposal across restarts.
Safety means that two different values are never chosen for the same decision. Paxos must preserve safety even while messages are delayed or lost. Liveness means that a value is eventually chosen. Paxos cannot guarantee that in a fully asynchronous network with failures. Progress requires a reachable majority, messages that eventually get through, and a proposer that can complete a round without being continually preempted.
Lamport’s Paxos Made Simple describes this message and failure model and separates safety from progress.
Phase 1: Prepare
Before a proposer can suggest a value, it needs to secure the right to be heard. Phase 1 handles exactly that: establishing priority and finding out what other proposers may have already slipped in.
The proposer picks a fresh, globally unique number, then sends prepare messages to a majority of acceptors. Each message says in effect: “I’m proposing something with this number. Don’t accept anything lower.”
When an acceptor gets a prepare request, it checks whether the proposal number is at least as high as its existing promise. If so, it records the promise and sends back the highest-numbered proposal it has accepted so far, if any. The proposer must carry forward the highest accepted value reported by its promise quorum, even when the earlier proposal was not known to have reached a majority.
If the proposal number is lower than the acceptor’s existing promise, the request is rejected. The proposer can retry Phase 1 with a higher number.
Here is a round where a previous value has already been accepted by a majority, but the proposer did not receive the acknowledgements. The next proposer must learn and carry that value forward:
sequenceDiagram
participant P0 as Earlier proposer
participant P as New proposer
participant A1 as Acceptor 1
participant A2 as Acceptor 2
participant A3 as Acceptor 3
P0->>A1: Accept(n=4, v="x")
P0->>A2: Accept(n=4, v="x")
Note over P0,A3: P0 does not receive the acknowledgements; x is still chosen by 2 of 3 acceptors
Note over P,A3: Phase 1: Prepare
P->>A2: Prepare(n=5)
P->>A3: Prepare(n=5)
A2-->>P: Promise(n=5, accepted=(4, "x"))
A3-->>P: Promise(n=5, accepted=nil)
Note over P: P must propose x, the highest accepted value it learned
Note over P,A3: Phase 2: Accept
P->>A2: Accept(n=5, v="x")
P->>A3: Accept(n=5, v="x")
A2-->>P: Accepted(n=5, v="x")
A3-->>P: Accepted(n=5, v="x")
Acceptor 2’s promise has two effects: it rejects later accept requests numbered below 5, and its response reveals the earlier accepted value. A proposer that receives a majority of promises must use the highest-numbered accepted value in those responses, if one exists. If every response reports no accepted proposal, it may use its own value.
Phase 2: Accept
If the proposer receives promises from a majority, it can send Phase 2 accept requests. That promise quorum is not a decision. A value is chosen only after a majority accepts the same proposal number and value.
sequenceDiagram
participant P as Proposer
participant A1 as Acceptor 1
participant A2 as Acceptor 2
participant A3 as Acceptor 3
rect rgb(40, 40, 60)
Note over P,A3: Phase 1: Prepare
P->>A2: Prepare(n=5)
P->>A3: Prepare(n=5)
A2-->>P: Promise(n=5, accepted=(4, "x"))
A3-->>P: Promise(n=5, accepted=nil)
end
rect rgb(40, 60, 40)
Note over P,A3: Phase 2: Accept
P->>A2: Accept(n=5, v="x")
P->>A3: Accept(n=5, v="x")
A2-->>P: Accepted(n=5, v="x")
A3-->>P: Accepted(n=5, v="x")
end
Note over P,A3: x is chosen after both acceptors accept proposal 5
Why Majority Matters
For a fixed set of N acceptors, a proposal is chosen when a majority accepts that same proposal. A majority of prepare responses only lets the proposer proceed to Phase 2; it does not choose a value. A majority can still be unreachable, so quorum size alone does not guarantee progress.
Any two majorities overlap. That overlap supports safety because the new proposer asks a majority to promise and report its highest accepted proposal, then carries the highest reported value forward. Overlap by itself is not enough if the proposer ignores those reports. With N acceptors, a majority quorum tolerates up to floor((N - 1) / 2) crash failures, provided the remaining majority can communicate.
The Role of Proposal Numbers
Proposal numbers provide a total order across proposals. A proposer must never reuse a number, and different proposers must not generate the same one. Implementations often combine a proposer ID with a persistent counter so each proposer can choose a fresh, globally unique number after a restart.
Unique, ordered numbers let acceptors reject stale requests. If two proposers compete, a higher-numbered prepare may preempt a lower one, but the higher proposer still has to follow the Phase 1 rule and preserve any previously accepted value it learns.
Practical Considerations
Implementing Paxos correctly is notoriously difficult. The original paper reads like a story rather than a specification, which has led to many misconceptions. Chubby (Google’s lock service) and many distributed databases use variants of Paxos, but most production implementations differ from the textbook algorithm in subtle ways.
Multi-Paxos extends the basic algorithm to agree on a sequence of values, which is more useful for building replicated state machines. You can read about this extension in my Multi-Paxos post.
Relationship to CAP Theorem
Paxos preserves agreement during a partition, but progress depends on quorum reachability. A side that can still communicate with a majority may choose a value; a minority side cannot. If no proposer can reach a majority, new decisions wait. The CAP Theorem post covers the broader availability and consistency trade-off.
Failure Scenarios
Proposer Crash During Phase 1
A proposer sends prepare messages to a majority of acceptors and receives promises back. At this point the proposer has the right to send accept messages, but it has not yet done so. If the proposer crashes before sending accepts, the promises remain active on the acceptor side.
Each acceptor that promised proposal number N will reject an accept request numbered below N. After recovery, the proposer can retry Phase 1 with its original number if no higher promise has superseded it. If any acceptor it needs has promised a higher number, the proposer must begin a new round with a fresh, higher number.
When Proposer B sends prepare messages with a higher number, the acceptors that already promised to Proposer A will update their promised_id to B (since B’s number is higher). B collects its majority of promises, possibly learning of any value that was accepted in the interim. If no value was accepted, B proceeds with its own value. If a value was already accepted by a majority, B adopts that value and tries to commit it with its higher proposal number. No value committed by a majority can be lost in this process.
sequenceDiagram
participant P1 as Proposer A
participant P2 as Proposer B
participant A1 as Acceptor 1
participant A2 as Acceptor 2
participant A3 as Acceptor 3
P1->>A1: Prepare(n=5)
P1->>A2: Prepare(n=5)
P1-xA3: Prepare(n=5) --timeout-->
Note over P1,A3: P1 crashes here
P2->>A1: Prepare(n=6)
P2->>A2: Prepare(n=6)
P2->>A3: Prepare(n=6)
A1-->>P2: Promise(n=6, none)
A2-->>P2: Promise(n=6, none)
A3-->>P2: Promise(n=6, none)
Note over P2,A3: P2 collects majority with n=6
P2->>A1: Accept(n=6, v="x")
P2->>A2: Accept(n=6, v="x")
P2->>A3: Accept(n=6, v="x")
Note over P2,A3: Value "x" chosen
Acceptor Crash
Acceptors can crash at any point, and the algorithm tolerates this as long as a majority remains operational. The critical case is when an acceptor accepts a proposal, sends the Accepted response, and then crashes before the proposer receives it.
The proposer only needs majority acknowledgments to consider a value chosen. When Acceptor 3 crashes after accepting but before its Accepted message arrives, the proposer has already received Accepted messages from Acceptors 1 and 2, giving it a majority. The value is considered chosen even though one acceptor that accepted never confirmed receipt. The quorum property guarantees that any future majority will overlap with this one.
An acceptor must persist its highest promise and accepted proposal/value before acknowledging them. After a restart, it restores that state rather than returning as a blank acceptor. If it forgets an earlier acceptance, a later proposer could miss information needed to preserve safety. Learners may still need to tell a recovering acceptor which value was chosen, but that does not replace durable acceptor state.
This contrasts with a proposer crash. If a majority accepted the proposal, the value is chosen even if the proposer never learned that its acknowledgements arrived. A new proposer still runs Phase 1 and uses the accepted state it learns. If only a minority accepted, the proposal was not chosen, but the durable acceptor state still informs later rounds.
sequenceDiagram
participant P as Proposer
participant A1 as Acceptor 1
participant A2 as Acceptor 2
participant A3 as Acceptor 3
P->>A1: Prepare(n=5)
P->>A2: Prepare(n=5)
P->>A3: Prepare(n=5)
A1-->>P: Promise(n=5)
A2-->>P: Promise(n=5)
A3-->>P: Promise(n=5)
P->>A1: Accept(n=5, v="y")
P->>A2: Accept(n=5, v="y")
A1-->>P: Accepted
A2-->>P: Accepted
Note over P,A3: Majority (2 of 3) achieved — value "y" chosen
P->>A3: Accept(n=5, v="y") --never responds (crashed)-->
Note over A3: A3 restores any promise or acceptance from durable state
Network Partition
Network partitions split the acceptor group into subgroups that cannot communicate. With fixed membership, at most one disjoint subgroup can contain a majority. A proposer on a majority side may continue; a minority side cannot choose a value.
On the side with a majority, a proposer may make progress if messages eventually arrive and it can complete both phases without being continually preempted. On the isolated side, a proposer cannot collect a majority of promises, so it cannot choose a new value. It may time out and retry with a higher number, but the partition prevents that retry from making progress.
When the partition heals, a proposer starts a new prepare round with a fresh proposal number. Its majority of promise responses reports accepted proposals, and the proposer carries forward the value attached to the highest-numbered one. A higher proposal number does not make its value win by itself; the Phase 1 rule preserves any value that may already have been chosen.
Two majorities overlap, and the prepare rule uses that overlap to preserve safety. A majority that remains connected can make progress if a proposer can complete both phases. A minority cannot choose a value on its own.
sequenceDiagram
participant Left as Left Partition
participant Right as Right Partition
Note over Left: Proposer L1 has majority (3 nodes)
Note over Right: Proposer R1 isolated, no majority
Left->>Left: Propose(n=7, v="left")
Note over Left: Value "left" chosen in left partition
Right->>Right: Propose(n=5, v="right")
Note over Right: No progress in right partition
Note over Left,Right: Partition heals
Note over Left,Right: A new proposer gathers a majority of promises at n=8
Note over Left,Right: The quorum reports accepted (n=7, "left")
Note over Left,Right: The proposer carries "left" into Phase 2
Note over Left,Right: A majority accepts "left" at n=8
Acceptor and Proposer Roles — Pseudo-code
# Acceptor state
promised_id = -1
accepted_id = -1
accepted_value = None
def on_prepare(proposal_id):
if proposal_id >= promised_id:
promised_id = proposal_id
return Promise(promised_id, accepted_id, accepted_value)
return Reject(promised_id)
def on_accept(proposal_id, value):
if proposal_id >= promised_id:
promised_id = proposal_id
accepted_id = proposal_id
accepted_value = value
return Accepted(accepted_id)
return Reject(promised_id)
# Proposer state
proposal_id = None
value = None
def on_propose(original_value):
proposal_id = generate_unique_id()
responses = send_prepare_to_all(proposal_id)
promises = [r for r in responses if r.type == "Promise"]
if len(promises) >= majority:
accepted = [r for r in promises if r.accepted_id != -1]
if accepted:
value = max(accepted, key=lambda r: r.accepted_id).accepted_value
else:
value = original_value
accepted_responses = send_accept(proposal_id, value)
if count_matching_accepts(accepted_responses, proposal_id, value) >= majority:
announce_chosen(value)
The proposer announces a chosen value only after responses show that a majority accepted the same proposal. A majority of promises is not enough.
Common Pitfalls / Anti-Patterns
Here is what goes wrong without a designated proposer. Two nodes keep outbidding each other. Each one proposes a higher number, collects promises from a majority, but then the other jumps in with an even higher number before the first can send its accept messages. No value ever gets chosen — just an infinite loop of higher and higher proposal numbers.
sequenceDiagram
participant P1 as Proposer A
participant P2 as Proposer B
participant A1 as Acceptor 1
participant A2 as Acceptor 2
participant A3 as Acceptor 3
P1->>A1: Prepare(n=1)
P1->>A2: Prepare(n=1)
P1->>A3: Prepare(n=1)
A1-->>P1: Promise(n=1)
A2-->>P1: Promise(n=1)
Note over P1,A3: P1 collecting majority...
P2->>A1: Prepare(n=2)
P2->>A2: Prepare(n=2)
P2->>A3: Prepare(n=2)
A1-->>P2: Promise(n=2, higher!)
A2-->>P2: Promise(n=2)
Note over P1,A3: P2 preempts P1's n=1
P1->>A1: Prepare(n=3)
P1->>A2: Prepare(n=3)
A1-->>P1: Promise(n=3, higher!)
Note over P1,A3: P1 preempts P2's n=2
P2->>A1: Prepare(n=4)
Note over P1,A3: ...continues indefinitely
Choosing a stable distinguished proposer reduces this livelock. It supports progress only when that proposer can communicate with a majority and messages eventually arrive; safety does not depend on a successful leader election.
Limitations
Paxos is not the fastest consensus algorithm. The two phases of communication introduce latency, and the algorithm is not designed for high-throughput scenarios. It prioritizes safety over performance.
Paxos alone does not specify how to choose a leader. Without a distinguished proposer, multiple nodes may try to propose simultaneously, leading to livelock. In practice, leaders are often chosen separately using techniques like leader election.
When to Use Paxos
Paxos is the right choice when:
- Correctness is paramount: When your application cannot tolerate divergent state (e.g., financial systems, distributed databases)
- You need a proven foundation: Paxos has formal correctness proofs and decades of analysis behind it
- You’re building infrastructure: Paxos forms the basis for systems like Chubby, Zookeeper (via Zab), and Google’s Spanner
- You need flexibility: Multi-Paxos adapts to sequences of values, making it suitable for replicated state machines
Paxos is not ideal when:
- Throughput matters more than safety: Raft’s leader-centric design often provides better performance
- You need operational simplicity: Raft’s clearer separation of concerns makes it easier to implement and debug
- Your team needs to maintain the code: Raft’s understandability advantage matters for long-term maintenance
Interview Questions
Paxos solves the consensus problem: achieving agreement among a distributed group of nodes on a single value, even when nodes can crash, messages can be lost, and the network is unreliable. It guarantees safety—if any node decides a value has been chosen, no other node can choose a different value for that same decision.
Phase 1 (Prepare): A proposer uses a fresh, globally unique proposal number and gathers promises from a majority. Each promise rejects lower-numbered proposals and reports the acceptor's highest accepted proposal, if any.
Phase 2 (Accept): The proposer carries forward the value from the highest-numbered accepted proposal in the promise responses. If none was reported, it may use its own value. The value is chosen only after a majority accepts the same proposal.
A majority quorum can tolerate up to floor((N - 1) / 2) crash failures when the remaining majority can communicate. Any two majorities overlap, and Phase 1 uses that overlap to learn accepted proposals. A majority of promises is not a chosen value, and a quorum by itself does not guarantee progress.
Proposal numbers define a total order. Each proposer must use a fresh number, and different proposers must use disjoint number ranges or another scheme that guarantees uniqueness. A persistent counter combined with a proposer ID is one common approach.
If a proposer restarts with its same proposal number, it can retry while its promises remain valid. An acceptor that has since promised a higher number rejects the old accept request. To start a new round, the proposer must use a fresh higher number, gather a majority of promises, and carry forward the highest accepted value it learns.
If an acceptor crashes after accepting a proposal but before its response reaches the proposer, a value is chosen only if a majority accepted that same proposal. The acceptor must persist its promise and accepted proposal/value so it can restore them after a restart; forgetting them can break safety.
Livelock can occur when competing proposers keep preempting one another with higher proposal numbers. A stable distinguished proposer can support progress if it can reach a majority and messages eventually arrive. Paxos safety still holds while progress is delayed.
Paxos safety prevents two values from being chosen for the same decision. During a partition, a proposer with a reachable majority may still make progress; a minority cannot. If no proposer can reach a majority, new decisions wait until communication recovers.
Multi-Paxos extends the basic single-decree Paxos algorithm to agree on a sequence of values, making it suitable for building replicated state machines. It optimizes by skipping Phase 1 for consecutive proposals when a leader is stable, reducing the communication rounds from 2 RTTs to 1 RTT per decision.
Paxos: Leader is optional (can be leaderless), high complexity, steep learning curve, classical correctness proofs. Typical latency is 2-3 RTTs per decision.
Raft: Strong leader assumption (single leader), medium complexity, clearer separation of concerns making it easier to implement. Typical latency is 1-2 RTTs with a stable leader, providing better throughput.
The Byzantine Generals Problem deals with achieving consensus in a system where nodes can send conflicting or malicious information (not just fail silently). Paxos assumes "fail-stop" failures where crashed nodes simply stop responding. Byzantine Fault Tolerance (BFT) algorithms like PBFT handle the stronger threat model. Paxos provides safety under fail-stop failures but not under Byzantine failures.
During a partition, a proposer on a minority side cannot gather a majority of promises, so it cannot choose a new value. A proposer that can reach a majority may continue. After communication recovers, a new prepare quorum reports accepted proposals, and the proposer must carry forward the highest-numbered accepted value it learns. The number alone does not determine which value is chosen.
Paxos is not the fastest consensus algorithm due to its two-phase communication overhead. It prioritizes safety over performance. Paxos alone does not specify how to choose a leader—without a distinguished proposer, multiple nodes may try to propose simultaneously, leading to livelock. It is complex to implement correctly, and the original paper is notoriously difficult to read.
Several prominent systems use Paxos: Google's Chubby (lock service), Google Spanner (distributed database), CockroachDB, TiKV, and etcd all use consensus protocols derived from or inspired by Paxos. ZooKeeper uses Zab, a related protocol. Microsoft's Azure uses Paxos variants for state machine replication.
Basic Paxos does not specify reconfiguration, making it complex to add or remove nodes. Joint consensus is one approach where a special joint quorum of old and new configuration must agree. Many production implementations develop custom reconfiguration schemes that extend the core Paxos algorithm.
Learners are acceptors that have accepted a value but need to propagate this information to other nodes that did not participate directly. When a learner receives accepted messages from a majority, it can inform other interested nodes (replicas) that a value has been chosen. Learners are part of the classic Paxos formulation but are often simplified in implementations.
Paxos was published in a single paper that reads like a mathematical proof mixed with narrative, using the fictional Paxos legislative protocol as an analogy. The algorithm is not clearly separated into independent components. Raft was designed specifically to be more understandable, with clear separation of leader election, log replication, and safety, and uses more concrete descriptions.
Viewstamped Replication is a consensus protocol developed independently by Barbara Liskov and Brian Oki around the same time as Paxos. Like Paxos, it achieves consensus in asynchronous systems with failures. VSR uses a view-change mechanism similar to Paxos's Phase 1, and both protocols have similar fault tolerance characteristics (majority quorum). They are functionally equivalent in terms of safety guarantees.
Any later prepare quorum overlaps with the majority that accepted the proposal. The overlapping acceptor reports its highest accepted proposal, and the new proposer must carry forward the highest accepted value reported by its quorum. The promise also prevents the overlapping acceptor from accepting an older proposal. This Phase 1 rule, not the higher number by itself, preserves the chosen value.
Several optimizations are used in practice: Multi-Paxos optimizes consecutive agreements by skipping Phase 1 when a leader is stable. Read-your-writes consistency can be achieved by tagging reads with the current proposal number. Leases reduce RTTs for reads. Some implementations use batching to group multiple proposals. Cheap Paxos uses fewer nodes for recovery. Fast Paxos attempts to reduce latency with larger quorums.
Further Reading
- Multi-Paxos - Extending Paxos for sequence of values and replicated state machines
- Raft Consensus Algorithm - A more understandable consensus alternative to Paxos
- CAP Theorem - Understanding the consistency vs. availability trade-off
- Consistency Models - The broader landscape of consistency guarantees in distributed systems
- Leslie Lamport’s Paxos Made Simple - The original 2001 paper
- The Part-Time Parliament - Lamport’s original 1998 Paxos paper with the fictional legislative origin story
- Fischer, Lynch, and Paterson on asynchronous consensus - The impossibility result behind Paxos’s liveness assumptions
- Raft Paper - “In Search of an Understandable Consensus Algorithm”
Quick Recap Checklist
Before deploying a system based on Paxos, verify:
- You need consensus for a single or sequence of values in a distributed system
- Fault tolerance is required (system must continue despite node failures)
- Membership and crash-failure assumptions are explicit
- Proposal numbers are globally unique and totally ordered
- A majority quorum is reachable for the required failure threshold
- Liveness depends on eventual communication and a proposer that can complete a round
- You have a plan for leader election to prevent livelock
- Your implementation handles Phase 1 failures and retries correctly
- Acceptor state is persisted to survive crashes
- You understand the difference between Paxos (fail-stop) and Byzantine fault tolerance
- For multi-value decisions, you are using Multi-Paxos or an equivalent
- Cluster reconfiguration is handled if nodes need to be added or removed
Consensus Algorithm Comparison
| Algorithm | Leader Assumption | Complexity | Reconfiguration | Correctness Proof | Learning Curve |
|---|---|---|---|---|---|
| Paxos | Optional (can be leaderless) | High | Complex | Classical | Steep |
| Raft | Strong (single leader) | Medium | Joint consensus | In paper | Moderate |
| VSR | Within view | Medium | View changes | Formal | Moderate |
| Zab | Primary-backup | Medium | Static | Formal | Moderate |
| Algorithm | Typical Latency | Throughput | Fault Tolerance (2f+1 members) | Production Use |
|---|---|---|---|---|
| Paxos | 2-3 RTTs per decision | Moderate | f+1 acceptors per quorum | Chubby, Spanner |
| Raft | 1-2 RTTs (with leader) | High | f+1 nodes per quorum | etcd, CockroachDB, TiKV |
| VSR | 1-2 RTTs | Moderate | f+1 replicas per quorum | CORFU, some Zab variants |
| Zab | 1-2 RTTs | High | f+1 nodes per quorum | ZooKeeper |
Conclusion
Paxos preserves safety despite arbitrary message delays and crash failures, under its stated membership and acceptor-state assumptions. It does not guarantee progress in a fully asynchronous system; progress needs a reachable majority, eventual message delivery, and a proposer that is not continually preempted. Despite its complexity, understanding Paxos provides a foundation for reasoning about practical consensus protocols such as Raft.
If you want to go deeper, my post on Consistency Models explores how consensus fits into the broader landscape of consistency guarantees in distributed systems.
Category
Related Posts
Multi-Paxos
Multi-Paxos extends basic Paxos to achieve consensus on sequences of values, enabling practical replicated state machines for distributed systems and databases.
View-Stamped Replication
View-Stamped Replication (VSR) is a distributed consensus protocol that uses views and timestamps to achieve agreement in asynchronous systems.
The FLP Impossibility Result
The FLP result shows that deterministic consensus cannot guarantee termination in a fully asynchronous message-passing system with one possible crash failure.