Part II — Failure, replication, agreement · Chapter 6

Consensus

~20 min1 instrumentA.Y. 2025/26 · Prof. Omicini
C3 The Problem of Consensus in Distributed Systems
The question

Can unreliable processes on an asynchronous network always reach the same decision? If not, what can they still guarantee?

The argument in one paragraph

Committing a transaction, keeping replicas identical, recovering from a crash: all are agreement problems, and consensus is their general form. FLP proves that in a fully asynchronous system no deterministic protocol can guarantee a decision if even one process may crash, because a crashed process looks exactly like a slow one. The way out is to keep safety unconditional and let only termination depend on the system staying calm for long enough. Paxos does exactly that. Run it once per log slot and you get state machine replication.

Why processes must agree

Components may hold divergent views of the system state and of what is happening. Coherent behaviour then requires them to agree on everything relevant (state, events…). What matters is that they reach the very same conclusion, whatever it is about.

Examples of agreement problems [Fischer, 1983]

  1. Distributed database: commit or abort a distributed transaction?
  2. Replicated file system: where should the file copies reside?
  3. Flight control: the engine and flight-surface control modules must agree whether to continue or abort a landing.
Agreement problem[Fischer, 1983]

Agreement problems involve a system of processes, some of which may be faulty. A fundamental problem of fault-tolerant distributed computing is for the reliable processes to reach a consensus.

Consensus[C3]

Consensus is the process by which we reach agreement over system state between unreliable machines connected by (possibly) asynchronous networks.

When processes fail, the reliable ones must agree on what has happened and what happens next, so that state and evolution stay consistent, e.g. during recovery (Ch. 4). So consensus is essential to fault tolerance: when a crash breaks replica synchronisation, recovery needs the replicas to agree on each replica's state and on the events handled or still to handle.

Consensus is often hidden inside other problems: commit (§3), replication (Ch. 5), replicated state machines (§7), coordinator election (Ch. 2) and ledgers (Ch. 7). Reducing so many issues to one abstract problem gives general solutions. “…how hard can this be?”

The model: processes, time, failures

A system is modelled as a collection of processes (logical) or processors (physical) that compute at the same time and interact through:

  1. one-to-one direct channels: message-passing architectures;
  2. shared channels: shared-memory architectures.

Concurrent or distributed, process or processor, even parallel: the literature uses them interchangeably when the problem is unaffected by its physical nature (precise terms: Ch. 1).

Time modelC3 · basic ontology

Synchronous: there is a bound Δ on message transmission delay and a bound Φ on the relative speed of processes, which allows accurate failure detection.

Asynchronous: otherwise. This models unpredictable load on network and CPUs, where it is never possible to know whether a process has crashed or not.

A crashed process and a slow one both look silent. Waiting for it may never end; deciding without it risks contradicting a decision it is about to make.

Failure model: processes, processors and links may all fail, in diverse ways. Fault tolerance is the property of keeping working beyond faults of any sort (Ch. 4).

The problem, precisely

Basic (single-bit) consensus[Fischer, 1983]

There is a fixed number n of possibly faulty processors, and each has an initial bit xi. The non-faulty processes must agree on a bit y, the consensus value. The problem is solvable if some protocol makes all non-faulty processors terminate with the same y.

As stated, “always output 0” would work. So dependency requirements say how y must depend on the inputs, and each choice defines a different problem:

Dependency requirements [Fischer, 1983]

  1. Non-triviality: for each y ∈ {0, 1}, some input vector and run lead to y.
  2. Strong unanimity: if xi = x for all i, then y = x.
  3. Weak unanimity: the same, required only if no failures occur at run time.

Two relatives change what is agreed on:

Problem [Fischer, 1983]Agree onStrongWeak
Interactive consistencya vector y: what each processor's initial value wasyi = xi for each non-faulty ithe same, if no failures occur during the run
Generals problem (reliable broadcast)the bit x that the general (transmitter) sends to ally = x if the general is not faultyy = x if no failures occur

The concrete case is transaction commit [Dolev & Strong, 1982]: the data managers of a transaction agree whether to install its results or discard them (say, because one could not do its part). All must decide the same, or the database becomes inconsistent.

For Paxos the slides use today's names. Agreement: no two processes decide differently. Validity: the decided value was proposed. Termination: every non-faulty process eventually decides. The first two are safety, the third liveness.

With reliable processes and network, commit is straightforward. Real systems suffer faults [Fich & Ruppert, 2003]:

  1. process crashes;
  2. network partitioning;
  3. lost, distorted or duplicated messages;
  4. Byzantine failures, where faulty processes go out of control or behave malevolently.

Enough faults overwhelm any protocol, so the goal is tolerating a prescribed number of “expected” ones.

FLP: impossible with one crash

Fich & Ruppert survey “hundreds” of impossibility results, outright or within resource bounds, across models of synchrony, fault tolerance, communication and randomisation. CAP is not alone (Ch. 5):

Impossibility, again

  1. Distributed systems are easy to conceive and build, easy to crash, hard to understand and debug.
  2. Formal proofs are fundamental for serious engineering, yet properties are difficult to prove.
  3. So we must know how models affect properties, and what we cannot solve.
FLP impossibility[Fischer, Lynch & Paterson, 1985]

In a fully asynchronous system, no consensus protocol can tolerate even a single crash failure, under the mere requirement of non-triviality.

The other hypotheses are kind: no Byzantine failures, reliable exactly-once delivery. Still, one process stopping at an inopportune time can defeat any commit protocol. Without further assumptions, or tighter limits on the failures tolerated, there is no robust solution.

What the proof shows

A configuration (all process states plus the messages in transit) is univalent (0- or 1-valent) if only one decision is still reachable from it, and bivalent if both are. For a deterministic protocol, the proof has two steps:

  1. Some initial configuration is bivalent (Fig. 6.1): the inputs alone do not fix the outcome; the schedule does.
  2. Bivalence can last forever. From a bivalent configuration, any pending step can be taken, possibly after others, and still reach a bivalent configuration. That yields an infinite run where every process keeps stepping and every message arrives, yet nobody decides.
WHY SOME INITIAL CONFIGURATION IS BIVALENT 0 0 0 1 0 0 1 1 0 1 1 1 inputs p1 p2 p3 0-valentif 0-valent: Cif 1-valent: C′1-valent p1p2p3 C and C′ differ only in p2's input. Run both with p2 silent: p1 and p3 see exactly the same run, so they must decide the same value in both. So C and C′ cannot be 0-valent and 1-valent: one of them is bivalent.
Fig. 6.1 — Step 1 with three processes. Neighbouring initial configurations differ in one input, so if all were univalent the valence would flip somewhere along the chain. Unanimity fixes the endpoints here for concreteness; FLP needs only non-triviality.
Reading the FLP slide

The slide says a stopped process can make a commit protocol “fail to reach agreement”. Read this as fail to reach a decision. The proof's run stays undecided forever; it never makes processes decide differently. Nor does anyone actually stop in it: one process that is slow at the wrong moments is enough, because it cannot be told apart from a crashed one.

FLP shows that a bad run exists for every such protocol, not that it is likely.

From impossible to possible

Give up the problems, or essential features of the systems solving them? The slides choose a third road: solutions within the boundaries impossibility theorems set, following Howard's “making impossible possible”:

Solution to FLP [Howard, 2016]

  1. In practice: accept that the system will sometimes be unavailable, and mitigate that with timers and backoffs.
  2. In theory: make weaker assumptions about synchrony, e.g. “messages arrive within a year”.

Neither refutes FLP. A timer only guesses that a silent process crashed, so a wrong guess must cost time, never safety; and assuming some bound, however large, suffices to prove eventual decision. Paxos is built on this split.

Beyond the slides · the classic escapes

Partial synchrony [Dwork, Lynch & Stockmeyer, 1988]: bounds exist but are unknown. Failure detectors [Chandra & Toueg, 1996]: eventually accurate suspicion. Randomisation [Ben-Or, 1983]: termination with probability 1.

Paxos

Lineage

  1. A 1989 technical report by Lamport, recast in a more academically viable form as “The part-time parliament” [Lamport, 1998].
  2. Generalised with respect to state machine replication [Lampson, 1996].
  3. Formally described and proven correct [De Prisco et al., 1997].
  4. Nicely explained in “Paxos made simple” [Lamport, 2001].

Features

  1. Paxos implements fault-tolerant consensus on a single value.
  2. It runs on a completely connected network of n processes and tolerates up to f failures, with n ≥ 2f + 1.
  3. Processes can crash and messages may be lost. Byzantine failures are ruled out.
  4. It primarily guarantees agreement and validity.
  5. Termination is ensured only if there is a sufficiently long interval in which no process restarts the protocol.

Items 4 and 5 are the answer to FLP: safety is unconditional, liveness is conditional.

Process roles

  1. Proposer: submits proposed values on behalf of clients.
  2. Acceptor: decides the candidate values for the final decision.
  3. Learner: collects this from the acceptors and reports the final decision back to the clients.

Roles are logical processes [Tanenbaum & van Steen, 2017]: one process may play all three. The basic idea is a two-phase process (promise, then commit), majority agreement and monotonically increasing numbers labelling proposals.

Why two phases

Paxos made simple [Lamport, 2001]

  1. Values are proposed by proposers.
  2. There is not one acceptor but several, an odd number.
  3. Quorum: once a bare majority of acceptors accepts a value, it is chosen.
  4. Once a value is chosen, future proposals must propose the same value.
  5. Hence two phases: prepare finds out whether a value may already be chosen, and accept proposes accordingly.
  6. The result is either a chosen value or another iteration, which in theory might lead to livelock.

One acceptor's crash would stop everything, hence several. A majority suffices because any two majorities share at least one acceptor, and with 2f + 1 acceptors a majority survives f crashes. Hence n ≥ 2f + 1, and an odd number: a (2f + 2)-th acceptor enlarges the majority without tolerating another crash.

Point 4 is the core. A proposer cannot see whether a value was chosen: acceptances may be lost or sit on crashed acceptors. So it first asks a majority what they accepted, and makes them promise to ignore older proposals so the answer cannot go stale. That majority overlaps any choosing majority, so the chosen value (or a later proposal carrying it) is among the replies, and adopting the highest-numbered one suffices.

The phases [Ghosh, 2014]

Proposals

  1. A proposal is a pair (v, n): a value and a sequence number.
  2. To deal with crashes, multiple acceptors are selected for the proposal.
  3. A proposal must be endorsed by at least one acceptor before it becomes a candidate for the final decision.
  4. The sequence number distinguishes successive attempts to invoke the protocol.
  5. On receiving a proposal with a larger sequence number from a given process, acceptors discard those with lower numbers.
  6. Eventually, an acceptor accepts the majority's choice.

Phases

  1. Preparatory phase. Each proposer sends (v, n) to each acceptor. If n is the largest number an acceptor has seen, it replies ack(n, ⊥, ⊥), a promise to ignore proposals numbered below n. If it has already accepted (v, n′) with n′ < n, it replies ack(n, v, n′).
  2. Request for acceptance. A proposer with acks from a majority sends accept(v, n) to all acceptors. If any ack carried a value, v must be the one with the highest number (rule 2.1). An acceptor accepts unless it has promised some n′ > n.
  3. Final decision. A value accepted by a majority becomes the decision. The acceptors multicast it to the learners, which check the majority and tell the clients.

Ghosh's observations turn these rules into the two invariants behind safety:

  1. An acceptor accepts proposal n only if it has not promised any n′ > n.
  2. If accept(v, n) is sent, then either no acceptor in some majority has accepted any n′ < n, or v is the value of the highest-numbered such proposal accepted in that majority.
Three loose phrasings

In Lamport's formulation prepare carries only n; the value is fixed after the acks. The slides read ack(n, v, n′) as “no point” in trying a larger number; what it actually imposes is rule 2.1: drop your own value and propose v. And a promise holds against lower numbers from any proposer, not one given process.

Prepare phaseAccept phaseLearning phase ProposerAcceptorAcceptorAcceptorLearnerLearner PREPAREPREPARE_ACK ACCEPTACCEPT_ACK COMMIT
Fig. 6.2 — Basic Paxos, after Zhao [2014]: one round trip per phase. In Ghosh's version the acceptors notify the learners directly.
Instrument 1Paxos simulator

P1 wants red, P2 wants blue. You are the network: deliver, drop, crash. Step through a scenario or play freely; the verdict checks that at most one value is ever chosen.

In flight

    blue: prepare/ack · green: accept/accepted · ○ ignored · × dropped or lost · red bar: acceptor down

    Duelling proposers and leaders

    Scenario 4 is point 6's livelock. Promises for 2 make P1's accept for 1 ignored; P1 retries with 3, making P2's accept ignored; and so on. Every rule holds and nothing is chosen: FLP's endless run, made concrete. The remedy is a distinguished proposer, a leader, plus timers and backoffs. This reduces conflicts without eliminating them: electing a leader is itself agreement, so two processes may briefly both believe they lead. That costs progress, never safety.

    From one value to a replicated log

    State machine replication[Schneider, 1990]

    Replication relates to consensus because all replicas of a resource must agree on the same state over time. The state machine approach is a general method for implementing fault-tolerant services in distributed systems.

    1. The same state machine is replicated over a distributed system.
    2. Each replica has a consensus module.
    3. An operation is performed on a replica only if and when all machines have agreed on the same order of execution.
    4. Consensus over distributed state becomes consensus over distributed actions on state.
    5. Determinism is assumed.

    Determinism makes the shift sound: same start, same operations, same order, same state. It is the replicated bank account of Ch. 2, fixed by agreement rather than clocks.

    clienty ← x+1 consensus module x←3 y←x+1 … state machine x=3 y=4 agree on slot 2
    Fig. 6.3 — State machine replication, after Howard [2016]: consensus fills each log slot, and deterministic machines replay the log.

    Multi-Paxos [Van Renesse & Altinbuken, 2015]

    1. SMR needs consensus over an array of values; Paxos handles one.
    2. Multi-Paxos runs one separate, indexed Paxos instance per array entry,
    3. plus leader election to reduce proposer conflict, presumably dropping iterations.
    4. It is not really well specified overall.

    Other Paxos-based algorithms

    1. Fast Paxos [Lamport, 2006]: proposers send values straight to the acceptors, bypassing the leader. Without conflicts this saves a message delay, at the price of larger quorums.
    2. ZooKeeper [Hunt et al., 2010]: a coordination service.
    3. ZAB, ZooKeeper atomic broadcast [Reed & Junqueira, 2008].
    4. Egalitarian Paxos [Moraru et al., 2013]: leaderless.
    5. Raft [Ongaro & Ousterhout, 2014]: designed to be understandable, with a strong leader.

    Chubby. Google built a Paxos-based fault-tolerant database [Chandra et al., 2007] for Chubby [Burrows, 2006], a reliable lock service used widely inside Google, e.g. by GFS and Bigtable. They use Chubby; Chubby runs Paxos. Ledgers take the same state-machine idea to open, Byzantine settings (Ch. 7).

    Lessons

    General

    1. Impossibility results define the space of problems we can actually solve.
    2. Relating formal models to their practical instances often reveals a technically feasible solution.
    3. Formal models are essential to sound engineering of distributed systems, and not just in very complex settings.

    Specific

    1. Faults are both the source of the problems of distributed systems and the reason we need them.
    2. Consensus is one of the most expressive and general ways to model distributed application problems.
    3. Its complexity defies common sense and yields archetypal impossibility results.
    4. Yet protocols solve it in meaningful cases by relaxing some hypotheses: Paxos & friends.

    For the oral

    Why can't a timeout solve FLP?

    A timeout guesses a crash; the process may only be slow. Acting risks disagreement, never acting risks waiting forever. Timeouts give progress; safety must survive wrong ones.

    Why does Paxos need a prepare phase?

    A proposer cannot see whether a value was chosen. Prepare queries a majority (intersecting any choosing one) and freezes the answer with promises; rule 2.1 carries the value forward. Show scenario 3 with and without the broken rule.

    Where does n ≥ 2f + 1 come from?

    Majorities intersect, so no accepted value is forgotten, and 2f + 1 acceptors keep a majority after f crashes. With more crashes (scenario 2), Paxos stalls but never decides wrongly.

    Does Paxos contradict FLP?

    No. Safety always holds; termination needs a calm enough period. Duelling proposers can stall it forever. A leader makes that unlikely, not impossible.

    How do consensus, replication and CAP connect?

    SMR turns replication into agreeing on the order of deterministic operations. In a partition, a minority cannot form a majority and stops rather than diverging: in CAP terms, Paxos picks consistency (Ch. 5).

    Project lens · Thunk
    Slide coverage: where each slide section went
    SlidesContentHere
    C3 · Agreement I–II; Agreement & FT; Consensus; Consensus & FTProblem, examples, definitions, why§1
    C3 · Basic ontology I–IVComponents, terms, time and failure models§2
    C3 · Many problems I–III; Commit; So what?; What is the problem?Fischer's problems and requirements; commit; faults§3, §1
    C3 · Impossibility I–II; FLPImpossibility results; FLP§4
    C3 · So what?; Harsh reality I–IIOptions; solution to FLP§5
    C3 · Paxos I–VI; Made simple; Phases I–IV; ObservationsLineage, features, roles, reasoning, phases§6
    C3 · SMR I–II; Beyond Paxos I–II; ChubbySMR, Multi-Paxos, variants, Chubby§7
    C3 · Lessons learnt I–IIGeneral and specific lessons§8