how raft follower rejoin after network disconnected?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
In the context of distributed systems, the Raft consensus algorithm plays a crucial role in ensuring data consistency and integrity across multiple nodes or servers. It addresses some of the common issues around achieving consensus in a network, especially when some parts of the network are unreliable or experience failures. Network disconnections can cause a node, often referred to as a "follower" in Raft terminology, to lose synchronization with other nodes. When a follower reconnects, it must follow specific procedures to reintegrate with the cluster and reestablish its role within the consensus system. Here's a detailed look at how a follower node rejoins a Raft cluster after a network disconnection.
Reconnecting Process for a Raft Follower
When a follower in a Raft cluster becomes disconnected due to network issues, it stops receiving heartbeat messages from the leader. Without these heartbeats, the follower assumes there may be a problem with the leader or itself and starts a leader election process after its election timeout expires. Here are the steps it follows to rejoin the cluster:
1. Election Timeout and Leader Election
Upon disconnection, the follower will eventually reach its election timeout because it does not receive any communication from the leader. The follower then transitions to a candidate state and increments its current term. It starts a new election by voting for itself and sending out RequestVote RPCs to all other nodes in the cluster.
2. Receiving Response from Other Nodes
If the disconnected node remains isolated (i.e., its network connection is not yet restored), its RequestVote RPCs will fail, and it won't receive any majority of votes. Without a majority, it cannot become the leader. If other nodes can communicate with it again (ascending the node has reconnected), those nodes will respond based on their current term and leader status.
- If their terms are higher than the candidate’s term, the candidate updates its term and reverts to follower status.
- If their terms are equal or lower, and they haven't voted for another node in this term, they might grant their vote to the candidate.
3. Synchronization After Reconnection
Once the disconnection issue is resolved, and the node is back online, if it does not become the leader, it resumes its role as a follower. The leader of the cluster will then bring the follower up-to-date via the following mechanism:
- Log Matching: The leader sends
AppendEntriesRPCs that contain log entries starting from where the follower’s log diverges. If a follower’s log is inconsistent with the leader’s, the follower deletes the conflicting entries in its log and replaces them with the entries from the leader’s log. - Commit Point Update: Once the follower’s log is consistent with the leader's log and new entries are committed by the leader, the follower updates its commit index. This step is crucial as it guarantees the consistency of the replicated logs across all nodes.
Handling Edge Cases
During the reconnection process, a few edge cases need careful handling, such as:
- Network Partition: If the follower is in a minority partition (split-brain scenario), it will not be able to become the leader or affect the ongoing consensus of the majority segment.
- Simultaneous Reconnections: If multiple followers get disconnected and reconnected around the same time, there could be multiple elections triggered, potentially leading to confusion and delays in achieving consensus.
Summary Table on Reconnection Mechanisms
| Step | Action | Purpose |
| Election | Follower becomes a candidate and increments term. | To attempt to re-establish leadership or connectivity. |
| Voting | Request and grant votes. | To determine if the node should become a new leader. |
| Log Matching | Leader sends missing or divergent log entries. | To ensure logs consistency across the cluster. |
| Commit Update | Follower updates its commit index. | To finalize the log synchronization process. |
Conclusion
The reconnection and synchronization of a follower node in Raft after a network disconnect are essential for maintaining the robustness and reliability of the consensus process. By following the designated steps and handling potential edge cases, Raft ensures that each node, irrespective of temporary failures or disconnections, remains an integral part of the cluster’s operability and resilience.
Related reading
- How safe is totally ordered multicasting using logical clocks?
- how sockets or communication channels are maintained in distibuted system
- How to access a Tensorflow docker instance from the outside without Jupyter - for distributed Tensorflow
- How to account for clock offsets in a distributed system?
- How to adapt Fenwick tree to answer range minimum queries
- How to add two numbers without using or or another arithmetic operator
- How to achieve high availability in a Kafka Streams app during deployment?
- How to achieve master- master replication between more than two postgresql databases?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.