2026-11-02·par Sijie Wang#fundamentals#distributed#consensus#cap

leader-election-pattern

The leader-election pattern: same cast, everywhere

Leader, follower, candidate, term, heartbeat, election — the same cast appears far beyond raft: MongoDB replica sets (which use the word term outright), Redis Sentinel (an epoch counter, majority vote among sentinels), Kafka (a leader per partition, and a leader epoch added specifically to retire resurrected leaders), PostgreSQL HA under Patroni (the primary holds a lease in a consensus store; renewing the lease is the heartbeat), Kubernetes controllers (a Lease object, renewed by the one active replica), and router VRRP decades before all of them.

The recurrence is forced, not fashion. Three ingredients, once combined, admit essentially one shape of solution:

  1. Replicas exist, but exactly one may act. Two acting at once is split-brain: divergent writes, two truths.
  2. The actor can fail silently, and "dead" is indistinguishable from "slow" or "cut off". There will be no death announcement, so the actor must continuously prove it is alive — the heartbeat (or its twin, a renewed lease). Silence past a deadline is treated as death.
  3. A declared-dead leader may come back. So every command carries a monotonically increasing generation number — term or epoch — and anything stamped with an old generation is ignored. Zombie orders expire by construction.

Wherever redundancy, a single actor, and silent failure meet — databases, queues, coordination services, routers, game-session hosts — this cast is re-derived. Recognizing the three ingredients in a new system predicts its failover machinery before reading a line of its docs.

CAP position of this family. Consensus systems of this kind are the canonical CP example (see cap-theorem): partition is not a choice, so the question is what is sacrificed while it lasts. The majority side elects a leader and keeps serving; the minority side can neither elect nor commit, so it refuses rather than risk a second truth. Availability is sacrificed on the minority side only, and consistency never. The mirror family — multi-master stores like Cassandra or Dynamo-style systems — takes the AP side: both sides keep accepting writes during a partition and reconcile afterwards.

read next
à propos de cette entrée

L'une des entrées de wiki de sijie. L'IA sur ce site est fondée sur le même corpus et répond à la voix de sijie, avec citations revenant à des entrées comme celle-ci — répondre coûte argent à sijie, donc cela attend derrière un code : entrer un code d'accès →

leader-election-pattern — Sijie Wang