Implement each broadcast model of Module 1 on top of point-to-point links, prove the algorithms correct (safety and liveness), count their cost, and see exactly where the simple total order algorithms stop being fault tolerant.
Module 1 defined what each broadcast promises. This module shows how to keep those promises with nothing but point-to-point messages, and proves that the algorithms do. The plan of lecture 04.04 has two layers. The lower layer makes sure every message reaches every correct node, even if its sender crashes halfway (reliable broadcast). The upper layer decides when a received message may be delivered (FIFO, causal or total order).
The reliability layer and the FIFO and causal layers need no coordination at all: every node decides alone, from metadata carried by the messages. Total order is different. Both simple algorithms for it (a sequencer, or Lamport timestamps) work, but each stops completely when a single node crashes. Making the sequencer fault tolerant is exactly the consensus problem, which the rest of these notes solve.
The module follows lectures 04.04 (Broadcast Algorithms) and 04.05 (Broadcast Protocols, Part 2), and Kleppmann’s notes, Section 4.3, slides 81-86 (1).
Two layers on top of the network
Question. What does each layer have to guarantee, and which layer should handle lost packets?
Figure 2.1. The two layers of lecture 04.04 on top of point-to-point links: first make every message reach every correct node, then decide when to deliver it.
The bottom of Figure 2.1 is the network of the system model: it may drop, delay, duplicate or reorder packets.
Definition 2.1 (Reliable link).
A reliable link from node to node provides and with
reliable delivery: if and are correct and sends to , then eventually receives ;
no duplication: receives each sent message at most once;
no creation: if receives from , then sent to .
A reliable link is FIFO if, in addition, receives the messages from in the order sent them.
A reliable link is built from a lossy one by numbering messages, retransmitting until acknowledged, and discarding duplicates by number. TCP does all of this and is also FIFO. Lecture 04.04 notes that real systems almost always simply use TCP; only a system whose throughput depends on the broadcast (for example inside one data center, where loss is rare) might use UDP and fold a lighter retransmission scheme into the broadcast algorithm.
Note what a reliable link does not give: if the sender crashes, its retransmissions stop and the receiver may never get the message (condition 1 needs correct). That gap is what the next section closes.
Reliable broadcast: eager relaying
Question. How do the correct nodes agree on whether a message exists when its sender may crash after sending only some of the copies?
The first attempt of Kleppmann’s slide 81 sends directly to every node over reliable links. It satisfies best-effort broadcast and fails agreement, as Example 1.7 showed. The repair is to enlist every recipient: the first time a node receives a message, it forwards it to everybody else. Then a single correct node holding suffices to spread it.
// eager reliable broadcast at node i (Kleppmann slide 82)on initialisation: seen := {} // ids of messages already handled count := 0on request to broadcast m: m.id := (i, count) // unique message id count := count + 1 handle(m)on receive m from a reliable link: handle(m)procedure handle(m): if m.id not in seen: seen := seen + {m.id} for each node j != i: send m to j via reliable link deliver m to the application
Line
Why it is there
if m.id not in seen
each node handles a message once: gives no duplication, and stops the forwarding
send m to j for every
the relay: after this step, the fate of no longer depends on the original sender
deliver m after the loop
a node delivers only after it has relayed (this order matters for Remark 2.3)
Theorem 2.2 (Eager reliable broadcast is correct).
Assume crash-stop nodes and reliable links. Every execution of eager reliable broadcast satisfies reliable broadcast (Definition 1.6): integrity, validity and agreement. In an execution without crashes, each broadcast causes exactly point-to-point messages.
Proof
We treat each handler as one atomic step of a node; a node that crashes simply takes no further steps, so a crash can interrupt the sequence of sends only between steps of a faulty node’s execution of the loop. (A correct node completes every step it starts.)
No creation. By induction on the events of the execution: every message a node receives was sent by some node (no creation of links), and a node sends only inside , which is called either by the original broadcast or on receipt of . Following the chain of receipts backwards (it is finite, since each receipt follows its send), we reach a call of broadcast for at , which precedes every delivery of .
No duplication. A node delivers only inside the branch guarded by m.id not in seen, and the same step adds m.id to seen. Ids are unique (a node never reuses a value of count), so each message is delivered at most once per node.
Validity. If correct node broadcasts , then runs at with a fresh id, so delivers in that step. It also sends to every other node over reliable links; since is correct, every correct eventually receives , runs and delivers , unless m.id was already in its seen, in which case delivered in an earlier step.
Agreement. Let a correct node deliver . It did so in a step of whose loop sent to every other node, and , being correct, completed that step. By reliable delivery (both ends correct), every correct node eventually receives from . When it does, either has m.id in seen (and then delivered when it inserted the id) or inserts it now and delivers . Either way delivers .
Cost. Without crashes every node handles exactly once and sends copies in that step: messages in total.
Agreement needed only one correct node that had delivered . This is precisely the situation of Figure 2.2, where the original sender crashed but B’s relay reached C.
Try it: step through the run. A crashes right after its first copy leaves, and B’s relay saves the broadcast. The last step counts the point-to-point messages: 5, because A sent only one of its two copies; a run without crashes sends . Then switch off re-broadcast on first receipt and step again: C never delivers m.
Figure 2.2. Eager reliable broadcast (Kleppmann slide 82). A crashes after its copy to B left; because B forwards m on first receipt, C still gets it. The dashed copy is redundant traffic, the price of the O(n squared) message count.
Remark 2.3 (Uniform agreement needs a majority).
Eager reliable broadcast does not give uniform agreement. Node may relay , deliver it, and crash before any copy leaves its machine; a reliable link from a crashed sender may lose those copies, so no correct node ever delivers although did. The standard fix: a node delivers only after it has received copies of (relays act as acknowledgements) from a majority of nodes. If , some correct node is in that majority and has already relayed , so every correct node gets it (2). The price is that a node must wait for nodes, an early sighting of the majority quorums that dominate Modules 3-9.
Gossip: relaying to a few random nodes
Question. Eager reliable broadcast sends messages per broadcast. With thousands of nodes that is too much. Can we relay less and still reach everybody?
Lecture 04.04 describes the gossip (or epidemic) idea: a node that has the message sends it to a few, say 3 or 4, randomly chosen nodes; each of those does the same, and so on. Like a rumour, the message spreads quickly, and no node depends on any particular other node. The price is that the guarantee becomes probabilistic: “every node receives the message with high probability”. To make that precise we use the simplest analysable model.
Definition 2.4 (Push gossip with fanout k).
Time proceeds in rounds. In every round, every node that has the message (an informed node) sends it to nodes, each chosen independently and uniformly at random among the other nodes. A node that receives the message becomes informed and starts gossiping in the next round. Nodes keep gossiping for a fixed number of rounds after they are informed.
The spread has two phases. While few nodes are informed, almost every copy reaches a new node, so the informed set grows by a factor of about per round: about rounds bring it to half the nodes. After that, most copies hit nodes that already know, and the question becomes how fast the last stragglers are found. The second phase is where the “high probability” comes from, and it has a clean proof.
Proposition 2.5 (The last phase of gossip).
In push gossip with fanout and no crashes, suppose that at the start of some round at least nodes are informed, and that informed nodes keep gossiping for the next rounds. Then
In particular, rounds leave some node uninformed with probability at most .
Proof
Fix a node that is uninformed at the start of the rounds. In each of these rounds at least nodes are informed (the informed set never shrinks), and each sends copies to targets chosen independently and uniformly among its other nodes. A single copy misses with probability at most (exactly that if the sender is not ). So the probability that all of the at least copies of one round miss is at most
using and . The targets of different rounds are chosen independently, so the probability that is missed in all rounds is at most . There are fewer than such nodes ; by the union bound, the probability that at least one of them is still uninformed is at most . Substituting gives .
So with the first phase, about rounds, that is rounds, reach every node with high probability, while each informed node sends only messages per round.
Fine print: "forward once to three nodes" is not enough for large groups
Kleppmann’s slide 83 states the rule “when a node receives a message for the first time, forward it to 3 other nodes” and says it reaches all nodes with high probability. If each node forwards only once, that is not true for large : a constant fraction of nodes is missed. Heuristically, if a fraction of nodes ends up uninformed, about copies were sent in total, and a fixed node is missed by all of them with probability about , so ; for this gives , about 6% of the nodes. The high-probability guarantee needs nodes to keep gossiping for several rounds (as in Proposition 2.5), or a fanout that grows like , or a periodic “anti-entropy” exchange that repairs the stragglers, as in Demers et al. (3).
Lecture 04.04 draws the practical consequence. Gossip makes it very likely that the information reaches everybody soon, but it never tells you that a particular node has it now. If you update a replicated register from 3 to 4 by gossip and then answer a read from one randomly chosen replica, you may well return the stale 3. Systems such as Amazon’s Dynamo therefore combine gossip with reading and writing at several replicas, so that read and write sets overlap: the quorums of Module 3.
FIFO broadcast: per-sender sequence numbers
Question. Given reliable broadcast, how does a node make sure it delivers each sender’s messages in the order they were sent?
FIFO is a promise per sender, so a per-sender counter is enough (lecture 04.05: “[per] sender you need a counter, that’s basically it”). Each message carries its sender’s sequence number ; each receiver remembers, per sender, how many messages it has delivered, and holds back any message that arrives early.
// FIFO broadcast at node i, over reliable broadcast (Kleppmann slide 84)on initialisation: sendSeq := 0 delivered := [0, 0, ..., 0] // delivered[j] = # delivered from j buffer := {}on request to broadcast m: send (i, sendSeq, m) via reliable broadcast sendSeq := sendSeq + 1on receive (j, s, m) from reliable broadcast: buffer := buffer + {(j, s, m)} while exists (k, s', m') in buffer with s' = delivered[k]: deliver m' to the application buffer := buffer - {(k, s', m')} delivered[k] := delivered[k] + 1
Two words about the interface. “Receive from reliable broadcast” is the delivery event of the lower layer; to the FIFO layer it is an arrival, not yet a delivery. And the message a node broadcasts comes back to itself through reliable broadcast, which is how a node FIFO-delivers its own messages. Kleppmann’s slide omits the line that removes delivered messages from the buffer; without it the algorithm is still correct (the condition s' = delivered[k] never matches a delivered tuple again) but the buffer grows forever.
Example 2.6 (The FIFO algorithm at node C).
Run the algorithm on the execution of Figure 1.2, with node order A, B, C. A broadcasts and ; B broadcasts . Node C receives them from reliable broadcast in the order .
Arrival at C
Delivered by the loop
Buffer afterwards
delivered afterwards
nothing: delivered[A]
, then
The third arrival triggers two deliveries: once is out, delivered[A] becomes 1, which matches the waiting , and the while loop takes it as well.
Theorem 2.7 (The FIFO algorithm implements FIFO broadcast).
If the lower layer satisfies reliable broadcast, then every execution of the FIFO algorithm satisfies FIFO broadcast (Definition 1.8). More precisely, at every node and for every sender :
(prefix) at all times, the messages from that has delivered are exactly those with sequence numbers , delivered in this order;
(no starvation) if is correct and has received from reliable broadcast every message of with sequence number at most , then eventually delivers all of them.
Proof
Sender numbers its broadcasts in the order it makes them (sendSeq starts at 0 and increases by one per broadcast), so the pair (sender, sequence number) identifies a message, and a smaller number means an earlier broadcast.
Part 1, by induction over the delivery steps at . Initially nothing is delivered and . A step delivers only if , and then increments . By the induction hypothesis the delivered set from was , so afterwards it is , and the new message has the largest number so far. Each tuple is in the buffer at most once (reliable broadcast has no duplication) and is removed when delivered, so no message is delivered twice.
FIFO order. Let broadcast (number ) and later (number ). If delivers , part 1 says that at that moment the delivered set from is , delivered in increasing order; so was delivered before .
Part 2, by induction on . Suppose has received . By the induction hypothesis the messages numbered below are eventually delivered, so eventually . If at that point has been delivered we are done. Otherwise by part 1, and is in the buffer (it was received and not yet removed). The while loop runs after every arrival and only stops when no buffered tuple matches; consider the step in which the later of the two events happened (the arrival of , or the delivery that made , which happens inside a loop). In that step the loop finds matching and delivers it.
Integrity. No duplication is part 1. No creation: delivers only tuples received from reliable broadcast, which has no creation, and only after they were broadcast.
Validity. If correct broadcasts with number , it previously broadcast the messages numbered . Validity of reliable broadcast gives that every correct receives all of them, and part 2 that delivers .
Agreement. If correct delivers , then by part 1 it delivered, hence received, all of ‘s messages numbered . Agreement of reliable broadcast makes every correct node receive all of them, and part 2 makes it deliver .
Intuition: why no message waits forever
A message from waits at only for messages from with smaller numbers. Each of those was broadcast before it, so reliable broadcast either brings it to every correct node or (if crashed in the middle) to none. In the second case the later message is stuck at all correct nodes alike, which agreement allows. Gaps are never “partially” filled.
Causal broadcast: dependency vectors
Question. FIFO looks only at the sender’s own previous messages. How can a node know which messages from other senders a message depends on?
The sender writes it down. When node broadcasts , it attaches a vector whose entry says how many messages from node it has delivered so far, and whose own entry is the number of messages it has itself broadcast before . A receiver delivers once it has delivered at least that many messages from every node. This is Kleppmann’s slide 85; lecture 04.05 calls the check “dependencies less than or equal to delivered”.
// causal broadcast at node i, over reliable broadcast (Kleppmann slide 85)on initialisation: sendSeq := 0 delivered := [0, 0, ..., 0] // delivered[k] = # delivered from k buffer := {}on request to broadcast m: deps := copy of delivered deps[i] := sendSeq send (i, deps, m) via reliable broadcast sendSeq := sendSeq + 1on receive (j, deps, m) from reliable broadcast: buffer := buffer + {(j, deps, m)} while exists (k, d, m') in buffer with d <= delivered: // componentwise deliver m' to the application buffer := buffer - {(k, d, m')} delivered[k] := delivered[k] + 1
For a message broadcast by node , write for its vector and for its own entry: the number of messages broadcast before . Vectors are compared componentwise, iff for every (Kleppmann slide 72). The delivery condition is
Remark 2.8 (These vectors are not vector clocks).
Kleppmann points out the difference. A vector clock (lecture 04.02) counts events observed from each node. Here counts messages from that have been delivered. A message received but still buffered does not count; this is what makes the algorithm respect causality defined through deliveries (Remark 1.4).
Try it: step through the lecture example. At each arrival at C, compare the message’s deps vector with C’s delivered vector and predict whether it is delivered or buffered before you press the next step.
ABCm1 [0,0,0]m1m2 [1,0,0]m2m3 [1,0,0]m3m2 heldneeds [1,0,0], has [0,0,0]m1, m2m3delivered at C: [0,0,0] -> [1,0,0] -> [1,1,0] -> [2,1,0]Figure 2.3. The causal broadcast algorithm (Kleppmann slide 85) on the lecture example, vectors in node order A, B, C. When m2 reaches C, its deps vector exceeds C's delivered vector, so C holds it; delivering m1 releases m2.
Example 2.9 (The causal algorithm on the lecture example).
Use the execution of Figure 1.3 (node order A, B, C), but let the copy of to C be slow, as in Figure 2.3.
A broadcasts : ; A delivers it to itself, so .
B delivers () and broadcasts with (its own entry is ).
A broadcasts with (its own entry is ; it has delivered nothing from B or C).
Arrival at C
Check
Delivered
delivered at C
, deps
: hold
nothing
, deps
ready; then ready
, deps
C delivers , respecting and . Node A delivers (it delivers its own at once, since ). The two orders differ on the concurrent pair, as causal broadcast allows.
Correctness of the causal algorithm
The proof has three small lemmas: per-sender deliveries form a prefix, dependency vectors grow along causal chains, and a vector “covers” every causal predecessor. Throughout, causal precedence is that of Definition 1.3, and ” is a step” means a chain of length one (program order, or delivery then broadcast).
Lemma 2.10 (Per-sender prefix).
At every node , at all times and for every sender , the messages from that has delivered are exactly those with , and delivered them in increasing order of .
Proof
Sender assigns values to its broadcasts, so identifies a message. Induction over delivery steps at . Initially the claim holds with the empty set. Suppose delivers from with . The condition includes . If , then by the induction hypothesis the message from with number , which is itself, was already delivered and therefore removed from the buffer; since reliable broadcast delivers each message to the causal layer once, cannot be in the buffer again. So , and after the step the delivered set from is with last.
Lemma 2.11 (Dependency vectors grow along steps).
If is a step, then and .
Proof
Let and let be the time at which broadcasts , so at time for , and . Two facts about node : never decreases; and at all times, because by Lemma 2.10 the messages from that delivered have numbers below and each of them was broadcast, so has number below .
Program order: broadcast at time . For , at , which is at most its value at . For , . This proves both claims, since .
Delivery then broadcast: delivered at time , and has sender . Just before that delivery by , and right after it by Lemma 2.10. By monotonicity both bounds still hold at time . For entries this gives , and if also . For the entry : at time . If , then is an earlier broadcast of and the program-order case applies.
Take a chain of steps. By Lemma 2.11, and , so . The same chain gives . They differ in the entry : .
Theorem 2.13 (The causal algorithm is safe).
If the lower layer satisfies reliable broadcast, every execution of the causal algorithm satisfies integrity and causal order: if and a node delivers , then delivered before .
Proof
Causal order. When delivers , condition holds: . Let . By Lemma 2.12, . By Lemma 2.10, the messages from delivered by are those numbered below ; this includes , so has already delivered .
Integrity. No duplication follows from Lemma 2.10 (each delivered tuple is removed and never re-enters the buffer). No creation: delivers only what reliable broadcast handed it, and reliable broadcast has no creation.
Intuition: the vector is a summary of "what I had seen"
When broadcasts , its vector is a compact list of every message it had seen: the first messages of each sender (a prefix, by Lemma 2.10). Those are exactly the messages that could have influenced , because anything saw it had delivered. A receiver that has delivered at least that prefix of every sender has seen everything had seen. The lemma about steps just checks that this summary only grows along a causal chain.
Safety is not enough: an algorithm that never delivers anything is trivially safe. Liveness needs the reliable layer.
Theorem 2.14 (The causal algorithm is live).
If the lower layer satisfies reliable broadcast, every execution of the causal algorithm satisfies validity and agreement. Together with Theorem 2.13 it implements causal broadcast (Definition 1.9).
Proof
For a message define its dependency set: the messages with . Each such exists: if , it is one of ‘s earlier broadcasts; otherwise the sender of had delivered it (Lemma 2.10). In both cases (by program order, or by a delivery-then-broadcast step), so by Lemma 2.12, , hence , and .
Claim. If a correct node receives from reliable broadcast the message and every message in , then eventually delivers .
Proof of the claim by strong induction on . Every has a smaller sum and , so all of was received by ; by the induction hypothesis eventually delivers every . For each sender , contains the messages of numbered , so by Lemma 2.10 eventually for all , that is holds for . If was not delivered before, it is in the buffer; in the step where the last of these deliveries or the arrival of happens, the while loop runs until no buffered message is ready, so it delivers .
Validity. Let correct broadcast . The messages in are ‘s own earlier broadcasts (received everywhere by validity of reliable broadcast, since is correct) and messages delivered, hence received from reliable broadcast at the correct node (received everywhere by agreement of reliable broadcast). itself is received everywhere by validity. The claim gives delivery at every correct node.
Agreement. Let correct deliver . At that moment held, so by Lemma 2.10 had delivered, hence received, every message of , and it received . By agreement of reliable broadcast every correct node receives all of them, and the claim gives delivery of .
Total order broadcast
Question. FIFO and causal order could be decided by each node alone. Total order requires every node to make the same choice about concurrent messages. Who chooses?
Lecture 04.05 and Kleppmann’s slide 86 give two answers: one designated node chooses (a sequencer), or a deterministic rule on timestamps chooses and everybody waits until the rule’s answer is certain. Recall that total order constrains only the agreement between nodes; the order itself may be arbitrary (Proposition 1.16, execution E4).
A single leader (sequencer)
// total order broadcast through a fixed sequencer L (lecture 04.05, slide 86)on request to TO-broadcast m at node i: send Request(m) to L via reliable FIFO linkon receive Request(m) at L: FIFO-broadcast Ordered(m) // L handles requests one by oneon FIFO-deliver Ordered(m) at node i: TO-deliver m to the application
Theorem 2.15 (The sequencer gives FIFO-total order while the leader is up).
Assume the FIFO broadcast used by satisfies Definition 1.8 and links are reliable and FIFO. Then every execution satisfies integrity, total order (Definition 1.10) and FIFO order. If is correct, it also satisfies validity and agreement. If crashes, no message that has not yet FIFO-broadcast is ever delivered.
Proof
Every TO-delivery is a FIFO-delivery of a message broadcast by the single sender . Number ‘s FIFO broadcasts in the order makes them.
Each node delivers a prefix of ‘s sequence. By FIFO order, a node that delivers has delivered before it, in this order (apply FIFO order to each pair with ). So the delivery sequence of every node is for some (possibly infinite).
Total order. Let and . Since delivers a prefix of ‘s sequence, and with ; since also delivers a prefix and contains , it delivered before : .
FIFO order. If node TO-broadcasts before , it sends before on its FIFO link to , so receives and FIFO-broadcasts them in this order: , , . Every node that delivers delivers its prefix, which contains earlier.
Integrity follows from integrity of the FIFO broadcast and of the links, provided broadcasts each request once.
Validity and agreement when is correct. A correct node’s request reaches (reliable link), FIFO-broadcasts it, and validity of FIFO broadcast (sender correct) makes every correct node deliver it. Agreement is inherited from the agreement of FIFO broadcast.
When crashes, only ever FIFO-broadcasts messages, so no new message enters any delivery sequence.
Try it: step through the run (the figure below lets A act as sequencer; here the sequencer is a separate node L, and nothing else changes). B and C send requests x and y; check that every node delivers them in L’s numbering, even A, which receives x first and must hold it. Then L crashes and A sends z: nothing more is delivered anywhere.
ABCsequencerx1:x1:x1:xy2:y2:y2:yA crasheszz is never ordered: no deliveries until a new sequencerFigure 2.4. Total order through a sequencer (lecture 04.05, Kleppmann slide 86). Requests go to A, which numbers them and FIFO-broadcasts them; every node delivers 1:x then 2:y. After A crashes, nothing more is delivered.
Lecture 04.05 calls this the approach preferred in industry, and it is the shape of every leader-based system later in these notes. Its weakness is availability: after the leader crashes nothing is delivered (Figure 2.4). The obvious repair, “detect the crash and pick a new leader”, is where all the difficulty hides. A slow leader looks exactly like a crashed one, so two nodes may both act as sequencer and number messages differently; and the new leader must learn which messages the old one had already numbered and to whom. The lecture admits that changing the leader “safely while broadcasts are going on” is technically difficult and defers it; Raft and Paxos are the answer (Module 4 and onward).
Lamport timestamps
The leaderless alternative orders messages by Lamport timestamp. Each message gets a key : the sender’s Lamport clock value and the sender’s id , compared lexicographically, so keys are unique and totally ordered. Every node delivers messages in increasing key order. The difficulty, in Kleppmann’s words: how do you know that you have seen all messages with a smaller key?
// total order broadcast with Lamport timestamps at node i (slide 86)// assumes reliable FIFO links between all pairs of nodes, including i to ion initialisation: t := 0 buffer := {} latest[q] := (0, q) for every node q // largest key received from qon request to broadcast m: t := t + 1 send (t, i, m) to every node, including ion receive (t', j, m) from node j: // m = none for a heartbeat t := max(t, t') latest[j] := (t', j) if m != none: buffer := buffer + {(t', j, m)} while buffer is not empty: (T, k, m') := entry of buffer with the smallest key (T, k) if latest[q] >= (T, k) for every node q: deliver m' to the application buffer := buffer - {(T, k, m')} else: break // a smaller key may still comeon timeout (nothing sent for a while): t := t + 1 send (t, i, none) to every node // heartbeat: "nothing below t"
Line
Role
t := t + 1 before every send
each node’s keys strictly increase, so a FIFO link carries keys in increasing order
latest[q] >= (T, k) for all
nothing with a smaller key can still arrive from
heartbeat
a node with nothing to say must still let the others advance
Theorem 2.16 (Lamport timestamps give FIFO-total order without crashes).
Assume reliable FIFO links. Every execution of this algorithm satisfies integrity, total order and FIFO order: every node delivers messages in increasing order of key, without gaps. If no node crashes and every node sends heartbeats, every message is eventually delivered by every node. If one node crashes, deliveries stop at every node as soon as their smallest buffered key exceeds the last key received from the crashed node.
Proof
Keys per sender increase. Node increments before each send, so its keys strictly increase in sending order, and FIFO links deliver them to every node in that order.
Main claim: when node delivers a message with key , it has already delivered every message with a smaller key. Let be a message with key , sent by . At the delivery of , , so has received from a message with key at least ; since sent earlier (smaller key) and the link is FIFO, received before that. So entered ‘s buffer. If were still there, the buffer’s smallest key would be at most and the loop would not have picked . So was delivered before.
Consequences. At node deliveries happen in increasing key order (a later delivery with a smaller key would contradict the claim at the earlier one), and the delivered set is downward closed. So each node’s delivery sequence is a prefix of the single sequence of all messages sorted by key. Total order follows as in Theorem 2.15. If then , and any that delivers delivered every smaller key before it. FIFO order follows because one sender’s keys increase in broadcast order. Integrity holds because each message is sent once per link and removed from the buffer on delivery.
Liveness without crashes. Let with key be in ‘s buffer. Every node eventually sends a message or heartbeat with key above (its clock only grows and heartbeats keep coming), so eventually for all . Messages with smaller keys are finitely many (keys are pairs of natural numbers and node ids), and by induction on their position they are delivered first; then is the smallest buffered key and the condition holds.
Blocking after a crash. If crashes, stops at some key . A buffered message with key above never satisfies the condition, and since deliveries go in key order, nothing after it is delivered either.
Lecture clarification: why "dense timestamps"?
Lecture 04.05 says this approach “only works if you have very dense timestamps”, like 11, 12, 13, so that a receiver that holds 11 and 12 and then sees 14 knows that 13 is missing and waits for it. The underlying point is right: a node may deliver key only when it is certain that no smaller key is still on its way. But Lamport timestamps are not dense across nodes (two nodes can both be at 12, and a node’s clock can jump from 3 to 40 on receipt), so “detect the gap” cannot work by looking at the numbers. The working rule is the one on Kleppmann’s slide 86 and in the pseudocode: use FIFO links, and wait until every node has sent something with a larger key. Per sender, the keys then behave like the dense sequence numbers of FIFO broadcast.
Exam trap: "Lamport timestamps solve total order, so we do not need consensus"
Both algorithms of this section are correct only as long as nobody crashes (Lamport) or the leader does not crash (sequencer). Kleppmann’s verdict on slide 86: neither is fault tolerant, because the crash of a single node stops every other node from delivering. Waiting longer does not help: in an asynchronous system a crashed node and a slow one are indistinguishable. Fault-tolerant total order broadcast is equivalent to consensus (4), and consensus is the subject of Modules 4-9.
Summary: which algorithm gives what
Algorithm
Guarantee
Messages per broadcast
Survives crashes?
direct send over reliable links
best-effort
not if the sender crashes mid-way
eager reliable broadcast
reliable
yes, any number
gossip, fanout
reliable w.h.p.
about per informed node per round
yes, probabilistic
FIFO algorithm over RB
FIFO
RB cost, plus one counter
as the RB layer
causal algorithm over RB
causal
RB cost, plus an -vector
as the RB layer
sequencer
FIFO-total
1 request + one FIFO broadcast
no: the leader is a single point of failure
Lamport timestamps
FIFO-total
per message + heartbeats
no: any crash blocks all
consensus (Raft, Multi-Paxos)
FIFO-total
a majority round per entry
yes, if a majority is up
The last row is the destination. Raft’s leader is a sequencer; what Raft adds is a way to replace the leader that never lets two leaders number messages inconsistently, and a commit rule that only counts an entry as ordered once a majority stores it (Modules 5-7). Multi-Paxos achieves the same with ballots (Modules 8-9).
Worked example: one run through all the layers
We follow one broadcast of node B in a group of three, from the network up, to see every mechanism at once. The execution is the causal one of Figure 2.3; we look only at B’s message .
Application. B’s application calls broadcast for after it has seen .
Causal layer at B. and , so . B hands to reliable broadcast and sets .
Reliable broadcast at B (eager). B gives the tuple the id , puts it in seen, sends it to A and C over reliable links, and delivers it to its own causal layer.
Causal layer at B again. The tuple arrives at B’s buffer; , so B delivers to itself at once and sets .
Reliable links. The copy to C is delayed and retransmitted (TCP); it arrives once.
Reliable broadcast at C. First receipt of id : C relays it to A and B, then hands it to its causal layer. (B and A discard the relayed copies as duplicates.)
Causal layer at C., the check fails, is buffered. When arrives, C delivers and then , as in Example 2.9.
The reliable layer did not care about order, and the causal layer did not care about crashes: the two-layer split of lecture 04.04 in action.
What breaks
Crash-recovery. All the algorithms keep their state (seen, delivered, sendSeq, buffer, Lamport clock) in memory. A node that restarts with empty state reuses sequence numbers (receivers then discard or misorder its new messages) and re-delivers old messages. Recovery needs stable storage or a fresh incarnation id.
Uniform agreement. Eager relaying gives agreement only among correct nodes (Remark 2.3). If a node acts on a message and crashes, the survivors may never see it unless delivery waits for a majority.
Partitions. Reliable, FIFO and causal broadcast simply wait for the partition to heal; gossip may need many rounds afterwards. The total order algorithms block during the partition: the sequencer’s side keeps going, but the other side cannot deliver; the Lamport algorithm blocks everywhere.
Leader failure. The sequencer is a single point of failure; replacing it by timeout alone may create two sequencers. This is the problem that consensus solves.
Byzantine nodes. A lying node can send different messages under one id, forge a deps vector, or (as sequencer) give different numberings to different nodes. None of these algorithms tolerates that.
Why it matters
Reliable, FIFO and causal broadcast are cheap and fully fault tolerant because each node decides alone. Total order is not: both simple algorithms reduce it to “one node decides” or “wait for every node”, and either way one crash stops the system. Module 4 shows that this is no accident: fault-tolerant total order broadcast is equivalent to consensus. Module 5 starts repairing the sequencer with terms and majority votes, Raft (Modules 6-7) turns it into a replicated log, and Paxos (Modules 8-9) does the same with ballots.
Further reading
Kleppmann’s notes, Section 4.3, slides 81-86, for the original pseudocode of every algorithm here (1).
Hadzilacos and Toueg build every broadcast of Module 1 from reliable broadcast in modular steps, including uniform versions, and prove each layer (2).
Demers et al. introduced epidemic (gossip) algorithms for replicated databases and analyse rumour mongering and anti-entropy (3).
Chandra and Toueg show that total order broadcast and consensus are equivalent and solve both with failure detectors (4).
Kleppmann M. Distributed Systems: Lecture Notes [Internet]. University of Cambridge, Computer Science Tripos Part IB; 2021. Available from: https://www.cl.cam.ac.uk/teaching/2122/ConcDisSys/dist-sys-notes.pdf
2.
Hadzilacos V, Toueg S. A Modular Approach to Fault-Tolerant Broadcasts and Related Problems. Cornell University, Technical Report TR94-1425. 1994;
3.
Demers A, Greene D, Hauser C, Irish W, Larson J, Shenker S, et al. Epidemic Algorithms for Replicated Database Maintenance. In: Proceedings of the 6th ACM Symposium on Principles of Distributed Computing (PODC). 1987. p. 1–12.
4.
Chandra TD, Toueg S. Unreliable Failure Detectors for Reliable Distributed Systems. Journal of the ACM. 1996;43(2):225–67.