TL;DR
Atomic broadcast is a way for a group of machines to send each other messages so that every working machine receives the same messages and handles them in the same order. It solves the problem that machines which each apply updates in their own order drift apart, even when every update arrives. Because it is the basis of replicated state machines, it is how a group of computers can act as one reliable service.
Builds on: Distributed Consensus, State Machine Replication, Quorum · Leads to: ZooKeeper, replicated logs in databases and configuration services
Where it's used
Configuration services. A cluster of five servers holds the settings that every other service reads, such as which database address to use or which feature flags are on. A change must reach all five in the same order, or two servers will answer the same question differently. Systems in this family, such as ZooKeeper and etcd, run a log that works like an atomic broadcast channel.
Replicated databases. A database that keeps three copies of its data must apply the same transactions in the same order on each copy. If copy 1 applies "withdraw 50" then "deposit 20", while copy 2 applies the deposit first, a balance that was never enough can be rejected on one copy and accepted on the other. Atomic broadcast gives every copy the same transaction order.
Coordinating a group of workers. A set of job runners must agree on which runner owns which job. Each claim is broadcast, and the first claim in the shared order wins. Every runner reaches the same answer without asking a central boss, and without two runners both claiming the same job.
How it works
Take one tiny instance. A leader L and two followers F1 and F2 form a group of three. A client asks the group to append two items, "x" and then "y". The goal is that all three machines deliver x and y in the same order.
- Client sends an item to the leader. The client sends "x" to L. L is the only machine that gives items positions. Check: at this moment no follower has seen x.
- Leader assigns a position. L gives x position 1, and then gives the next item position 2. Positions never repeat and never change. Check: x has position 1, and y will have position 2.
- Leader copies the entry to the followers. L sends "position 1: x" to F1 and F2. Check: each follower now holds one new entry, and none of them has delivered it yet.
- Majority commits the entry. L counts itself plus F1, which acknowledged. That is 2 out of 3 machines. Three machines make a majority of 2, so position 1 is committed. Check: 2 is at least 3 divided by 2, rounded down, plus 1, which is 2.
- Machines deliver in position order. L delivers x. The followers deliver x as soon as they know position 1 is committed. A machine never delivers position 2 before position 1. Check: every machine's delivery list starts with x.
sequenceDiagram participant C as Client participant L as Leader participant F1 as Follower 1 participant F2 as Follower 2 C->>L: append x L->>L: assign position 1 L->>F1: position 1 = x L->>F2: position 1 = x F1-->>L: ack position 1 L->>L: 2 of 3, commit position 1 L->>L: deliver x
The idea to keep is the separation of two jobs. The leader gives positions, and a majority makes each position permanent. Once a position is permanent, every machine delivers items in position order. The whole service is built on this order rule.
The math
Let machines take part, and let at most of them crash. A broadcast of a message is an operation broadcast(m), and the event of a machine handing to its application is deliver(m). Atomic broadcast requires four properties for every pair of messages and every pair of correct machines.
A protocol is an atomic broadcast if it satisfies these four properties for all correct machines:
- Validity. If a correct machine broadcasts , it eventually delivers .
- Agreement. If a correct machine delivers , every correct machine eventually delivers .
- Integrity. A machine delivers at most once, and only if someone broadcast .
- Total order. If two correct machines both deliver and , they deliver them in the same order.
Agreement and integrity say that all working machines receive the same set of messages. Total order says they receive that set in the same sequence. The first three are the job of a reliable broadcast. The fourth is what makes the broadcast atomic.
Step 1 in symbols
The leader gives each item a position , a whole number starting at . The position is the index of the item in the log, written and . Positions are fixed once assigned, so two machines that both know agree that comes first.
Step 3 in symbols
A position is committed when the number of machines that hold the entry is at least a majority. For machines the majority size is
For the example, and . A quorum of size is the group that must hold an entry before it counts, as described in Quorum.
Two majorities always share at least one machine. This is why a committed entry survives a leader change: any new leader must contact a majority, and that majority includes a machine that knows the committed entry.
Step 4 in symbols
Let be the list of items a machine has delivered, in order. The rule is that grows by position: receives the item at position only after it has received the items at positions to . In symbols, for some . Total order follows, because committed positions are the same everywhere.
How many crashes can it survive
With machines, the majority is . Up to machines can crash, and then machines remain, which is still a majority. So five machines tolerate two crashes, and seven tolerate three.
Worked examples
Messages and are broadcast. Three machines X, Y and Z receive them in these network orders:
- X sees , then .
- Y sees , then .
- Z sees , then .
- X and Z agree on the order .
- Y has the order .
- X and Y both deliver and , but in opposite orders. This breaks total order.
- Now add a sequencer that gives position 1 and position 2. Y receives first. It has position 2 but not position 1, so it holds back.
- Y then receives with position 1, delivers , and then delivers .
Interpretation: positions turn an arrival order, which differs per machine, into one delivery order. The holding back in step 4 is the key rule.
A group has five machines, so and the majority is . The leader sends position 9 to four followers. Acknowledgements arrive in this order:
- The leader counts itself. Count: 1.
- Follower F1 acknowledges. Count: 2. Two is below 3, so position 9 is not committed.
- Follower F2 acknowledges. Count: 3. Three is at least 3, so position 9 is committed.
- Follower F3 acknowledges later. Count: 4. The decision does not change, because position 9 was already committed.
- Follower F4 never answers, because it has crashed. The group still works, since it needed only three.
Interpretation: the leader waits for the third acknowledgement, not for all five. The slowest or crashed machines do not hold up the group, which is why a group of five tolerates two failures.
Two operators change the same flag at the same moment. Operator A sends "flag = on" and operator B sends "flag = off". The leader gives "on" position 7 and "off" position 8. Each replica starts with the flag off.
- Every replica delivers position 7 first, so the flag becomes on.
- Every replica then delivers position 8, so the flag becomes off.
- All five replicas end with the flag off. Their delivery lists are identical: on, then off.
- Suppose instead the network let some replicas see "off" first. Replicas R1 and R2 end on, while R3, R4 and R5 end off. Now a request for the flag gets different answers depending on which replica it reaches.
- Atomic broadcast rules out step 4, because every replica has to deliver the same sequence.
- Try it: replica R4 has delivered positions 1 to 8. Position 9 is "flag = on", and it has not yet been delivered. What value does R4 report? Answer: off. R4 has delivered position 8, which set the flag off, and it must not act on position 9 until it has been delivered in order.
Interpretation: a single shared order is the entire guarantee. The flag's final value is not decided by which message was sent last in real time. It is decided by the position the group agreed on.
Common mistakes and tradeoffs
It is tempting to think that reliable broadcast already gives total order. In fact it gives agreement on the set of messages but not on their order. Gossip, described in Gossip Protocol, spreads each message to every machine, yet two machines may receive and in different orders, because each one hears from different peers at different times.
It is tempting to think that timestamps solve the problem. Lamport timestamps can be sorted into a total order by breaking ties with machine IDs, and happened-before is only a partial order that says nothing about concurrent messages. Even with timestamps, in an asynchronous network a receiver cannot deliver a message until it knows no earlier message is still on its way. If one sender is silent, the receiver must wait, and a crashed sender can make it wait forever. Atomic broadcast needs an agreement step that a timestamp alone cannot supply.
It is tempting to think a leader makes the problem trivial. A leader gives order, but when it crashes, the group must elect a new one, as in Leader Election, and must not lose or reorder an entry that was already committed. This is where the consensus problem in Distributed Consensus comes back in.
Atomic broadcast is not free. Every delivery waits for a majority round trip, so the latency is at least one trip from the leader to a majority and back.
When to use it: when many machines must apply the same updates in the same order, such as configuration, locks, or the transactions of a replicated database.
When not to use it: when messages only need a weaker order. A stream of sensor readings, or a chat where messages from one sender must stay in order, can use FIFO or causal broadcast, which are cheaper. The table below sets the options side by side.
| Guarantee | Same set everywhere | Same order everywhere | Typical cost |
|---|---|---|---|
| Reliable broadcast (gossip) | yes | no | low |
| Causal broadcast | yes | causally related messages only | medium |
| Atomic broadcast | yes | yes | high, needs a majority |
History
In 1978 Leslie Lamport showed that events in a distributed system can be partly ordered by the messages that connect them, and that clocks can give a consistent view of that order. His paper defined the happened-before relation and raised the question of how to make a total order that all machines agree on.
In the late 1980s the ISIS toolkit used broadcast protocols with ordering guarantees to make groups of processes behave as a single service. People used these tools in trading and control systems, and they learned how hard the failure cases were.
In the mid-1990s Tushar Chandra and Sam Toueg showed that, in an asynchronous system with unreliable failure detectors, atomic broadcast and consensus solve the same problem. Each can be built from the other. This is why the two ideas appear together in the literature.
Leslie Lamport's Paxos algorithm, written in 1989 and published in 1998, gave a practical way to reach that agreement. Later work used Paxos-like logs to build replicated services. The ZooKeeper coordination service, described in a 2010 paper, uses its own broadcast protocol, Zab. The Raft algorithm, published in 2014, was designed to be easier to explain and implement, and it made the leader-based log common in practice.
Recap
- A group needs one shared order, not just a shared set of messages. That is the difference between reliable broadcast and atomic broadcast.
- A leader assigns positions, and a majority makes each position permanent.
- Delivery follows position order, so a machine that sees position 2 early waits for position 1.
- With machines, a majority of survives crashes.
- Atomic broadcast is the channel behind State Machine Replication. Read the ZooKeeper paper to see it used as a coordination service, and Paxos for one way to reach agreement on each position.
Check yourself
QuestionIn your own words, what is the total order property, and why does reliable broadcast not give it?Show answer
Total order says that any two correct machines that both deliver two messages deliver them in the same sequence. Reliable broadcast only promises that every correct machine receives the same set of messages. Messages can arrive at different machines in different orders, so sets can agree while sequences do not.
QuestionA group has seven machines. What is the majority size, and how many crashes can the group survive while still committing new entries?Show answer
The majority is . With and , the number of machines left after three crashes is , which is still a majority. A fourth crash leaves three machines, which is below 4, so the group stops committing. The answer is three crashes.
QuestionWhy must a machine hold back position 2 until it has delivered position 1, even when position 2 has already been committed?Show answer
Delivery order is what makes the states match. If machines could deliver committed entries in whatever order they reached them, one machine could apply position 2 before position 1 while another applied them in order. Their states would then diverge, and total order would fail. Holding back keeps the delivery list equal to a prefix of the one shared log.
QuestionA team says that because their messages carry timestamps, they do not need atomic broadcast. A sender goes silent after sending a message with timestamp 10. What goes wrong?Show answer
A receiver that holds a message with timestamp 12 from a second sender cannot tell whether the silent sender has a message with timestamp 11 still in transit, or has nothing more to send. Delivering 12 now could put it ahead of 11. The receiver must wait, and if the sender crashed, it waits forever. Atomic broadcast avoids this by having a majority agree on each position, so no receiver needs to guess about silent senders.
Sources
- Consensus (computer science), Wikipedia: https://en.wikipedia.org/wiki/Consensus_(computer_science)
- Paxos (computer science), Wikipedia: https://en.wikipedia.org/wiki/Paxos_(computer_science)
- Ongaro and Ousterhout, In Search of an Understandable Consensus Algorithm: https://raft.github.io/raft.pdf