Part 3 of 6 · 1 min read
Why a leader, and what makes a good election
One process with special powers, chosen safely.
Think of a meeting. With no chair, everyone talks over each other. A chair keeps order, and when the chair leaves, the group picks a new one before going on.
The book says some systems need a single process with special powers: the only one allowed to touch a shared resource, or the one that hands out work. The system must elect a leader from among candidates, who stays in charge until it crashes or becomes unavailable. Then the others notice and elect another.
Leader election
Leader election is the process by which a group of processes chooses one of themselves as the leader and chooses another when the leader fails.
Example: five database nodes elect node 3 as the leader for writes. When node 3 crashes, the others elect node 5.
A good election algorithm must have two properties:
- Safety: at most one leader at any time.
- Liveness: an election eventually completes, so the system does not stay leaderless forever.
Safety and liveness
Safety means nothing bad happens (never two leaders). Liveness means something good eventually happens (an election finishes).
Example: a system that never elects anyone is safe but not live. A system that lets two nodes both lead is live but not safe.
Leaders already appeared in Level 4, where replication used a leader for writes. This module is about how that leader is picked and replaced.
Check yourself:
- What is the difference between safety and liveness in an election?
- Which property fails if no leader is ever chosen?