Leader Election
ELI5 - The Vibe Check
When you have several identical servers doing the same job, sometimes one of them needs to be in charge, deciding who gets to write, coordinating the others, without a human picking. Leader election is the process those servers use to vote among themselves for a leader, and just as importantly, to notice when that leader disappears and quickly vote in a replacement.
Real Talk
Leader election is a distributed systems process by which nodes in a cluster select a single coordinator to handle tasks that must not be done by multiple nodes at once, such as writing to a resource or scheduling jobs. It is typically implemented using a consensus algorithm like Raft or Paxos, or coordination services like etcd and ZooKeeper, and includes mechanisms to detect leader failure and trigger a new election.
When You'll Hear This
"Patroni handles leader election for our Postgres cluster automatically." / "Split-brain happened because two nodes both thought they'd won the leader election."
Related Terms
Consistent Hashing
Consistent Hashing distributes data across servers so that when you add or remove a server, only a small fraction of data needs to move. Normal hashing?
Failover
Failover is what happens when your primary database keels over and, instead of the whole app going down with it, a standby replica gets promoted to take it...
Raft
Raft is a consensus algorithm designed to be understandable, unlike its predecessor Paxos which requires a PhD to read.
Two-Phase Commit
Two-phase commit (2PC) is like a wedding ceremony for distributed transactions. Phase 1: 'Do you all agree to commit?' Every node says yes or no.