Leader election is how a group of equally capable nodes agrees on which single one of them gets to make decisions, coordinate work, or accept writes for some period of time. It shows up anywhere multiple replicas exist but only one should act at once, such as a primary database replica, a controller instance in an orchestrator, or a partition leader in a messaging system. The mechanism matters because getting it wrong doesn't fail loudly; it fails as split brain, where two nodes both believe they're in charge and both proceed to act on that belief.
How it works
At a high level, every leader election protocol answers the same three questions:
- How does a node become leader? Usually by getting a majority of votes from other nodes, or by successfully acquiring a lease in a shared, strongly consistent store.
- How long does leadership last? Leadership is time-bounded, a lease with a TTL, and must be actively renewed with a heartbeat. It is never permanent.
- What happens when the leader disappears? After a timeout with no heartbeat, the remaining nodes hold a new election and a new leader takes over.
Node A, B, C — all start as followers
A times out waiting for a leader → becomes candidate → requests votes
B and C vote for A (haven't voted this term, A's log is current)
A gets majority (2 of 3) → becomes leader → sends heartbeats
--- A crashes ---
B times out waiting for A's heartbeat → becomes candidate → requests votes
C votes for B → B becomes new leader
This is essentially Raft's leader election in miniature. See Raft vs Paxos for how the two major consensus algorithms differ on this exact mechanism.
Common approaches
| Approach |
How it decides |
Used by |
| Consensus-based (Raft) |
Majority vote among nodes, term numbers prevent stale leaders |
etcd, Consul, CockroachDB |
| Lease in a strongly consistent store |
First to write a key with a TTL becomes leader |
Kubernetes controller-manager and scheduler (via etcd) |
| ZooKeeper ephemeral sequential nodes |
Lowest sequence number among live sessions is leader |
Older Kafka versions, HBase |
| Bully algorithm |
Highest ID node that responds wins |
Older or simpler academic systems, rarely used raw in production now |
Almost all production systems in 2026 delegate this problem to etcd, ZooKeeper, or Consul rather than implementing it directly. These systems have already solved the hard edge cases around network partitions, clock drift, and delayed messages using a proven consensus algorithm underneath.
How to approach it in your own system
- Do you actually need a single leader, or just mutual exclusion for one operation? If it's the latter, a distributed lock with a short lease is simpler than full leader election.
- Do you have a consensus store already available, such as etcd, ZooKeeper, or Consul? Use its leader-election primitive rather than building one; this is a solved problem with subtle correctness edge cases.
- Can your system tolerate a brief period with no leader during failover? Most can, and should design for it. A short gap with no leader is far safer than a window with two.
- What does the leader actually do while elected? Keep its responsibilities narrow, such as assigning work or sequencing writes, so failover impact is small and re-election is cheap.
Common mistakes
Building election on heartbeats and timeouts alone, without consensus underneath. Heartbeat-based failure detection is necessary but not sufficient. Without a quorum-based agreement on who won, a network partition can let two sides each elect their own leader.
Treating leadership as permanent once granted. Every real implementation uses a bounded lease that must be renewed; a leader that stops renewing must lose leadership automatically, not just eventually when someone notices.
Ignoring term or epoch numbers. A message from an old leader that resurfaces after a partition heals must be recognizable as stale. Term numbers, as in Raft, let followers reject commands from a leader that has since been superseded.
Assuming failover is instant and free. Re-election takes time, typically hundreds of milliseconds to a few seconds, and the system is leaderless during that window. Design callers to retry, not to assume a leader always exists.
FAQ
Is leader election the same as a distributed lock?
Related but not identical. A lock is usually acquired briefly for one operation; leader election establishes a longer-lived single coordinator. See distributed locks explained for the narrower mechanism.
What happens if two nodes both think they're the leader?
That's split brain, and it's the scenario every serious election protocol is designed to prevent using term numbers and majority quorums. A stale leader's writes get rejected once followers recognize a newer term exists.
Should I implement leader election myself?
Generally no. Use etcd, ZooKeeper, or Consul's built-in primitive. The edge cases around partitions and timing are exactly what consensus algorithms exist to solve correctly.
Does every distributed system need leader election?
No, only systems where some operation must be single-writer or single-coordinator at a time. Fully peer-to-peer or conflict-free systems avoid the need entirely.
Where to go next