Maps to: CMU 15-440/640 Spring 2026, learning outcome “consensus: majority (leader election, Paxos)”; the reading Lamport, Paxos Made Simple. Problem set: PS4 asks you to complete and to judge Paxos message sequences written in the course’s notation —
Prepare(n),Promise(n, AlreadyAccepted(nk, ak)),PleaseAccept(n, v),Accept_OK(),NAK(Np). This lecture and its code use the same notation, so that the traces read like the course’s. It gives no answers, and the code deliberately contains no checker for hand-written traces. Sources:
- L. Lamport, Paxos Made Simple (ACM SIGACT News 2001) — the reading;
- L. Lamport, The Part-Time Parliament (ACM TOCS 1998) — the original;
- M. J. Fischer, N. A. Lynch and M. S. Paterson, Impossibility of Distributed Consensus with One Faulty Process (JACM 1985);
- C. Dwork, N. Lynch and L. Stockmeyer, Consensus in the Presence of Partial Synchrony (JACM 1988);
- H. Garcia-Molina, Elections in a Distributed Computing System (IEEE TC 1982) — the bully algorithm;
- E. Chang and R. Roberts, An Improved Algorithm for Decentralized Extrema-Finding in Circular Configurations of Processes (CACM 1979);
- D. Ongaro and J. Ousterhout, In Search of an Understandable Consensus Algorithm (USENIX ATC 2014) — Raft;
- C. Newcombe et al., How Amazon Web Services Uses Formal Methods (CACM 2015).
The slides are not public; this is not a transcript. Every number not attributed to a paper comes from
code/lecture20/, run on the author’s machine (Apple M4 Pro, macOS, Python 3.13 and 3.9). Everything is exhaustive or seeded and deterministic, except one labelled real measurement. Code:code/lecture20/. Reading time: ~100 minutes, plus ~2 to run the demos.
0. How to read this lecture
0.1 Learning goals
After this lecture you should be able to:
- State the consensus problem (agreement, validity, termination), its failure model, and how it differs from atomic commit.
- Explain why majorities are the building block, and how many failures 2f + 1 acceptors tolerate.
- Compare leader election algorithms (bully, ring, majority voting), and say which can produce two leaders.
- Derive Paxos from its requirements the way Lamport does, and run it by hand in the course’s message notation.
- Say exactly what an acceptor must keep in stable storage, and why each part is needed.
- Explain why Paxos is always safe but not always live (FLP, dueling proposers), and how a leader restores progress.
- Read a model-checking result: what was enumerated, and what a counterexample proves.
0.2 Prerequisites and scope
- Prerequisites:
- Lecture 19: majorities intersect; leases; split brain;
- Lecture 18: unanimity, blocking, and Skeen and Stonebraker’s impossibility results;
- Lecture 14: failure models and failure detectors;
- Lecture 15: stable storage and forced writes.
- Scope: single-decree Paxos (agree on one value) with crash-recover processes and an asynchronous, lossy network. A replicated log built from many Paxos instances (Multi-Paxos), a stable leader, membership changes and engineering lessons are Lecture 21. Byzantine consensus was Lecture 14.
0.3 Section → code map
| Section | Idea | Demo in code/lecture20/ |
|---|---|---|
| §1–2 | the problem; why majorities | 01_consensus_problem.py |
| §3 | leader election | 02_leader_election.py, election.py |
| §4–5 | Paxos, derived and run | 03_paxos_trace.py, paxos.py |
| §6 | what acceptors store | 05_stable_storage.py |
| §7 | checking every interleaving | 04_paxos_explorer.py, modelcheck.py |
| §8 | liveness: dueling proposers | 06_dueling_proposers.py |
0.4 Notation
- Roles: proposers propose values, acceptors vote, learners find out what was chosen. In the course’s servers S1…Sn, as in Lamport’s implementation, every server plays all three roles. The model checker separates them: proposers P1, P2 and acceptors A1–A3.
- Proposal numbers must be unique and totally ordered. Attempt k of server i uses n = 10k + i (S1: 11, 21, …; S3: 13, 23, …).
- Acceptor state: Np, the highest number it has promised; (na, va), the highest-numbered proposal it has accepted, or “null”.
- Messages (course notation):
Prepare(n)andPleaseAccept(n, v)go from proposer to acceptors;Promise(n, AlreadyAccepted(nk, ak))(writtenPromise(n, null)if nothing was accepted),Accept_OK()andNAK(Np)go from acceptor to proposer.
- Trace lines “S1 -> S2: Prepare(11)” mean S1’s Prepare(11) was delivered to S2.
1. The consensus problem
1.1 What is asked
A set of processes each may propose a value; they must end up agreeing on one. Lamport’s three safety requirements:
- Only a value that has been proposed may be chosen.
- Only a single value is chosen.
- A process never learns that a value has been chosen unless it actually has been.
The liveness goal is that some proposed value is eventually chosen, and that processes eventually learn it. Lamport deliberately does not make this a precise requirement, for a reason §8 makes clear.
The failure model is the “customary asynchronous, non-Byzantine” one:
- Processes run at arbitrary speeds, may stop, and may restart.
- Messages may be delayed arbitrarily, duplicated or lost, but are never corrupted.
A process that restarts after a value is chosen must still behave consistently. So some state must survive the crash: §6.
1.2 Why it matters
Almost every fault-tolerant system needs one decision that everybody agrees on, even under crashes:
- Who is the leader (or the primary, Lecture 19 §2).
- What the next command in a replicated log is (Lecture 21), that is, a replicated state machine.
- Whether a distributed transaction commits (Gray and Lamport’s Paxos Commit, Lecture 18 §7.4).
- What the current configuration is, such as which machines are members and who holds a lock (Chubby, ZooKeeper, etcd).
1.3 Consensus versus atomic commit
Two-phase commit (Lecture 18) also makes processes agree, but on a decision that depends on everyone’s vote: one “no” forces abort, so it must hear from all participants and blocks when one is silent. Consensus only needs the processes to agree on some proposed value. That is why a majority suffices, and why it can keep going with a minority down.
2. Why majorities
2.1 One acceptor is not enough; first-come is not enough
The simplest way to choose a value is a single acceptor that takes the first proposal it receives. But when that acceptor fails, nothing can progress.
With several acceptors that each accept the first proposal they see and never change (Lamport’s P1, alone), two problems appear (demo 01 Part A, every arrival order):
- Split votes. With 3 acceptors and 3 simultaneous proposers, no value had a majority in 22.2% of orders, so no value could ever be chosen. With 5 acceptors and 3 proposers: 37.0%.
- Fragile wins. With 2 proposers some value always wins, but in 75% of orders by a bare majority (2 of 3). If one of those two acceptors fails, no learner can tell which value won.
So acceptors must be allowed to accept more than one proposal, and that is what proposal numbers are for.
2.2 Majorities always meet
Any two majorities of the same set share at least one member (demo 01 Part B):
| acceptors | quorum size | pairs of quorums sharing nobody |
|---|---|---|
| 3 | 1 (half or less) | 3 of 6 |
| 3 | 2 (majority) | 0 of 6 |
| 5 | 2 | 15 of 55 |
| 5 | 3 | 0 of 55 |
| 7 | 3 | 70 of 630 |
| 7 | 4 | 0 of 630 |
That shared acceptor is the thread Paxos pulls on. Whatever a majority did in an earlier proposal, every later majority includes someone who saw it.
With 2f + 1 acceptors, a majority survives f crashes: 3 tolerate 1, 5 tolerate 2. An even number buys nothing; 4 acceptors still tolerate only 1. (Lamport notes the generalization: any quorum system in which every two quorums intersect will do, as in Lecture 19.)
3. Leader election
Paxos needs a single “distinguished proposer” to make progress (§8), and primary-backup needs a single primary to be safe. Three classic ways to elect one, after the old leader crashes (demo 02):
- Bully (Garcia-Molina 1982). A process that suspects the leader sends ELECTION to every process with a higher id. Anyone higher answers OK and takes over the election. A process that hears no OK declares itself leader and tells everyone. The highest live id wins.
- Ring (Chang and Roberts 1979). ELECTION(id) travels clockwise, each process forwarding the larger of the id it received and its own. The process whose own id returns is the leader, and an ELECTED message goes round once more.
- Majority voting. This is the core of Raft’s election, and Paxos’s phase 1 in another form. A candidate starts a new term, votes for itself, and asks for votes. Each process votes for at most one candidate per term, recorded on stable storage. A majority of votes makes a leader. Randomized timeouts make split votes rare.
| processes | bully | ring | majority |
|---|---|---|---|
| 5 | 20 msgs, 47 ms | 11 msgs, 58 ms | 40 msgs, 46 ms |
| 20 | 1,153 msgs, 49 ms | 54 msgs, 100 ms | 606 msgs, 55 ms |
| 40 | 3,043 msgs, 45 ms | 114 msgs, 178 ms | 2,786 msgs, 80 ms |
The ring is frugal with messages but slow, since it goes round twice. The bully is fast but quadratic in the worst case. Majority voting costs about two messages per process per round, plus retries after split votes.
Partitions separate them sharply. With p7 crashed and the network split {p1, p2} | {p3–p6}:
- bully elected p2 and p6;
- ring could not close, and elected nobody;
- majority voting elected p4 on the 4-of-7 side, and nobody on the other.
Over 50 random splits of 9 processes, bully had two leaders in 49 runs and majority voting in 0. It had no leader in 12, when neither side held a majority.
Only majority-based election cannot produce two leaders in the same term. Even so, an old leader may not yet know it has been replaced. That is why leaders need leases (Lecture 19 §2.3), and why Paxos is designed so that two leaders at once can slow it down but never make it wrong.
4. Paxos, derived
Lamport’s claim is that the algorithm “follows almost unavoidably from the properties we want it to satisfy”. The steps:
- Many acceptors, chosen by majority. A value is chosen when a majority of acceptors have accepted it. Two majorities intersect, so if each acceptor accepted at most one value, at most one value could be chosen.
- P1: an acceptor must accept the first proposal it receives. Otherwise a lone proposer might never succeed. As §2.1 showed, P1 with “accept at most one” can deadlock, so acceptors must accept several proposals. Proposals get unique numbers, and a value is chosen when a single numbered proposal is accepted by a majority.
- P2: if a proposal with value v is chosen, every higher-numbered proposal that is chosen has value v. Several proposals may be chosen, but they all carry the same value. Lamport strengthens it twice:
- P2a: every higher-numbered proposal accepted by any acceptor has value v;
- P2b: every higher-numbered proposal issued by any proposer has value v. (P2a alone clashes with P1: an acceptor that never heard of v must accept the first proposal it gets.)
- P2c, the invariant that makes P2b true. For a proposal (n, v) to be issued, there must be a majority S of acceptors such that either
- (a) no acceptor in S has accepted any proposal numbered below n, or
- (b) v is the value of the highest-numbered proposal below n accepted by the acceptors in S.
- Phase 1 is how a proposer learns enough to obey P2c. It cannot predict future acceptances, so it forbids them:
- it sends Prepare(n) to the acceptors;
- each acceptor answers with a promise never again to accept a proposal numbered below n, together with the highest-numbered proposal it has already accepted,
Promise(n, AlreadyAccepted(nk, ak)).
- Phase 2. With promises from a majority, the proposer sends PleaseAccept(n, v). Here v is the ak of the highest nk among the promises, or any value it likes if no promise reports one. An acceptor accepts unless it has promised a number greater than n (P1a), and answers Accept_OK(); otherwise it may refuse with NAK(Np).
The acceptor’s rules, in full:
| on | condition | action (state written to stable storage first) | reply |
|---|---|---|---|
| Prepare(n) | n > Np | Np := n | Promise(n, AlreadyAccepted(na, va)) |
| Prepare(n) | n ≤ Np | — | NAK(Np), or silence |
| PleaseAccept(n, v) | n ≥ Np | Np := n; (na, va) := (n, v) | Accept_OK() |
| PleaseAccept(n, v) | n < Np | — | NAK(Np), or silence |
NAKs are an optimization: Lamport points out that ignoring a request is always safe. A NAK just tells the proposer to stop wasting time.
Why it works, in one paragraph. Suppose (m, v) was chosen: a majority C accepted it. Take any later proposal n > m. Its phase 1 got promises from a majority S, and S meets C in some acceptor a. Acceptor a accepted (m, v) before promising n, since after the promise it would have refused m. So a’s promise reports some accepted proposal numbered at least m. By induction, every proposal numbered between m and n carries v, so the highest-numbered one reported carries v, and the proposer must propose v.
5. Paxos in action (demo 03)
5.1 No failures
S1 -> S1: Prepare(11) S1 -> S1: Promise(11, null)
S1 -> S3: Prepare(11) S3 -> S1: Promise(11, null) <- a majority: S1, S3
S1 -> S2: Prepare(11) S2 -> S1: Promise(11, null) (arrives later; not needed)
S1 -> S1: PleaseAccept(11, v1) S1 -> S1: Accept_OK()
S1 -> S3: PleaseAccept(11, v1) S3 -> S1: Accept_OK() <- v1 chosen
One value, two round trips (the last Accept_OK arrived at 8.2 ms with 1–3 ms links), 12 messages including the Chosen notices to learners, and 5 stable writes in all: one per promise, one per acceptance.
5.2 A second proposer must carry the first one’s value forward
S1 proposes v1 at 0 ms; S3 proposes v3 at 4 ms. The essential lines:
S1 -> S1: PleaseAccept(11, v1) S1 accepts (11, v1)
S3 -> S1: Prepare(13) ... S1 -> S3: Promise(13, AlreadyAccepted(11, v1))
S3 -> S1: PleaseAccept(13, v1) S3 proposes v1, not v3
S3 -> S1: NAK(13) S3 (as acceptor) refuses S1's old PleaseAccept(11)
S3 cannot tell whether v1 was already chosen: a majority might have accepted (11, v1) without S3 knowing. So, by P2c, it must propose v1. It did, and v1 was chosen and learned everywhere. That is the whole idea of phase 1: find out what may already be chosen, and stop older proposals from adding to it.
5.3 A restarted acceptor carries the value
Demo 03 Part C scripts the failures so that everything rests on one acceptor’s memory:
- S3 is down at the start, so S1’s majority is {S1, S2}, and v1 is chosen by them.
- S2 crashes at 9 ms and restarts at 30 ms.
- S1 dies for good at 20 ms.
- S3 restarts at 35 ms knowing nothing, and proposes v3. Its majority can only be {S2, S3}.
S2 woke up with Np = 11 and accepted (11, v1) on stable storage. Its promise to S3 was Promise(13, AlreadyAccepted(11, v1)), so S3 proposed v1, and the outcome stayed v1. §6 shows the same run without stable storage.
5.4 NAKs
In Part D, S2’s Prepare(12) overtook S1’s PleaseAccept(11, v1) at two acceptors. They answered S1 with NAK(12), S1 abandoned proposal 11, and S2’s v2 was chosen. Abandoning a proposal mid-way is always allowed. Late replies to it are simply ignored: every reply carries the proposal number it answers.
6. What an acceptor must remember (demo 05)
Lamport: an acceptor need remember only the highest-numbered proposal it has accepted and the highest-numbered prepare it has answered, and it must remember them even if it fails and then restarts. It records its intended response in stable storage before sending it.
The same run as §5.3, with acceptors that keep Np, na and va in memory only:
| S2 keeps its state | S2 right after restart | its promise to S3 | values chosen |
|---|---|---|---|
| on stable storage | Np = 11, (11, v1) | Promise(13, AlreadyAccepted(11, v1)) | v1 |
| in memory only | Np = 0, (0, null) | Promise(13, null) | v1 and v3 |
S2 promised as if it had never accepted anything. S3, seeing no earlier value, proposed v3, and v3 was accepted by {S2, S3}, a majority, while v1 had already been chosen.
Both halves are needed. The model checker (§7) found two values chosen in 15 steps when a crash loses only the promise, and in 15 steps when it loses only the accepted proposal:
- Lose the promise: an acceptor that helped choose y under proposal 12 forgets its promise, then accepts an older proposal 11 carrying x. With one other acceptor, that makes x chosen too.
- Lose the accepted value: a promise then reports “null” for a value that was chosen, as above.
Proposers need much less. Each must never reuse a proposal number, so it records the highest number it has used, or derives numbers from a stable counter. It may forget a proposal at any time.
The cost is real. On this machine (demo 05 Part C, real) a 64-byte state write took about 1 µs into the page cache, 20 µs with fsync() (which on macOS does not reach the medium, Lecture 15 §2.4), and about 2.9 ms with F_FULLFSYNC. Two forced writes sit on the critical path of every decision, the promise and the acceptance, so about 6 ms per decision: more than the network round trips in a data centre. Real systems batch many decisions per write (Lecture 21).
7. Checking every interleaving (demo 04)
7.1 Why enumerate
Simulation tries some schedules; an adversarial network can produce any of them. modelcheck.py does what TLA+‘s TLC model checker does:
- Explore every reachable state. Every delivery order of every message in flight, every message never delivered (loss), every moment a proposer may give up and retry, and up to one acceptor crash.
- Check the invariant in each state: at most one value chosen, where chosen means accepted by a majority under one proposal number.
It stores a 64-bit fingerprint per state rather than the state, as TLC does, so 2.7 million states fit in about 400 MB.
7.2 Correct Paxos
Two proposers (values x and y) and three acceptors:
| attempts (P1 / P2) | reachable states | longest path | two values chosen |
|---|---|---|---|
| 1 / 1 | 15,700 | 18 steps | never |
| 2 / 1 | 2,696,996 | 27 steps | never |
7.3 Every rule is load-bearing
Breaking one rule at a time, breadth-first, so each counterexample is a shortest one:
| bug | shortest schedule that chooses two values |
|---|---|
| a crash wipes the acceptor’s state | 15 steps |
| the proposer ignores AlreadyAccepted and proposes its own value | 14 steps |
| the proposer takes the first promise’s value instead of the highest-numbered | 14 steps |
| the proposer proceeds with promises from 1 of 3 acceptors | 10 steps |
| an acceptor accepts PleaseAccept(n) after promising more than n | 14 steps |
The own-value counterexample, as printed:
... P1 -> A2: PleaseAccept(11, x) -> Accept_OK()
P1 -> A3: PleaseAccept(11, x) -> Accept_OK() x is chosen (A2, A3)
P2 -> A2: Prepare(12)
A2 -> P2: Promise(12, AlreadyAccepted(11, x)) P2 is TOLD about x ...
P2 -> A1: PleaseAccept(12, y) -> Accept_OK()
P2 -> A2: PleaseAccept(12, y) -> Accept_OK() ... and y is chosen too (A1, A2)
7.4 One rule that is not what it seems
Lamport requires unique proposal numbers. What if two proposers both use 10, 20, …? The checker found no violation with two attempts each. While acceptors promise only strictly greater numbers, an acceptor promises a given number at most once, so two proposers with the same number cannot both gather a majority of promises.
A second change that is individually harmless, “also promise when n = Np”, made duplicates fatal in 13 steps. With unique numbers it is harmless, since only the same proposer can send the same number again. The two conventions protect each other. This is the kind of subtle interaction that model checking finds and that reasoning by example tends to miss. It is also why industry uses TLA+ on protocols like this (Newcombe et al. report bugs found that way in AWS systems).
7.5 A bug in the model
The first version of the checker reported that correct Paxos chose two values. The modelled proposer had reacted to a promise that arrived after it had already sent PleaseAccept(12, y): it recomputed its value and sent PleaseAccept(12, x), two values under one number. Real proposers must ignore promises once they have picked a value. A model is a program too, and it must be debugged against the protocol it claims to represent.
8. Liveness: dueling proposers (demo 06)
8.1 The scenario
Lamport describes it:
- p completes phase 1 with number n1;
- q completes phase 1 with n2 > n1, so p’s phase 2 is refused;
- p completes phase 1 with n3 > n2, so q’s phase 2 is refused;
- and so on.
Safety holds throughout; nothing is ever chosen.
With five servers and proposers that retry immediately when refused, 300 seeded runs per row:
| proposers | retry policy | rounds: median / 99th pct / max | chosen after: median / 99th pct |
|---|---|---|---|
| 2 | at once | 5 / 15 / 18 | 13.0 / 53.2 ms |
| 3 | at once | 21 / 97 / 188 | 36.3 / 210 ms |
| 5 | at once | 176 / 980 / 1,159 | 170 / 1,003 ms |
| 5 | random backoff 5–40 ms | 5 / 7 / 8 | 6.5 / 7.8 ms |
| 1 (a leader) | — | 1 / 1 / 1 | 6.5 / 7.8 ms |
In all 2,100 runs exactly one value was chosen, and never two. The duels cost time, not correctness.
8.2 Why liveness cannot be guaranteed: FLP
Fischer, Lynch and Paterson proved that no deterministic protocol can guarantee that consensus terminates in an asynchronous system in which even one process may crash. The intuition: a process cannot tell a crashed peer from a slow one. An adversarial scheduler can always delay exactly the message that would let the system decide, keeping it “bivalent” forever.
Paxos’s answer is to separate the two properties:
- Safety never depends on timing. No schedule, however adversarial, makes Paxos choose two values (§7).
- Liveness depends on timing. Lamport: elect a single distinguished proposer; if it can reach a majority and uses a high enough number, it succeeds. A reliable election “must use either randomness or real time — for example, by using timeouts”. Random backoff and leader election with timeouts are exactly that.
Dwork, Lynch and Stockmeyer made the “eventually timely” condition precise as partial synchrony: the system may behave asynchronously for a while, but eventually messages arrive within a bound. Paxos is live once that happens.
8.3 Learning the value
Learners must find out that a majority accepted one proposal. Lamport discusses three options:
- Every acceptor informs every learner: fastest, but the number of messages is the product of acceptors and learners.
- Acceptors inform a distinguished learner, which informs the rest: the sum instead of the product, at the cost of one more message delay and one more point of failure.
- Several distinguished learners: in between.
If messages are lost, a learner may not know whether anything was chosen. The robust answer is to run a proposal: phase 1 reveals any value that may be chosen. Our servers act as the distinguished learner when they propose, and broadcast Chosen(v).
9. Design rules
- Decide by majority quorums, which intersect, and size the group as 2f + 1.
- Number proposals uniquely and monotonically (disjoint sets per proposer, persisted), and promise only strictly greater numbers.
- Phase 1 before phase 2. Never propose a value without first collecting promises from a majority, and carry forward the highest-numbered accepted value they report.
- Write the acceptor’s state (Np, na, va) to stable storage before replying.
- Ignore late replies, tagged with an old number, and late promises once the value is picked.
- Elect a leader for liveness, not for safety. Expect two leaders sometimes, and rely on proposal numbers to sort it out.
- Back off randomly when pre-empted.
- Model-check the protocol, and the model.
Summary
- Consensus: agree on one proposed value, never two, despite crashes, restarts, delays and loss. Only a majority is needed, unlike atomic commit’s unanimity.
- Majorities always intersect, which is the thread that carries a chosen value forward. First-come acceptance split the vote in 22.2% of arrival orders.
- Leader election: bully, ring and majority voting each elect within tens of milliseconds, but under partitions only majority voting never elected two leaders (0 of 50 random splits, against 49 for bully).
- Paxos follows from P1, P2 and its strengthenings to P2c:
- phase 1 (Prepare / Promise with AlreadyAccepted) blocks older proposals and discovers what may be chosen;
- phase 2 (PleaseAccept / Accept_OK) gets a majority to accept. Without failures that is two round trips, 12 messages and 5 stable writes for 3 servers.
- Stable storage: memory-only acceptors let Paxos choose v1 and v3. Losing either the promise or the accepted value breaks safety. A durable write cost ~3 ms here.
- Model checking: correct Paxos was safe in all 2.7 million reachable states. Every broken rule gave a counterexample of 10–15 steps. Duplicate proposal numbers are harmless with strict promises, and fatal with ”≥” promises.
- Liveness: immediate retries made 5 proposers duel for a median 176 rounds (~1 s at the 99th percentile). Random backoff took 5 rounds; a single leader 1. FLP says timing assumptions are unavoidable; Paxos confines them to liveness.
Common pitfalls
- Proposing your own value although a promise reported an accepted one.
- Taking the value of any reported proposal rather than the highest-numbered.
- Proceeding with promises from fewer than a majority.
- Keeping acceptor state in memory, or writing it after replying.
- Accepting a proposal numbered below your promise.
- Reusing proposal numbers across proposers or restarts (and relying on a ”≥” promise rule).
- Reacting to late promises or replies for a proposal you have moved past.
- Thinking a leader is needed for safety: it is needed for progress only.
- Retrying immediately when pre-empted.
- Believing a test run proves safety.
Exercises
-
Majority arithmetic. (a) How many acceptors are needed to tolerate 3 crashed acceptors? (b) A system has 6 acceptors and requires quorums of 4. How many crashes does it tolerate, and is it any better than 5 acceptors with quorums of 3? (c) Could a system use quorums of 3 out of 6? Why not?
Answer
(a) 2f + 1 = 7. (b) Quorums of 4 survive 2 crashes (6 − 4), the same as 5 acceptors with quorums of 3, so the sixth acceptor adds cost and message load without adding fault tolerance. (c) No: two quorums of 3 out of 6 can be disjoint ({1,2,3} and {4,5,6}). Two different values could each be accepted by a quorum, so safety fails. -
What may be proposed? A proposer collected promises for proposal 47 from three of five acceptors. They reported AlreadyAccepted(31, red), null, and AlreadyAccepted(39, blue). (a) Which value must it propose? (b) Suppose instead all three reported null. Can it propose any value? Could a value already have been chosen? (c) Why is “the most common reported value” the wrong rule?
Answer
(a) Blue: the value of the highest-numbered accepted proposal among the promises (39 > 31). (b) Yes, any value. No value can have been chosen with a number below 47: any majority that accepted it would intersect this majority, and the intersecting acceptor would have reported it. That acceptor accepted before promising, since after promising 47 it would refuse lower numbers. (c) Popularity says nothing about which value may be chosen. Red at 31 may have been superseded: if blue at 39 was proposed, its proposer's phase 1 found blue to be the safe value at 39. The highest-numbered value is the one consistent with P2c, by the induction in §4. -
Two proposers, by hand. Three acceptors. P1 sends Prepare(11) and gets promises from A1 and A2. Before P1’s PleaseAccept arrives anywhere, P2 sends Prepare(12) and gets promises from A2 and A3. (a) What happens to P1’s PleaseAccept(11, x) at A1, A2 and A3? (b) What value does P2 propose, and why? (c) Can x still be chosen?
Answer
(a) A1 promised only 11, so it accepts (11, x). A2 promised 12, so it refuses (NAK(12)). A3 promised 12, so it refuses too, if P1 sent to it at all. (b) P2's promises (A2, A3) reported null, because neither had accepted anything when it promised, so P2 proposes its own value y. (c) Not with proposal 11: only A1 can accept 11, since A2 and A3 promised 12, so 11 cannot reach a majority. x can be chosen later only if some higher proposal discovers it, for instance a proposal whose phase 1 includes A1 before y is accepted by a majority. Once y is chosen, every later proposal carries y. -
The forgotten promise. An acceptor writes its accepted proposal to disk but keeps Np only in memory. Describe a run in which two values are chosen. Which of Lamport’s properties fails, and at which step?
Answer
Three acceptors. P1 gets promises for 11 from A1 and A2. P2 gets promises for 12 from A1 and A2, then gets (12, y) accepted by A1 and A2: y is chosen. A1 crashes and restarts with Np = 0 but (12, y) on disk. P1's delayed PleaseAccept(11, x) reaches A1, which now accepts it (11 ≥ 0) and overwrites its accepted proposal. It also reaches A3, which never promised anything and accepts. Now A1 and A3 accepted proposal 11 with x: x is chosen too. The broken rule is P1a, accepting a proposal numbered below a promise already given (12). The step is A1 accepting 11 after its restart. demo 05 Part B finds this kind of run in 15 steps. -
Message count. With n acceptors, one proposer, no failures, and the proposer also acting as distinguished learner that informs the other n − 1 servers: count the messages per decision if PleaseAccept goes (a) to all n acceptors, (b) only to the first majority that promised. How many forced writes are there in each case?
Answer
(a) n Prepare + n Promise + n PleaseAccept + n Accept_OK + (n − 1) Chosen = 5n − 1 messages; forced writes: n promises + n acceptances = 2n. (b) n Prepare + n Promise + m PleaseAccept + m Accept_OK + (n − 1) Chosen, with m = ⌊n/2⌋ + 1: 3n − 1 + 2m. Forced writes: n + m. For n = 3 that is 12 messages and 5 forced writes, the counts of demo 03 Part A. Sending phase 2 to everyone costs more but tolerates a slow or crashed promiser without a retry. -
Election under partition. Nine processes are split 5 | 4 while the old leader is alive on the 5 side. (a) With bully election, what can happen if the 4 side times out? (b) With majority voting with terms? (c) In (b), can the old leader and a new one both think they lead? What makes this harmless for Paxos, and what makes it harmless for a primary-backup store?
Answer
(a) The 4 side elects its highest id; now two leaders accept requests: split brain. (b) The 4 side cannot collect 5 votes, so it elects nobody; the old leader keeps leading on the 5 side. (c) Yes, briefly. For instance, if the leader was on the 4 side, a new leader is elected on the 5 side in a new term before the old one notices. In Paxos this is harmless for safety: the new leader's higher proposal numbers make acceptors refuse the old leader's proposals, and phase 1 carries forward anything it got accepted. In primary-backup it is harmless only with leases: the old primary stops serving when its lease expires, and the new one waits until then (Lecture 19 §2.3). -
FLP and Paxos. A colleague says: “FLP proves consensus is impossible, so Paxos must be wrong.” Explain precisely what FLP rules out, what Paxos guarantees, and the assumption under which Paxos terminates.
Answer
FLP rules out a deterministic protocol that *always* terminates in a purely asynchronous system with one crash: some schedule keeps it undecided forever. Paxos does not claim that. It guarantees safety (never two values; only proposed values; learners learn only chosen values) under every schedule, and terminates once the system behaves synchronously enough for long enough (partial synchrony). Concretely, a single proposer must be able to reach a majority within its timeouts without being pre-empted. Lamport's paper says the leader election that achieves this must use randomness or real time. Demo 06's duels are FLP's adversary in miniature, and random backoff and leaders are the way out. -
Read a counterexample. The model checker reports the 13-step run of §7.4 for “duplicate numbers and promise n == Np”. (a) At which step is the first acceptor in two quorums for “the same” proposal? (b) Why does this not happen if numbers are unique? (c) Why not if promises need n > Np?
Answer
(a) When A1 promises Prepare(10) to P2 after having promised 10 to P1 (and, later, A2 does the same). The intersecting acceptors serve two different proposals that share a number. P1 gets x accepted by A1 and A2 under 10, and P2's later PleaseAccept(10, y) is also accepted (10 ≥ 10): two values under one number. (b) With unique numbers, a second Prepare(10) can only come from P1 itself, which proposes one value per number. (c) With strict promises, A1's second Prepare(10) is refused, so P2 cannot assemble a majority for 10, since every majority meets P1's.
Related project and problem set (concepts only)
- Problem Set 4 asks you to fill in missing messages of Paxos runs and to decide whether given runs could come from a correct implementation, in the notation used here. §4 (the acceptor’s table and the proposer’s value rule), §5 (worked traces) and §6 (what promises report) give the concepts. The runs here are generated by the protocol, the PS’s runs are not reproduced, and the code has no checker for hand-written traces, by design.
- Project 4 uses two-phase commit, not Paxos. Lecture 18 §7.4 explains how Paxos removes 2PC’s blocking coordinator.
Further reading
- L. Lamport, “Paxos Made Simple”, ACM SIGACT News 32(4), 2001 — the reading.
- L. Lamport, “The Part-Time Parliament”, ACM TOCS 16(2), 1998.
- M. J. Fischer, N. A. Lynch and M. S. Paterson, “Impossibility of Distributed Consensus with One Faulty Process”, JACM 32(2), 1985.
- C. Dwork, N. Lynch and L. Stockmeyer, “Consensus in the Presence of Partial Synchrony”, JACM 35(2), 1988.
- H. Garcia-Molina, “Elections in a Distributed Computing System”, IEEE Transactions on Computers C-31(1), 1982.
- E. Chang and R. Roberts, “An Improved Algorithm for Decentralized Extrema-Finding in Circular Configurations of Processes”, CACM 22(5), 1979.
- D. Ongaro and J. Ousterhout, “In Search of an Understandable Consensus Algorithm”, USENIX ATC 2014 — Raft.
- R. van Renesse and D. Altinbuken, “Paxos Made Moderately Complex”, ACM Computing Surveys 47(3), 2015.
- C. Newcombe et al., “How Amazon Web Services Uses Formal Methods”, CACM 58(4), 2015.
- L. Lamport, Specifying Systems (TLA+ and TLC), Addison-Wesley, 2002 (free online).
Preview of Lecture 21 — Consensus II: Paxos in practice and replicated state machines
One Paxos instance chooses one value. A service needs a sequence of them: the 1st command, the 2nd, the 135th. Lecture 21 builds a replicated state machine from one Paxos instance per log slot (Lamport’s §3). It covers:
- a stable leader that skips phase 1 for every slot (Multi-Paxos);
- gaps in the log and how replicas catch up;
- membership changes;
- what Google learned running Paxos in Chubby (Paxos Made Live): disk corruption, master leases, snapshots, and why testing distributed protocols is hard;
- Raft as a comparison point.
术语表 (Glossary, English → 中文)
| English | 中文 |
|---|---|
| consensus | 共识 |
| agreement / validity / termination | 一致性 / 有效性 / 终止性 |
| safety / liveness | 安全性 / 活性 |
| proposer / acceptor / learner | 提议者 / 接受者 / 学习者 |
| proposal / proposal number (ballot) | 提案 / 提案编号(选票号) |
| prepare request / promise | 准备请求 / 承诺 |
| accept request / accepted proposal | 接受请求 / 已接受提案 |
| chosen value | 被选定的值 |
| majority quorum / quorum intersection | 多数派仲裁集 / 仲裁集相交 |
| 2f + 1 replicas | 2f+1 个副本 |
| single-decree Paxos / Multi-Paxos | 单决议 Paxos / 多决议 Paxos |
| distinguished proposer / distinguished learner | 指定提议者 / 指定学习者 |
| stable storage / forced write | 稳定存储 / 强制写 |
| crash-recover / crash-stop | 崩溃-恢复 / 崩溃-停止 |
| asynchronous system / partial synchrony | 异步系统 / 部分同步 |
| FLP impossibility | FLP 不可能性 |
| bivalent state | 双价状态(结果未定状态) |
| dueling proposers / livelock | 提议者决斗 / 活锁 |
| randomized backoff | 随机退避 |
| leader election | 领导者选举 |
| bully algorithm | 霸道(欺凌)算法 |
| ring election (Chang–Roberts) | 环选举(Chang–Roberts 算法) |
| term / vote | 任期 / 投票 |
| split vote / split brain | 选票分裂 / 脑裂 |
| lease | 租约 |
| invariant | 不变式 |
| model checking / state space / counterexample | 模型检查 / 状态空间 / 反例 |
| fingerprint (state hashing) | 指纹(状态哈希) |
| replicated state machine | 复制状态机 |
| NAK (negative acknowledgement) | 否定应答 |