Distributed Systems Consensus
Paxos: Reaching Agreement in an Unreliable Distributed System
Distributed systems often contain many computers that must behave as though they were one reliable machine. This creates a fundamental challenge: several computers may receive different instructions, messages may arrive late or disappear, and some computers may crash. Nevertheless, the system must agree on one result.
Paxos is a consensus algorithm designed for this situation. Its central purpose is to allow distributed processes to agree on a single value without allowing conflicting values to be chosen, even when the network and individual computers are unreliable.
The Consensus Problem
Consensus is the problem of getting a collection of independent processes to agree on one value.
A process may be a physical computer, a virtual machine, or a software component running on a server. Processes can propose values, but they may propose different or conflicting values. For example:
- One process proposes depositing $100 into an account.
- Another proposes withdrawing $50.
- Several servers may receive these proposals in different orders.
- Some servers may crash before reporting what they received.
The purpose of consensus is not necessarily to ensure that every proposed value is used. Instead, the system must select one legitimate value as the final decision for a particular decision instance.
Consensus chooses one agreed-upon value and makes that value the single source of truth for that decision.
This is important whenever multiple computers maintain copies of the same information. In an online game, for example, many servers may process actions involving a rare item. Consensus ensures that one consistent update is selected, so one server does not report that a player owns a sword while another reports that the sword belongs to someone else.
Consensus is also useful in configuration services. A shared configuration service may provide settings to many applications. If one application uses an old configuration while another uses a new one, the system can behave inconsistently. Consensus helps all components agree on the current configuration.
Consensus is not the same as simple communication
If the network were perfectly reliable, every process could simply send its proposal to every other process and follow a predetermined rule. Real distributed systems cannot assume this simplicity. A message might be delayed, duplicated, or lost, and a process might stop responding.
Therefore, consensus must deal with uncertainty:
- A slow computer may appear to have crashed.
- A delayed message may appear to have been lost.
- A restarted computer may no longer remember its previous decisions.
- Two proposals may be active at the same time.
The algorithm must remain safe despite not knowing exactly what is happening.
Think About It
Why is it dangerous for two servers to make different decisions about the same bank transaction, game item, or database operation?
Safety and Liveness
A useful consensus algorithm must satisfy two broad categories of requirements: safety and liveness.
Safety: never choose an incorrect or conflicting result
Safety means that the system never violates its correctness rules, regardless of delays or crashes. The key safety requirements are:
-
Only proposed values may be chosen.
The system cannot invent a value that no process proposed. -
At most one value may be chosen.
Two different values cannot both become the decision for the same consensus instance. -
A process learns that a value was chosen only when a value actually was chosen.
A process must not act on a false report of agreement.
The second rule is the heart of consistency. If one value is chosen for a particular decision, the system must never later choose a different value for that same decision.
For example, if a consensus instance chooses “deposit $100,” it cannot later choose “withdraw $50” for that same instance. The chosen result is permanent.
Liveness: eventually make progress
Liveness means that the system eventually makes useful progress.
Paxos aims for two liveness properties:
- Eventually, some proposed value is chosen.
- Once a value has been chosen, processes eventually learn what that value is.
A system that never makes a wrong decision but also never makes any decision is safe but not useful. This creates a tension:
- Safety prevents harmful contradictions.
- Liveness prevents the system from becoming permanently stuck.
In highly unpredictable environments, guaranteeing both perfectly is difficult. Paxos is designed so that safety remains dependable, while progress may require additional mechanisms such as leader election and timeouts.
Think About It
Would a system that never chooses any value be safe, live, both, or neither?
Why a Single Decision-Maker Fails
The simplest design is to appoint one process as the sole decision-maker. Proposers send their values to this central acceptor, and the acceptor chooses one.
This approach is easy to understand and may work when nothing fails. However, it has a critical weakness: the single acceptor is a single point of failure.
If that process crashes or becomes disconnected from the network:
- No new value can be chosen.
- Other processes cannot safely replace it without additional coordination.
- The entire system stops making progress.
Distributed systems are often built precisely to avoid depending on one component. A consensus algorithm therefore needs multiple acceptors so that the failure of some machines does not automatically stop the system.
The System Model
Paxos operates under an asynchronous, non-Byzantine model.
Asynchronous behavior
“Asynchronous” means that the system does not assume fixed timing guarantees.
Processes may:
- Run at different speeds.
- Pause for an unpredictable amount of time.
- Crash and later restart.
- Take arbitrarily long to respond.
Messages may:
- Be delayed for an arbitrarily long time.
- Be duplicated.
- Be lost entirely.
The system cannot reliably determine whether a process is merely slow or has crashed. Likewise, it cannot immediately know whether a message is delayed or permanently lost.
Non-Byzantine behavior
“Non-Byzantine” means that processes are not malicious and do not intentionally lie. A process may crash, restart, or operate slowly, but it does not deliberately send contradictory or corrupted information.
Messages can be delayed, duplicated, or lost, but they are not changed into false messages. What arrives is what was originally sent.
This assumption distinguishes Paxos from algorithms designed to tolerate Byzantine faults, in which processes may behave maliciously or send arbitrary false information.
Stable storage
Because a process may crash and restart without remembering its in-memory state, important information must be stored in stable storage.
Stable storage is durable memory that survives a process failure or power loss. Examples include:
- Disk storage.
- Write-ahead logs.
- Journaling systems.
- Nonvolatile or persistent memory.
An acceptor must remember at least:
- The highest proposal number to which it has promised.
- The highest-numbered proposal it has accepted.
If an acceptor forgot these facts after restarting, it could accept an older conflicting proposal and undermine the safety guarantees.
Proposers do not require stable storage for safety in the same way. A proposer may abandon an unsuccessful attempt and forget its details, provided that any later attempt uses a new, higher proposal number.
The Three Logical Roles
Paxos separates responsibilities into three logical roles. A single physical computer may perform all three roles simultaneously; the separation is conceptual.
Proposers
Proposers suggest values. A proposer might request:
- Setting an account balance to a particular value.
- Executing a transaction.
- Recording a game action.
- Adding a command to a replicated log.
A proposer begins the process of trying to get one value chosen.
Acceptors
Acceptors determine which proposals can become chosen. They receive proposal messages and record accepted proposals.
Acceptors preserve consistency by:
- Remembering promises made to higher-numbered proposals.
- Reporting previously accepted proposals.
- Refusing proposals that conflict with a higher promise.
Acceptors are the central participants in Paxos safety.
Learners
Learners find out which proposal was chosen. Once they learn the result, they can update their local state or perform the required action.
A learner does not necessarily participate in deciding the value. Its main responsibility is to discover and use the result.
Majorities and the Safety of Overlap
A value becomes chosen when the same proposal has been accepted by a majority of acceptors.
Suppose there are five acceptors. A majority is three. Any two groups of three acceptors must share at least one acceptor.
For example:
- Group A: acceptors 1, 2, and 3.
- Group B: acceptors 3, 4, and 5.
Both groups contain acceptor 3.
This overlap is the mathematical foundation of Paxos safety. If one proposal is accepted by a majority and another proposal is also accepted by a majority, at least one acceptor belongs to both majorities.
If acceptors could accept only one conflicting value for a decision instance, the shared acceptor would prevent two different values from both being chosen.
A majority also provides fault tolerance. With five acceptors, the system can continue making progress if two acceptors fail, because three remain available. However, if three fail, a majority is no longer available, so progress may stop.
Why not require every acceptor?
Requiring every acceptor would make progress depend on every machine being available. One failed or disconnected acceptor could prevent all decisions.
A majority is a compromise:
- It is large enough to guarantee overlap.
- It is small enough to continue operating when some machines fail.
Think About It
With seven acceptors, how many acceptors are needed for a majority, and why must any two majorities overlap?
Proposal Numbers
Multiple proposers create a problem. Suppose proposer A proposes value X while proposer B proposes value Y. If acceptors simply accept the first proposal they see, messages may be divided between the two values.
For example, with five acceptors:
- Some acceptors accept X.
- The others accept Y.
- Neither value reaches a majority.
The system becomes stuck even though no safety rule has been violated.
To manage multiple attempts, Paxos identifies each proposal using a unique, increasing number. A proposal is represented as:
(n,V)where:
- n is the proposal number.
- V is the proposed value.
For example, (101,X) means proposal number 101 carrying value X.
The proposal number allows acceptors to distinguish between different attempts and rounds. An acceptor may accept multiple proposals over time, but it must obey the ordering rules imposed by proposal numbers.
A proposal is chosen only when that specific numbered proposal and value are accepted by a majority.
The Development of Paxos Safety Rules
Paxos safety can be understood as a sequence of increasingly strong requirements.
Rule P2: preserve the value after it is chosen
The first important rule is:
If a proposal carrying value V is chosen, every higher-numbered proposal that is chosen must also carry value V.
If proposal (101,X) is chosen, then proposal (105,Y) must not later be chosen. Any later chosen proposal must carry X.
This protects the permanent nature of a decision.
Rule P2A: constrain individual acceptances
P2 is not strong enough operationally. It controls proposals that become chosen, but an acceptor could accept a conflicting higher-numbered proposal before that proposal reaches a majority.
P2A strengthens the rule:
If a proposal carrying value V is chosen, every higher-numbered proposal accepted by any acceptor must also carry value V.
Under P2A, once (101,X) has been chosen, an acceptor must not accept (105,Y). It may accept (105,X), but not a conflicting value.
This pushes the safety requirement down from the level of majorities to the level of individual acceptors.
Rule P2B: constrain issued proposals
Even P2A leaves a practical problem. A proposer may be unaware that (101,X) has already been chosen and may attempt to issue (105,Y).
P2B therefore states:
If a proposal carrying value V is chosen, every higher-numbered proposal issued by any proposer must carry value V.
This rule prevents a conflicting proposal from being issued at all. The difficulty is determining how a proposer can know which value it is required to use.
Rule P2C: the practical invariant
P2C provides the operational condition that allows P2B to be maintained.
Before issuing proposal (N,V), a proposer must identify a majority set of acceptors, called S, and ensure one of two conditions:
- No acceptor in S has accepted any proposal numbered lower than N.
- If acceptors in S have accepted earlier proposals, V must be the value of the highest-numbered proposal accepted by any acceptor in S.
In simpler terms, the proposer must ask a majority about its history before choosing the value for a new proposal.
- If the majority has no relevant history, the proposer may use its own value.
- If the majority reports an earlier accepted proposal, the proposer must adopt the value from the highest-numbered one.
This rule prevents a new proposer from overwriting a value that may already have been accepted by a majority or may be close to being chosen.
The Two Phases of Paxos
Paxos uses two phases because a proposer must both discover the past and reserve the future.
Phase One: Prepare
Step 1: choose a proposal number
The proposer selects a new proposal number N. This number must be higher than any number that proposer has previously used for the same consensus instance.
Step 2: send prepare requests
The proposer sends a prepare request containing N to acceptors.
The request effectively asks:
Will the acceptor promise not to accept proposals numbered lower than N?
Acceptor response to a prepare request
When an acceptor receives a prepare request for N, it compares N with the highest proposal number to which it has already promised.
If N is greater than that previous promise, the acceptor:
- Records N as its highest promise.
- Saves that promise in stable storage.
- Promises not to accept proposals numbered less than N.
- Reports the highest-numbered proposal it has already accepted, if any.
If the acceptor has never accepted a proposal, it reports that no previous accepted proposal exists.
If N is less than or equal to the acceptor’s existing promise, the acceptor ignores the prepare request. It must not respond positively because doing so would violate its earlier promise.
Why the promise matters
The promise prevents older proposals from later gaining a majority. If a majority of acceptors promise to reject all proposals below N, then no lower-numbered proposal can collect enough acceptances from that majority in the future.
This closes the race between learning the past and issuing a new proposal.
Phase Two: Accept
Choosing the value
The proposer waits until it receives positive promise responses from a majority of acceptors.
It then examines the previously accepted proposals reported in those responses:
- If none of the acceptors reports an earlier accepted proposal, the proposer may use its own intended value.
- If one or more acceptors reports an earlier accepted proposal, the proposer must use the value associated with the highest-numbered reported proposal.
The proposer does not freely choose a new value in the second case. It must carry forward the most recent relevant value.
Sending the accept request
The proposer sends an accept request containing the pair (N,V) to the same majority of acceptors.
Acceptor decision
When an acceptor receives the accept request for (N,V), it checks its current highest promise.
It accepts the proposal if:
N≥highest promiseEquality is allowed because the promise was to reject proposals numbered less than N, not proposal number N itself.
If another proposer has already caused the acceptor to promise a higher number, then N is lower than the current promise. The acceptor ignores or rejects the request.
If the proposal remains valid, the acceptor:
- Records (N,V) in stable storage.
- Marks it as the highest proposal it has accepted.
- Sends an accepted message to the proposer and, depending on the design, to learners.
When a majority accepts the same proposal (N,V), V is chosen for that consensus instance.
The role of the two phases
The two phases solve two different problems:
- Prepare discovers previously accepted information and obtains promises against older proposals.
- Accept attempts to make one proposal accepted by a majority.
The proposer must complete Phase One before deciding which value it is allowed to place in Phase Two.
How Learners Discover the Decision
A value being chosen is useful only if the rest of the system learns what it is.
Direct notification
The simplest method is for every acceptor to send an accepted message to every learner.
Each learner collects these messages. Once it observes that the same proposal has been accepted by a majority, it knows that the value has been chosen.
This approach is direct and can provide fast notification, but it creates many messages. If there are many acceptors and many learners, the number of acceptor-to-learner messages can become large.
Distinguished learners
To reduce communication, the system can designate one or more distinguished learners.
In this design:
- Acceptors send accepted messages to the distinguished learner.
- The distinguished learner determines when a majority has accepted a proposal.
- It informs the remaining learners that the value has been chosen.
This changes communication from roughly the product of the number of acceptors and learners to something closer to their sum.
For example, with five acceptors and 100 learners, direct communication could require hundreds of messages. A distinguished learner might receive only a few messages from the acceptors and then notify the other learners, greatly reducing traffic.
The drawback is that a distinguished learner can become a bottleneck or a single point of failure for learning. Using several distinguished learners provides better reliability while keeping communication lower than full broadcast.
Recovering a missed decision
A learner may fail to receive the messages announcing a chosen value. It can ask acceptors what they have accepted, but if too many acceptors are unavailable, it may still be unable to determine whether a majority accepted a proposal.
A learner that needs a definite answer can initiate another Paxos round for the same consensus instance. The new round uses a sufficiently high proposal number:
- If a value was already chosen, the prepare responses force the new proposer to carry that value forward.
- If no value was chosen, the new round can cause some value to be chosen.
Thus, running Paxos again can expose an already chosen value or complete an undecided instance.
Livelock and the Limits of Asynchrony
Paxos is designed to preserve safety, but basic Paxos can suffer from livelock.
Deadlock versus livelock
In a deadlock, processes stop doing anything useful because they are blocked.
In a livelock, processes remain active:
- They send messages.
- They process requests.
- They consume computing resources.
- They repeatedly interfere with one another.
However, no proposal reaches a majority, so no decision is made.
A two-proposer example
Suppose proposer P starts with proposal number 100 and value A.
- P completes Phase One and receives promises from a majority.
- Before P sends its Phase Two accept request, proposer Q starts with proposal number 101.
- Q obtains promises from the same majority.
- Those acceptors now refuse proposals numbered below $101.
- P’s Phase Two request for 100 fails.
P then retries with proposal number 102.
- P obtains new promises for $102.
- Q’s Phase Two request for 101 now fails because the acceptors promised to ignore numbers below $102.
- Q retries with 103.
- P retries with 104.
The proposers can continue preempting one another. Every proposer completes Phase One, but each is interrupted before completing Phase Two. The system remains safe, yet no value is chosen.
The FLP impossibility result
The FLP impossibility result establishes a fundamental limitation. In a completely asynchronous system where messages may take arbitrarily long and even one process may crash, no deterministic consensus algorithm can guarantee both:
- Perfect safety.
- Guaranteed termination.
This does not mean consensus is useless. It means that a system must give up at least one kind of absolute guarantee or add an assumption beyond pure asynchrony.
Practical systems introduce mechanisms such as:
- Randomness.
- Timeouts.
- Real-time assumptions.
- A distinguished leader.
These mechanisms help provide progress, although the underlying safety rules remain independent of them.
Leaders and Progress
A common solution to livelock is to elect a distinguished proposer, usually called a leader.
The leader is responsible for initiating new proposals, while other proposers remain passive unless leadership changes.
If the leader:
- Remains stable,
- Can communicate with a majority,
- Uses increasing proposal numbers,
then it can eventually complete Phase Two without being continually interrupted by another proposer.
Leader election itself may be implemented using another consensus round, an external coordination service, or timeout-based heuristics.
Leadership is for liveness, not safety
A crucial distinction is that leader election improves liveness but is not necessary for Paxos safety.
If leader election fails:
- No process may believe it is leader, causing progress to stop.
- Multiple processes may believe they are leaders, causing livelock.
Even in these situations, Paxos still prevents two different values from being chosen for the same consensus instance. The system may become stuck, but it does not become inconsistent.
Paxos can remain safe even when leadership is unreliable; leadership exists primarily to make progress more likely.
From One Decision to a Replicated Service
Paxos chooses one value for one consensus instance. Real systems usually need to agree on a long sequence of commands. This is achieved through state machine replication.
Deterministic state machines
A state machine begins in an initial state and processes commands one at a time. Each command may:
- Change the internal state.
- Produce an output.
A state machine is deterministic when the same initial state and the same command sequence always produce the same states and outputs.
For example, a calculator that receives the sequence “start with 5, then add 3” always produces 8.
Replicating the state machine
Instead of running one state machine on one server, the system runs identical copies on several servers.
If every replica:
- Starts from the same initial state.
- Receives the same commands.
- Executes them in the same order.
then every replica reaches the same state.
The main challenge is therefore not copying the program. It is agreeing on the exact ordered sequence of commands.
Paxos as a replicated log
The system runs a separate Paxos instance for each position, or slot, in the command sequence:
- Paxos instance 1 chooses the first command.
- Paxos instance 2 chooses the second command.
- Paxos instance 3 chooses the third command.
- The process continues indefinitely.
If slot 135 chooses a deposit command, every replica eventually learns that command for slot 135. After executing slots 1 through 134, each replica executes slot 135.
This creates a fault-tolerant, totally ordered log. Since all replicas execute the same commands in the same order, they maintain equivalent states.
Normal Operation with a Leader
In a normal state machine replication system:
- A client sends a command to the current leader.
- The leader identifies the next available log slot.
- The leader uses Paxos to propose the client’s command for that slot.
- Acceptors accept the proposal.
- Once a majority accepts it, the command is chosen.
- All replicas learn the command and execute it in order.
For example, if commands through slot 134 have already been chosen, the leader may place the next client command in slot 135.
A stable leader can make this efficient. After completing Phase One for a range of future slots, the leader may send Phase Two accept requests directly for new commands. In the normal case, consensus can require approximately one message round trip:
- The leader sends the accept request.
- A majority responds.
This avoids repeating the full preparation process for every command when the leader’s promises remain valid.
Recovering Missing Log Slots
A leader may crash while some commands have been chosen and others are uncertain. A new leader may discover:
- Slots 1 through 134 are known.
- Slots 138 and 139 contain commands.
- Slots 135 through 137 are missing or uncertain.
The state machine cannot simply skip the missing slots because every replica must execute a contiguous command sequence.
The new leader fills each gap by running Phase One for that slot.
Recovering an earlier accepted command
If Phase One reveals that acceptors previously accepted a command for the missing slot, the new leader must propose that command, even if it came from the old leader.
This follows P2C. The new leader cannot replace a value that may already have been on its way to being chosen.
Filling an empty slot with a no-op
If Phase One reveals that no command was previously accepted for a slot, the leader proposes a no-op command.
A no-op occupies the slot but does not change the state machine’s state. It serves as a placeholder so that later commands can be executed in order.
For example:
- Slot 135: recover the previously accepted command.
- Slot 136: choose a no-op because no previous command exists.
- Slot 137: recover or choose another appropriate value.
Once the gaps are filled, the leader can continue proposing new client commands in later slots.
Reconfiguring the Server Group
A replicated system may need to add or remove servers. Paxos can manage this change through state machine replication itself.
The current membership configuration can be represented as part of the replicated state. To change membership, the system proposes a special command such as:
- Add server Z.
- Remove server Y.
Once the configuration-change command is chosen for slot K, all replicas execute it and update their membership information. Starting with later commands, the consensus group may use the new set of acceptors to determine majorities.
This allows the system to use consensus to manage changes to the very group that performs consensus.
Comprehensive Review
Paxos addresses the problem of reaching agreement among unreliable but non-malicious distributed processes.
The central ideas are:
- Consensus selects one value for a decision instance.
- Safety ensures that only proposed values are chosen, no two different values are chosen, and processes do not learn false decisions.
- Liveness ensures that values are eventually chosen and learned, although pure asynchrony makes guaranteed progress impossible without additional assumptions.
- Acceptors preserve safety by recording promises and accepted proposals.
- Proposers initiate proposal attempts using increasing proposal numbers.
- Learners discover and use the chosen result.
- A value becomes chosen after a specific proposal is accepted by a majority.
- Majority overlap prevents two conflicting proposals from both being chosen.
- Proposal numbers allow acceptors to distinguish between competing attempts.
- The prepare phase gathers past accepted information and creates promises against lower-numbered proposals.
- The accept phase attempts to get one proposal accepted by a majority.
- The P2, P2A, P2B, and P2C rules progressively enforce the principle that once a value is chosen, all later successful proposals must preserve that value.
- Stable storage allows acceptors to remember their promises and accepted proposals after crashes.
- Learners may receive decisions directly from acceptors or through distinguished learners.
- Multiple competing proposers can cause livelock, even though safety remains intact.
- A stable leader improves liveness by reducing competition.
- Repeated Paxos instances create an ordered log of commands.
- State machine replication uses that log to keep multiple deterministic replicas in the same state.
- Missing log slots can be filled with recovered commands or no-op commands.
- Configuration changes can themselves be recorded as replicated commands.
Paxos turns unreliable components into a reliable agreement system through carefully enforced promises, majority overlap, durable memory, and ordered proposal numbers. Its deepest guarantee is that the system may stop making progress, but it will not make two conflicting decisions for the same consensus instance.

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