In RAFT is it possible to have a majority consensus on a log entry but the entry is not committed?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
In the RAFT consensus algorithm, achieving a majority consensus on a log entry is a crucial step, but it does not always mean the entry is committed immediately. Understanding why this situation can occur requires a detailed look into how RAFT handles log replication, leader election, and commitment of entries.
RAFT Overview
RAFT is a consensus algorithm designed for managing a replicated log across multiple servers. Its primary goal is to ensure system reliability and consistency by ensuring that all changes to the replicated log are agreed upon by a majority of the nodes (servers). RAFT simplifies the management of the replicated log through a leader election mechanism where one server is chosen as the leader, and this leader is responsible for log replication.
Log Replication
In RAFT, the leader accepts client requests, which contain commands to be executed by the replicated state machines. The leader appends these commands as new entries in its log and proceeds to replicate these entries to the follower nodes. The followers append these entries to their logs and send acknowledgements back to the leader.
Commitment of Log Entries
A log entry is only considered committed when the leader has safely replicated the entry on a majority of the nodes (including itself) and a new entry from the same term is committed on the leader's log. This definition ensures that a committed entry is durable and will persist even if the system fails.
Scenarios Where Majority Consensus Does Not Imply Commitment
It is possible to encounter situations where a leader has replicated an entry to a majority of nodes, yet the entry is not immediately committed. This can occur under several scenarios:
- Leader Failure: If a leader crashes immediately after replicating the entry to a majority but before it can commit the entry (including instructing the followers that the entry is committed), the entry is in a state of limbo. When a new leader is elected, it may or may not find this entry in its log, depending on the nodes that acknowledge the entry to the new leader.
- Network Partition: A similar issue can arise due to a network partition. If the leader manages to replicate the entry to a majority of nodes, but then a partition isolates the leader from these nodes, the leader cannot commit the entry. If meanwhile, the isolated segment elects a new leader, this new leader might overwrite this entry.
- Term Change: If a leader replicates the log entry to a majority but loses leadership (another node becomes the leader) before creating a new entry in the current term that gets committed, the original entry remains uncommitted until the new leader deals with it. This could lead to situations where the new leader, upon election, either replicates the old leader's uncommitted entries or, under certain circumstances, overwrites them.
Example
Here's an example to illustrate this situation:
| Term | Leader | Action | Commit Status |
| 1 | Node A | Replicates entry to a majority | Not committed |
| 1 | Node A | Crashes | - |
| 2 | Node B | Elected as leader; Starts new term | - |
| 2 | Node B | May or may not include Node A's last entry in its log | - |
This table shows how an entry that achieved majority can remain in an uncommitted state due to a leader crash and subsequent changes in leadership and term.
Conclusion
The RAFT algorithm's requirement that entries get replicated to a majority to be considered for commitment is a robust way of ensuring consistency and fault tolerance. However, specific conditions related to the timing of leader crashes or network issues can lead to situations where a log entry, despite having majority consensus, remains uncommitted until conditions are stabilized (e.g., a stable leader in the same or higher term commits an entry).
Understanding these nuances is critical for correctly implementing or troubleshooting systems based on RAFT, ensuring that data integrity and consistency are maintained even in failure scenarios.

