Imagine you have five database replicas. All of them can handle reads, but only one should handle writes. The question is: which one?
If multiple nodes accept writes simultaneously, you get conflicting data. If no node accepts writes, your system stops. You need exactly one node to take charge, and everyone else needs to agree on who that is.
This is the leader election problem. It sounds simple until you consider network failures, crashed nodes, and the terrifying possibility of two nodes both believing they're in charge.
Getting leader election wrong can cause data corruption, split-brain scenarios, or complete system outages. Getting it right is one of the fundamental challenges in distributed systems.
In this chapter, we'll explore: