Consensus & Leader Election
Getting a group of machines to agree on one value, so failover cannot produce two primaries.
Your database primary stops answering. Your health checker waits ten seconds, decides it is dead, and promotes a replica.
The primary was not dead. A network link dropped between it and the checker, and it has been happily taking writes from everybody on its side of that link the whole time.
You now have two machines that both believe they are the primary, both accepting writes to the same rows. Nothing has crashed and no error appears anywhere, because every component is doing exactly what you told it to.
When the link comes back you have two versions of the truth and no general way to merge them. Avoiding that afternoon is what consensus is for, and it starts by giving up on the idea that you can reliably tell a dead machine from an unreachable one.
Lessons
4 in this chapter- Split BrainA node that cannot be reached and a node that is dead look exactly the same.3 min
- QuorumsRequire a majority, because two majorities cannot exist at the same time.2 min
- How Raft Elects a LeaderTerms, randomised timeouts, and a majority of votes.3 min
- Using It Without Building ItPut the decision in etcd, keep your data out of it.3 min