Home/Labs/Leader Election Arena
All 280 Labs
INTERACTIVE LAB👑

Leader Election Patterns Lab (Interactive)

Bully versus ZooKeeper-style elections, herd versus watch, counted message by message. Crash nodes in an eight-member cluster and compare message cost per election across Bully, ephemeral-sequential ZAB-style election, and the thundering-herd wake-up.

Bully vs ZooKeeper Election Arena

Kill leaders in an 8-node cluster and compare who pays for re-election: every node with O(N) chatter, or one lucky watcher.

ID 1
follower
ID 2
follower
ID 3
follower
ID 4
follower
ID 5
follower
ID 6
follower
ID 7
follower
ID 8
👑 leader
Bully's flapping hazard: if the highest-ID node has a jittery NIC, every timeout makes it restart elections and every recovery makes it steal leadership back — the cluster thrashes. ZK sequential leases sidestep this by making leadership order explicit.
Current leader
node 8
Elections
0
Total messages
0
Election timeline

Crash the 👑 node to trigger a re-election and watch the message accounting.

    Kafka elects its Controller, Kubernetes controllers lease via etcd, and Patroni guards PostgreSQL primaries with exactly these patterns: unique ID bullying is simple but O(N) per election and wake-up hungry; ephemeral sequential nodes turn failover into one delete plus one watch event — which is why 10,000 standby workers can wait behind 1 leader without stampeding.

    How It Works Under the Hood

    Every consensus group needs a leader, and election styles trade chatter against coordination. The Bully algorithm messages every higher-id node and the highest survivor claims victory — simple, O(N) per election, and useless without leases to fence zombie leaders. ZooKeeper instead has every contender create an ephemeral sequential znode and watch its immediate predecessor; lowest sequence wins, and after a crash only one successor wakes, making failover cheap and the ephemeral session itself the health proof. This lab counts messages and wake-ups per election under each scheme so the design difference stops being folklore.

    Core Architectural Principles

    • Bully fans out to every higher node and broadcasts the result — message cost per election counted.
    • Ephemeral-sequential predecessor watch wakes one waiter instead of the whole herd.
    • Lease duration control frames how long a dead leader’s title survives before renegotiation.
    Interview Round Script

    When proposing a coordinator, say which election you delegate and why: “we rely on ZK/etcd ephemeral-sequential watches because hand-rolled Bully needs leases and heartbeat fencing.” Mention split-vote risk with N-of-M pings and prefer delegated elections for anything already storing state there.

    Key Trade-Offs

    Bully is trivial to implement but chatty; watch-based election scales and self-heals but binds you to a coordination service.

    Related Curriculum Chapter

    Leader Election Patterns

    Read Full Chapter Blueprint

    Explore More Interactive Labs

    View All 280 Labs