Consensus and coordination: recap and quiz
The module in five sentences
Section titled “The module in five sentences”- Quorums. A write that needs W acknowledgements and a read that needs R replies share a replica when R + W > N, and W above half of N keeps two sides of a partition from both writing.
- Consensus and leader election. Nodes agree on a leader by majority vote in numbered terms, started by a follower that hears no heartbeat within the election timeout, and the time without a leader is about that timeout.
- Leases and fencing tokens. A leader that pauses past its lease can wake up and write after a new one is elected, and only a storage that refuses older tokens stops the write.
- Distributed locks and coordination services. A safe lock is a lease plus a token, a lock for efficiency can be approximate and a lock for correctness cannot, and coordination services stop serving on the minority side.
- Two-phase commit. A coordinator that fails after every participant has voted yes leaves them unable to decide while they hold their locks, and a consensus group in place of the coordinator removes the stall.
How each one breaks
Section titled “How each one breaks”| Idea | What breaks | What you see | What helps |
|---|---|---|---|
| Quorums | R + W is not more than N, or W is at most half of N | Stale reads from a small side, or two sides that both write | R + W > N and W above half of N |
| Elections | The timeout is too short or too long | Needless elections, or a long wait with no leader | A timeout that suits the network, and randomised timeouts |
| Leases | The holder pauses past the lease | An old leader writes after a new one is elected | A token that increases with every grant |
| Locks | A lock for correctness without a token | Corrupted state that nobody was told about | A consensus-backed service and a token check at the storage |
| Two-phase commit | The coordinator fails after the votes | Participants wait and hold locks | A consensus group as coordinator, or no distributed transaction |
A checklist for using agreement between nodes
Section titled “A checklist for using agreement between nodes”Each question points to the lesson that answers it.
- What must the nodes agree on? A value, a leader, or an outcome. If one node can decide alone, do not use consensus. (Consensus and leader election)
- What happens on the minority side of a partition? Decide whether it refuses requests or serves stale ones, before the partition. (Quorums)
- Is R + W more than N, and is W above half of N? They guard different things. (Quorums)
- How long is the election timeout, and what does it cost in both directions? Measure the delays of your own network and processes. (Consensus and leader election)
- What happens when a leader pauses and wakes up? If the answer is that it writes, you need a token. (Leases and fencing tokens)
- Does the storage compare tokens? A token that nobody checks protects nothing. (Leases and fencing tokens)
- Is this lock for efficiency or for correctness? Only the second needs a consensus-backed service. (Distributed locks)
- Is the transaction spread over several databases, and who holds the decision? Know what a failed coordinator leaves locked, or keep the data together. (Two-phase commit)
- Did you run the failure? The labs and the failure labs are there to be broken.
Check your understanding
Section titled “Check your understanding”Seven questions cover the whole module. Every option is explained, whether it is right or wrong.
Consensus and coordination: module quiz
This quiz needs JavaScript to check your answers.
Where this goes next
Section titled “Where this goes next”This module showed how nodes agree and what it costs when they cannot. The next modules turn to asynchronous systems, where work travels through queues and streams, and where the same questions come back in another form: what happens when a message is delivered twice, and who decides which copy counts.
Your progress
Built by GhaziAlibi.
© ShardCraft. All rights reserved.