A leader is partitioned from its followers. Monitoring promotes a follower after 10 seconds. Then the old leader's network heals while some clients still talk to it. What goes wrong, and how do you prevent it?
Sketch your own answer first, then compare it with the one below.
A strong answer
Now two nodes accept writes, each believing it is the leader. Clients that reached the old leader and clients that reached the new one write different values for the same keys. The followers receive two histories. Without a rule, the data diverges, and some of the writes the old leader acknowledged during the gap will have to be thrown away or merged by hand. This is split brain.
The root problem is that the old leader cannot tell it has been replaced. A node cannot be sure from the inside whether a silence means its peers are down or it is cut off.
Prevention has layers. Give every leadership term a number, an epoch, and make followers and storage refuse writes from a lower number than the highest they have seen. This is fencing, and it turns the old leader's late writes into rejected requests rather than corruption. Have the old leader stop on its own: if it cannot reach a majority, or cannot renew its lease, it steps down and stops accepting writes. Choose the promotion timeout knowing the trade: too short and a slow leader triggers a needless failover, too long and writes are down for longer. Finally, decide beforehand what happens to the old leader's unreplicated writes when it rejoins, since they conflict with the new history.
The robust form of all this is a consensus protocol, which settles who the leader is by majority vote and is covered in a later module.
Sources
- Martin Kleppmann (2016). How to do distributed locking.
- Martin Kleppmann (2017). Designing Data-Intensive Applications.