Paxos and Multi Paxos

Topics Covered

Single Decree Paxos

The roles

Proposal numbers

Phase one: prepare and promise

Phase two: accept and accepted

Learning the chosen value

Why it is safe

Durability requirements

A short example

Why phase one must report values, not just promises

Paxos as a register

Message count and latency

Paxos is the original practical consensus algorithm. Leslie Lamport described it in a paper written in 1989 and finally published in 1998 as The Part Time Parliament, framed as the archaeology of a fictional Greek island whose legislators wandered in and out of the chamber. The framing confused readers for years, and Lamport followed with Paxos Made Simple in 2001, which begins by saying the algorithm is among the simplest distributed algorithms. Paxos and its descendants run inside Google Chubby and Spanner, Microsoft Azure Storage, Amazon services, Apache Cassandra lightweight transactions and many other systems. This section covers the basic protocol, which decides a single value.

The roles

Paxos describes three roles. Proposers suggest values. Acceptors vote on proposals and remember what they have accepted; a majority of acceptors forms a quorum. Learners find out which value has been chosen. In real deployments each server usually plays all three roles, but separating them makes the protocol easier to reason about. A value is chosen when a majority of acceptors have accepted the same proposal. The goal is that at most one value is ever chosen, that only proposed values can be chosen and that learners eventually learn the chosen value when enough of the system is working.

Proposal numbers

Every proposal carries a proposal number, which must be unique and totally ordered. A common construction pairs a round counter with the proposer identifier, so proposer 2 in round 5 uses the number five dot two, which is greater than five dot one and less than six dot one. Each proposer chooses numbers higher than any it has used or seen. Proposal numbers play the role that terms play in Raft, but they belong to individual proposals rather than to a leader, and there is no requirement that a proposer with the highest number succeeds.

Phase one: prepare and promise

A proposer that wants to propose picks a new proposal number n and sends a Prepare message with n to a majority of acceptors, or to all of them. An acceptor receiving Prepare with number n checks whether n is greater than any prepare number it has already responded to. If so, it promises not to accept any proposal numbered less than n and replies with a Promise containing the highest numbered proposal it has already accepted, if any, including that proposal number and value. If n is not greater, the acceptor ignores the request or replies with a rejection that includes the higher number it has seen.

In phase one, the proposer asks acceptors to promise to ignore older proposals and to report anything they already accepted.

Phase two: accept and accepted

When the proposer has received promises from a majority, it chooses a value. If any promise reported a previously accepted proposal, the proposer must use the value of the highest numbered such proposal. Only if no promise reported anything may it use its own value. It then sends Accept with number n and the chosen value to the acceptors. An acceptor accepts the proposal unless it has since promised a higher number, records the accepted number and value durably and replies Accepted. Once a majority of acceptors have accepted proposal n, its value is chosen.

Learning the chosen value

Acceptors can notify learners whenever they accept a proposal, and a learner knows a value is chosen once it hears that a majority accepted the same proposal number. Alternatively, the proposer learns from the Accepted replies and broadcasts the decision. Because messages can be lost, a learner may fail to learn the chosen value even though it is chosen. It can always find out by having some proposer run a new round: phase one will discover the chosen value from at least one acceptor in any majority, and phase two will propose it again.

Why it is safe

Safety rests on the argument from the consensus lesson. Suppose value v is chosen with proposal number m, so a majority accepted it. Any proposer with a higher number n runs phase one and receives promises from a majority, which overlaps the majority that accepted v. At least one acceptor in the overlap reports having accepted v under m or under some number between m and n, which by induction also carried v. The proposer must pick the value of the highest numbered reported proposal, which is v. So every proposal numbered above m has value v, and no other value can ever be chosen.

Durability requirements

Acceptors must persist the highest promised number and the highest accepted proposal before replying. If an acceptor forgot a promise after a crash, it could accept a lower numbered proposal and break the overlap argument. If it forgot an accepted value, a later proposer might not discover a chosen value. Proposers must persist the highest proposal number they have used, or derive unique numbers from durable state, so that after a restart they never reuse a number with a different value. These persistence rules are the same as those for Raft voters and are equally essential.

A short example

Three acceptors start empty. Proposer P1 sends Prepare 1 and receives three promises reporting nothing. It sends Accept 1 with value A, but only acceptor A1 receives it before P1 crashes. Proposer P2 sends Prepare 2 to A2 and A3, which report nothing, since they never accepted proposal 1. P2 may use its own value B, sends Accept 2 with B to A2 and A3, and both accept. B is chosen. If P1 restarts and sends Prepare 3 to A1 and A2, A2 reports accepted proposal 2 with B and A1 reports proposal 1 with A. P1 must take the higher, B, and proposes B again. The chosen value is preserved.

Once a majority accepts a value, any later majority includes someone who saw it. That acceptor forces the next proposer to keep the value.

Why phase one must report values, not just promises

It is tempting to simplify Paxos by having acceptors only promise and not report anything. That breaks safety at once. A proposer that does not learn what was accepted might propose its own value after another value was already chosen, and if a majority accepted it, two values would be chosen. Reporting accepted proposals is what lets a new proposer discover the past. The rule of adopting the highest numbered report is also essential: a lower numbered report may come from a proposal that was overtaken before it reached a majority, while the highest numbered one is the only candidate that could have been chosen.

Paxos as a register

A useful mental model treats single decree Paxos as a write once register spread across acceptors. Phase one is a read that also fences off older writers, and phase two is a write that succeeds only if no newer reader has appeared. Seen this way, Paxos resembles the quorum read and write protocols from earlier in the course, with the added rule that the writer must write back whatever it read rather than its own value. This read then write structure appears again in ABD style atomic registers and in many leaderless protocols.

Message count and latency

A full round of single decree Paxos with n acceptors sends n Prepare messages, receives up to n Promises, sends n Accepts and receives up to n Accepted replies, so four message delays and about 4n messages. The proposer needs replies only from a majority in each phase, so slow acceptors do not delay the decision. Durability adds two disk syncs on each acceptor, one for the promise and one for the accepted proposal, which is why acceptors are usually placed on fast storage.

Two phases protect the past

In phase one a proposer collects promises from a majority and learns any accepted values. In phase two it must propose the highest numbered reported value, or its own if none. Quorum overlap guarantees that once a value is chosen, every later proposal carries it.