Patterns
35 items
35 items
Selecting a single coordinator among distributed nodes
Leader election is a coordination pattern where distributed nodes agree on a single leader to coordinate activities. Only the leader performs certain operations (writes, scheduling, coordination) while followers remain on standby. If the leader fails, remaining nodes elect a new leader. This pattern prevents split-brain scenarios, ensures single-writer semantics, and simplifies distributed coordination. Implementations include Raft consensus, ZooKeeper recipes, and etcd. Leader election is fundamental to databases (primary/replica), message brokers (partition leaders), and orchestration systems (scheduler).
With one leader, no need for distributed consensus on every operation. Leader makes decisions, followers accept. Dramatically simplifies system design.
Must quickly detect leader failure to minimize downtime. But false positives cause unnecessary elections. Balance sensitivity vs stability.
Can never have two leaders simultaneously (split-brain). Use fencing tokens, epoch numbers, or lease expiration to prevent stale leaders.
Problems without leader election:
With leader election: - One node coordinates, others follow - Clear authority for decisions - Automatic failover when leader fails