Paxos Consensus Algorithm
Paxos and Distributed Consensus
What Paxos Does
Paxos is a family of distributed algorithms for reaching consensus among computers, or nodes. Its purpose is to help a group of nodes agree on one value even when communication is imperfect—for example, when messages are delayed or lost.
A Paxos run is one attempt to agree on a single value. The nodes may begin with different proposed values, but the algorithm is designed to ensure that they do not decide on conflicting values. This makes Paxos useful when a distributed system must apply changes consistently.
A key distinction is between agreeing on a proposal and agreeing on a value:
A proposer may initially suggest a particular value.
Other nodes can influence which value is ultimately chosen.
The goal is not necessarily to preserve any one proposer’s original suggestion; it is to ensure that the system settles on one value.
Consensus can take time to become known throughout the system. A value may already have been chosen by a majority even if some nodes have not yet learned what it is.
Why Distributed Systems Need Consensus
A single computer can serve a growing number of users only up to a practical limit. Once it runs out of capacity, a service may need to distribute its work or data across multiple computers.
Leader-and-replica systems
In a leader-and-replica arrangement, one node acts as the leader and the others hold replicas.
A client sends a proposed write to the leader.
The leader orders the proposed changes and sends them to the replicas.
The replicas apply the changes in the same order.
If the leader becomes unavailable, the system may need consensus to elect a replacement. Without a functioning leader, the system can stop making progress.
Peer-to-peer systems
In a peer-to-peer arrangement, nodes have equivalent roles rather than relying on one permanent leader.
A node shares a proposed operation with other nodes.
The nodes coordinate to decide which operation comes next.
Each node applies the accepted operations in the same order.
Consensus is needed repeatedly to maintain a consistent ordering of operations.
In either design, consensus helps nodes agree on decisions that must be consistent across the distributed system.
Paxos Roles and Operating Assumptions
Paxos describes three roles. A physical server can perform more than one role, and may perform all three.
Proposers
Proposers suggest values for the system to agree on. A proposer begins a round of Paxos by requesting permission to use a proposal number, then may ask acceptors to accept a value.
Acceptors
Acceptors participate in choosing a value. Their responses determine whether a proposal has the support of a majority.
Acceptors must retain relevant protocol state. In particular, they must not forget the promises they have made or the proposals they have accepted. If an acceptor restarted and forgot that state, it might make decisions that undermine the guarantees of the algorithm.
Learners
Learners find out which value has been chosen. They learn a value by observing that a majority of acceptors have accepted it. Learners can then make the result available to other parts of the system.
Majorities and intersecting quorums
Paxos relies on a majority of acceptors, also called a quorum. For a group of N acceptors, a majority contains more than half of them. For example, with three acceptors, a majority is two.
Any two majorities in the same group must overlap in at least one acceptor. This overlap is central to Paxos safety:
A later proposer cannot obtain a majority without contacting at least one acceptor from an earlier majority.
That overlapping acceptor can report what it has already accepted.
The later proposer can then preserve the previously accepted value rather than choosing a conflicting one.
Paxos assumes messages can be delayed or lost, but its acceptors must preserve their state. The basic version discussed here does not protect against acceptors forgetting their protocol history.
One Paxos Run Chooses One Value
A single Paxos run is for one decision: it chooses at most one value. Once a value has been chosen for that run, the run does not later change that decision to a different value.
Systems that need values to change over time use multiple Paxos runs. A distributed storage system, for example, can use one run for each position in a replicated log. Each position represents a separate decision.
The Basic Paxos Algorithm
Paxos uses numbered proposals. Each proposal has an identifier, or proposal number, that is unique and ordered relative to other proposal numbers. A proposer must not reuse a number. In a timeout or retry, it uses a higher number.
The algorithm proceeds in two main phases: a prepare-and-promise phase, followed by an accept-request-and-accept phase.
Phase 1: Prepare and promise
A proposer selects a proposal number and sends a PREPARE request with that number to a majority, or to all, acceptors.
An acceptor compares the request’s number with its existing promises.
If the request is not ruled out by a higher promise, the acceptor promises not to accept proposals with lower numbers.
The acceptor responds with a PROMISE. If it has previously accepted a proposal, it includes that accepted proposal’s number and value in its response.
The promise is important: it prevents the acceptor from subsequently accepting a lower-numbered proposal. The acceptor’s response also supplies the history a later proposer needs to preserve an earlier decision.
If a proposer obtains promises from a majority, it can proceed to the next phase. Because majorities overlap, a lower-numbered proposal cannot independently obtain a majority after a higher-numbered proposal has received a majority of promises.
Phase 2: Accept request and accept
After receiving promises from a majority, the proposer chooses a value and sends an ACCEPT REQUEST with its proposal number and value to a majority of acceptors.
The value-selection rule is crucial:
If none of the promises reports a previously accepted value, the proposer may use its original proposed value.
If one or more promises report accepted values, the proposer must use the value associated with the highest-numbered accepted proposal among those reports.
An acceptor accepts the request if it has not already promised to reject proposals with that number—for example, because it has since made a promise for a higher number. When it accepts, it records the proposal number and value and can notify learners.
When consensus is reached and learned
A value is chosen when a majority of acceptors has accepted that value. A proposer or learner can determine that the value has been chosen after receiving acceptance reports from a majority.
The proposal number is part of Paxos’s internal coordination. The agreement is about the value, not about the proposal number. Later rounds may use higher numbers while still preserving the same chosen value.
The essential sequence is:
A majority promises not to accept lower-numbered proposals.
A majority accepts a proposal number and value, choosing the value.
A proposer or learner observes acceptance from a majority and learns the decision.
Why Later Proposals Preserve an Accepted Value
Consider a group of three acceptors. A majority consists of two. Suppose a proposal numbered 5 is accepted by a majority with the value “cat.”
A later proposer sends a prepare request with number 6. To obtain promises from a majority, it must contact at least one acceptor that accepted proposal 5, because the two majorities must overlap. That acceptor reports the accepted value “cat” in its promise.
The later proposer must therefore use “cat,” even though its own initial proposal may have been different. It can send a new accept request numbered 6, but the value remains “cat.” This is how later rounds can recover and propagate an already chosen value.
The rule also protects the system if a proposer or learner missed the earlier acceptance messages. A later proposer can discover the accepted value through the promises it receives, re-propose it with a higher number, and help the system learn it.
Rejected Proposals and Competing Proposers
A lower-numbered proposal cannot overtake a majority promise
Suppose a majority of acceptors has promised to ignore proposal numbers below 5. Another proposer then sends a prepare request numbered 4.
At least the acceptors in that earlier majority will not promise to the lower number. The second proposer may receive an occasional response from another acceptor, but it cannot obtain a majority of promises. It must time out and retry with a higher number.
Higher-numbered proposals may create contention
Two proposers can compete by repeatedly issuing higher proposal numbers. For example:
One proposer obtains promises for number 5.
Another proposer obtains promises for number 6.
The first proposer retries with number 7.
The second may then retry with a still higher number.
Each new majority of promises can prevent a competing lower-numbered proposal from succeeding. Although this competition does not allow different values to be chosen, it can delay progress.
A common way to reduce this contention is exponential backoff. A proposer waits for progressively longer intervals after repeated failures. The pauses reduce the chance that multiple proposers will keep interrupting one another and give one proposer time to complete both phases.
Paxos’s safety comes from its quorum and value-preservation rules. Its ability to make progress can still be affected by delays, lost messages, unavailable nodes, or repeated competition.
Paxos and Replicated Storage
Paxos can support a distributed storage system by using it to agree on entries in a replicated log.
Why a log is needed
A storage item such as a bank balance changes over time. A single Paxos run cannot represent all those changes, because it chooses only one value.
Instead, the system assigns each change to a new log position:
Position 0 can represent the initial state of an account.
Position 1 can record a deposit of 50, producing a balance of 150.
Position 2 can record a withdrawal of 20, producing a balance of 130.
Each position is a separate Paxos decision. The system can reconstruct the current state by applying the log entries in order.
How replicas use Paxos
Suppose three storage replicas each contain a server acting as a proposer, acceptor, and learner. A client sends a write—such as a withdrawal of 30—to one of the storage servers.
The receiving server acts as a proposer and starts a Paxos run for the next log position.
It sends prepare requests to the acceptors.
Once it receives promises from a majority, it sends an accept request containing the proposed log entry.
If a majority accepts the entry, the value is chosen for that position.
The replicas apply the chosen entries in order to maintain the same stored state.
A majority can choose an entry even if one replica has not yet received it. That replica can catch up later. It may learn the missing entry through a recovery process, or through the values reported in promises when it participates in a later proposal.
This use of Paxos separates two responsibilities:
Paxos chooses the agreed-upon value for each log position.
The storage system applies the chosen sequence of values to maintain its changing data.
The result is a replicated log whose entries are agreed upon in order, allowing multiple storage replicas to converge on consistent state.

Ask anything
We've read this whole study set, so questions about it get the best answers.