Skip to content
StackDecode
System Design
6. Distributed Systems FundamentalsAnimated

Leader Election

Choosing one node to coordinate.

The idea

Nodes vote or compete so exactly one becomes leader, and a new one is chosen on failure.

Watch it work

Press play, pause, or step through. Some animations have settings you can change.

followerT0 L0followerT0 L0followerT0 L0followerT0 L0followerT0 L0
  • leader
  • candidate
  • follower
  • crashed

Five servers start as followers. Each waits for a heartbeat from a leader; if none arrives before a random timeout, it will stand for election.

1/10

Raft guarantees at most one leader per term and never loses committed entries.

Step by step

  1. 1Detect no leader
  2. 2Candidates request votes
  3. 3A majority picks one
  4. 4The leader sends heartbeats

Where it is used

Databases and coordination.

Watch out for

Two leaders (split brain) must never act at once.

Related