pattern
Leader Election
The process by which a group of nodes agrees which one of them is currently in charge of a task that must not run twice.
Needed whenever exactly one node may act — running a scheduled job, accepting writes for a shard, compacting a log. Implemented on top of a consensus system (Raft, Paxos) or a coordination service (ZooKeeper, etcd, Consul), never by hand.
The trap is the assumption that there is ever exactly one leader. Under a partition, an old leader may not yet know it has been deposed, and for a window there are two. Correct designs do not rely on the count; they rely on fencing tokens — a monotonically increasing number issued with leadership, which the downstream resource checks and uses to reject writes from a stale leader.