Lattice agreement over UDP
Perfect link, FIFO uniform reliable broadcast and lattice agreement are commonly used in distributed applications. In this project I implemented these algorithms over UDP in C++17. The code is accompanied by a harness that tests them under loss, pauses and crashes.
The code is on GitHub: https://github.com/chutommy/lattice-agreement
Perfect links
UDP loses, duplicates and reorders datagrams. Over it, a message sent to a correct process must be delivered there exactly once.
Perfect point-to-point links
Events
pl.Send(q, m)requestRequests to send message m to process q.
pl.Deliver(p, m)indicationDelivers message m sent by process p.
Properties
If a correct process p sends a message m to a correct process q, then q eventually delivers m.
No message is delivered by a process more than once.
If some process q delivers a message m with sender p, then m was previously sent to q by process p.
Eliminate Duplicates
links numbers messages per destination and acknowledges them one by one, with up to 64 in flight. A message is retransmitted once three later ones are acknowledged (TCP’s fast retransmit), or after a timeout that follows the measured round-trip time and doubles when it expires:
for (uint32_t s = l.base; s < seq; s++) {
Message &m = l.queue[s - l.base];
if (!m.acked && m.at <= acked.at && ++m.later == 3)
transmit(to, s, m, true);
}
FIFO uniform reliable broadcast
If any process delivers a message, every correct process does, given a correct majority. Messages from an origin are delivered in the order it broadcast them.
FIFO-order uniform reliable broadcast
Events
furb.Broadcast(m)requestBroadcasts a message m to all processes.
furb.Deliver(p, m)indicationDelivers a message m broadcast by process p.
Properties
If a correct process p broadcasts a message m, then p eventually delivers m.
No message is delivered more than once.
If a process delivers a message m with sender s, then m was previously broadcast by process s.
If a message m is delivered by some process (whether correct or faulty), then m is eventually delivered by every correct process.
If some process broadcasts message m1 before it broadcasts message m2, then no correct process delivers m2 unless it has already delivered m1.
Broadcast with Sequence Number
broadcast stacks three layers over perfect links: best-effort, majority-ack and sequence numbers. In the middle one, a process relays a message the first time it sees it and delivers it once more than half have relayed it: one of them is correct.
if (!e.relayed) {
e.relayed = true;
beb.broadcast(Bytes(d));
}
if (++e.copies * 2 > n && !e.delivered) {
e.delivered = true;
on_deliver(origin, r.rest);
}
broadcast --fused does it in a single layer over raw UDP. Every copy of a message carries the set of processes known to have it: a receiver adds itself, merges the set with its own and answers. A message is delivered once more than half have it, and resent every 20 ms to those missing until everyone has it.
Lattice agreement
Every process proposes a set and decides a set. The decisions don’t have to be equal, only ordered by inclusion. Unlike consensus, this can be solved in an asynchronous system, as long as a majority of processes is correct.
Lattice agreement
Events
la.Propose(I)requestProposes a set of values I for lattice agreement.
la.Decide(D)indicationOutputs a decided set of values D of lattice agreement.
Properties
If a process p proposes I and decides D, then I ⊆ D, and every value in D was proposed by some process.
If a process decides D and a process decides D', then D ⊆ D' or D' ⊆ D.
Every correct process eventually decides some set.
Proposer-Acceptor Lattice Agreement
An acceptor acknowledges a proposal that contains what it has accepted, and otherwise refuses, sending back the union. Once more than half have answered, the proposer decides if all acknowledged, and otherwise proposes again with everything it was sent. Every input line is a new instance, up to 16 run at once, and decisions come out in instance order:
if ((p.acks + p.nacks) * 2 <= n)
return;
if (p.nacks > 0) {
p.number++;
p.acks = p.nacks = 0;
send_proposal(instance, p);
return;
}
p.decided = true;
while (!proposals.empty() && proposals.front().decided) {
on_decide(proposals.front().value);
proposals.pop_front();
next_decision++;
}
Benchmark
Setup: layered v. single-layer broadcast, on Apple M1 Pro, loopback, values are median of three runs.

- Layered throughput falls with n². Every message crosses every pair of processes.
- From five processes on, the single layer sends four times as many datagrams. Its 20 ms resend fires before the acknowledgements return.
Setup: 5 processes, each dropping fraction of datagrams.

- Up to 0.2, layered broadcast holds (fast retransmit recovers a lost datagram without a timeout).
- Past 0.3, it collapses (timeout doubles on every expiry and the links treat loss as congestion).
- Single layer never waits longer than 20 ms.
| no loss | 20% loss | |
|---|---|---|
links, messages/s | 1,990,000 | 1,240,000 |
broadcast, messages/s | 565,000 | 544,000 |
broadcast --fused, messages/s | 132,000 | 412,000 |
lattice, instances/s | 480 | 649 |