Raft Leader Election
System Design

Raft Leader Election

Subtitle: How a cluster agrees on exactly one leader

THREE NODE STATES:

FOLLOWER - waits for heartbeats from the leader CANDIDATE - asks peers for votes LEADER - sends heartbeats, appends log

RULES THAT KEEP IT SAFE:

Randomized timeouts prevent tied votes One vote per node per term A majority is a quorum, not all nodes Higher term wins, old leader steps down

COMMON BEGINNER MISTAKE:

Assuming any node can just declare itself leader. Without a majority and a rising term, two nodes both believe they lead - and you get split brain.