Leader Election

Problem

Five instances of a scheduler are running for availability. But exactly one should execute: Generate monthly invoices Otherwise customers could receive five invoices.

Solution — Leader Election

Instances coordinate so one becomes leader.
A → follower
B → LEADER
C → follower
If B disappears, another instance can become leader. For example, instances compete for a Kubernetes Lease: the leader renews it, and another can take over after it expires. An instance that loses the lease must stop leader-only work.
Core idea: leader election selects one coordinator among multiple nodes.