Leader Election

Difficulty
Importance

The problem

Some coordination tasks (assigning work, sequencing writes) are simplest if exactly one node is temporarily in charge — but that leader can crash at any time, and the remaining nodes need a reliable way to agree on a replacement without ending up with two leaders acting simultaneously.

Why now

Consensus algorithms already provided the general mechanism for machines agreeing under failure; leader election is that mechanism applied to one specific, extremely common question — 'who is currently in charge' — making it a direct, practical application rather than a separate theoretical topic.

Mental model

Leader election is consensus with a narrow question: nominate a candidate, get a majority of votes, become leader for a term. The 'majority' requirement is what prevents split-brain — two simultaneous leaders — because two disjoint groups can't both contain a majority of the same cluster at once.

Requires

Related

Used in

Projects

  • Implement a basic leader election among three simulated nodes using a simple majority-vote protocol, including handling a leader crash and re-election
  • Explain, with a diagram, exactly how a network partition could create a split-brain scenario if a majority requirement weren't enforced

Examples

  • A database replica set with one primary and two secondaries elects a new primary automatically if the current primary stops responding
  • Two application instances both believing they're the 'leader' and both writing to the same resource is a split-brain bug caused by insufficient election guarantees

Resources

Mastery checklist