Quorums & Leader Election
Definition
Quorum
- In plain English
- A quorum is the minimum number of copies that must take part in a read or write for it to count.
- Think of it like
- It is like a club rule that a vote only counts if a majority of members are present.
Leader election
- In plain English
- Leader election is how a group of machines picks exactly one to coordinate, and picks a new one if it fails.
- Think of it like
- It is like a team choosing a captain, and a new captain if the old one leaves.
Why it exists
A stock update reaches two copies, but a read asks only the third. The user sees the older stock count.
Overlapping groups help a reader find a completed write. The groups must refer to the same fixed set of replicas.
How it works
N, W and R
- In plain English
- N is the number of copies, W how many must confirm a write, and R how many are asked on a read.
- Think of it like
- Like 5 judges, 3 needed to approve, 3 consulted to check.
Split brain
- In plain English
- Split brain is when two machines both believe they are the leader.
- Think of it like
- Like two captains giving opposite orders.
Lease and fencing token
- In plain English
- A lease is a time-limited right to act as leader, and a fencing token is an increasing number that lets storage reject orders from an old leader.
- Think of it like
- Like a parking permit that expires, stamped with a number so older permits are refused.
- R + W > N makes every successful read group overlap every successful write group.
- For N = 3, W = 2 and R = 2, any two read copies share at least one write copy.
- Overlap alone is not strong consistency: reads must compare versions, and concurrent writes need a consistent ordering rule.
- The examples assume saved acknowledgements, fixed membership, no substitute replicas, and correctly ordered writes.
| Setting | Read requirement for overlap | Main cost |
|---|---|---|
| W = N | R = 1 | Every replica must confirm each write |
| W = 1 | R = N | Every replica must answer each read |
| N = 3, W = 2 | R = 2 | One unavailable replica can be tolerated |
| Majority election | Two of three; three of five | A minority cannot elect a leader |
A client sends version twelve to three replicas; A and B save and acknowledge it while C is unavailable.
Storage accepts token seven, then token eight from the new leader, and rejects a later write from the old leader with token seven.
Examples
Read overlapping stock copies
Inventory uses three replicas with W = 2 and R = 2.
Write saved on: A and B
Possible read groups: A+B, A+C, B+C
Each group includes A or B
Reader compares versions and selects the newest valid valueWith one replica down, the remaining two can complete reads and writes. Fresh stock also needs ordered updates and version selection.
Check and reduce the stock in one atomic operation to prevent overselling. Quorum arithmetic alone does not enforce inventory rules.
The insight
R + W > N provides overlap; the protocol must use it correctly.
Reject a former leader’s commands
Two control servers lose contact and both believe they lead.
Three voting nodes elect a new leader with two votes; command storage accepts token eight and rejects the former leader’s token seven.
Majorities prevent two winners in the same election period. Fencing stops an unaware former leader from issuing commands after replacement.
The insight
Safe leadership requires both election rules and enforced fencing.
Handle a frozen task leader
A task leader holds a ten-second lease and renews it every three seconds.
A pause can stop renewals without stopping the process. After expiry, another leader takes over and receives a higher fencing token.
Safe expiry needs a trusted lease service and careful clock assumptions. Recovery also takes detection and election time, so ten seconds is not a universal bound.
The insight
Lease expiry permits replacement; fencing blocks delayed commands from the old leader.
Trade-offs
Pros
- Continues through minority failures.
- Provides overlapping read and write groups.
- Makes leadership explicit.
Cons
- Coordination adds delay.
- A minority cannot elect a leader.
- Lease timing needs careful assumptions.
Use when
- Replicated data needs coordinated updates.
- A shared resource needs one active coordinator.
Avoid when
- A single node already meets the requirement.
- Acceptable conflicts make coordination unnecessary.
Quick check
Takeaways
- R + W > N guarantees overlap, not a complete consistency protocol.
- Three-node and five-node majorities tolerate one and two unavailable nodes respectively.
- Use storage-enforced fencing to reject a former leader’s commands.