Course contentsShow
← Computer Science
Lesson 2655 of 2,87259. Consensus and ReplicationFree lesson

Leader Election Basics

Explore leader election as a prerequisite for many consensus protocols: choosing one node to coordinate decisions.

Leader Election Basics

What you'll learn: You'll discover why distributed systems choose one node to lead and how that choice enables reliable coordination.

Why Leader Election Matters

Many distributed systems need a single node to make decisions on behalf of others—think of coordinating writes in leader-based replication or driving consensus protocols. But in a dynamic, failure-prone environment, how do multiple nodes agree on who's in charge?

Leader election is the process by which nodes in a distributed system agree on a single coordinator (the "leader") without external help. This prevents chaos: without a leader, different nodes might make conflicting decisions, or everyone might wait for someone else to act.

The Core Challenge

Imagine a classroom where the teacher leaves and students must choose a replacement. If multiple students shout "I'm in charge!" simultaneously, chaos ensues. The group needs a fair, deterministic way to pick exactly one leader—even when some students can't hear each other or some leave the room unexpectedly.

In distributed systems, nodes face similar issues:

  • No global view: Nodes can't see everyone's status simultaneously
  • Failures happen: The current leader might crash mid-coordination
  • Network partitions: Some nodes may be unreachable temporarily

Prerequisites for Consensus

Leader election directly enables protocols like Two-Phase Commit and Three-Phase Commit (which you've already seen). These protocols assume one node coordinates the process—that coordinator must be elected first. Similarly, leader-based replication requires knowing who the leader is before writes can proceed.

A good leader election algorithm ensures:

  • Uniqueness: At most one leader exists at a time
  • Agreement: All reachable nodes recognize the same leader
  • Liveness: A leader is eventually chosen despite failures

Key Takeaway: Leader election solves the "who's in charge?" problem in distributed systems, providing the single coordinator that many consensus and replication protocols require to function correctly.