Detailed Lecture Notes
In this section we will continue to explore the more nuanced interactions in Raft. We will elaborate on the implementation of AppendEntries for receivers, explore what can happen when partitions in the network occur, and finally understand why having a log entry exist on a majority of servers is not one-to-one with it being eventually committed.
We must consider: is it possible that two entries, at the same index, across different logs, may conflict (represent different operations)? If so, what is our plan to reconcile this inconsistency?
If we investigate, we will see that yes– it is possible for two log entries at the same index to conflict, as they may come from different terms!
However, it will only be possible for at most one of these log entries to be committed at that index. Then, we must have a mechanism within Raft to reconcile these inconsistent log entries.
Consider that server 2 and server 3 have conflicting log entries for index 3. We can have conflicting log entries, for example, if server 2 was leader, but failed before sending appendEntries regarding the index 3 log entry. Notice that, at this point, neither log entry in index 3 is committed.
Now, the implementation of the receivers logic for AppendEntries adds the following logic:
The effect of rules 3 and 4, enforce that followers will delete conflicting log entries and eventually update their logs to match the leaders. This behavior works well with the fact that leaders are guaranteed to have all committed log entries in Raft. We are free to delete and discard uncommitted log entries, as clients do not expect that these entries are replicated or successful at this point.
###
Is it possible for there to be two servers who believe they are leaders simultaneously in Raft? Surprisingly, the answer is yes, however, not for the same term.
Consider the following interaction:

Notice that servers A and E will remain connected, happily sending heartbeat appendEntries back and forth, never triggering a new election.
However, B, D and E, fail to receive heartbeats, and as such, they start an election. When an election succeeds, we will elect a new leader in this majority partition (3 servers is enough to elect).
So, at this point in time, we have two leaders (the old one who believes it is term 1 and the new one who knows about term 2). However, is this a problem?

Notice that the old leader from term 1 cannot commit any entries. Thus we will not have a diverging application state. Though Raft allows for two leaders to exist at one time, only one leader, at most, will be able to commit.
When the partition heals, the A and E will be brought up to date and receive the entries they missed.
A troubling question in Raft is: can we be sure an entry will be committed if it exists on a majority of servers? Our intuition may say yes, however, as we have learned, there is a mechanism for catching up followers, and we need to add an additional rule to guarantee the safety of Raft’s committed entries.
Up until this point, our understanding of updating commitIndex has been:
commitIndex.However, if we reference the Raft paper, there is an additional caveat in the leader’s logic for updating commitIndex:
If there exists an N such that N > commitIndex, a majority of matchIndex[i] ≥ N, and log[N].term == currentTerm: set commitIndex = N.
This bolded portion of the rule describes that we may only update commitIndex in this way such that our for new commitIndex, N, log[N].term == currentTerm. In other words, we may only update commitIndex to a log entry from the current term.
Why do we need this additional rule? The intuition can be highlighted in the following interaction:

In the above image, we have server A who is currently the leader. Consider that A,D,E must have been the group of servers to elect A (because B and C have entries from 2, they would not have thought A was up to date). But 3 servers is enough for a majority– thus A can be elected.
Then, consider that A may be disconnected from the cluster before propagating the entry from term 3. Now, who may be elected? B or C (as they can get votes from E,D). Say server B is elected for term 4. Now, B goes about sending AppendEntries rpcs to update E and D. Once the [2 2] log entries have been propagated (as in the second picture) can we update commitIndex to 4?
No! (The currentTerm == 4 which does not equal 2). But why would it be dangerous to commit these entries? Let’s see:

In the above example, B is disconnected from the group, and A is elected leader again. Notice that log [1 1 3] is more up-to-date than [1 1 2 2], by the rule regarding the term of the last index. Once A is elected leader, it will propagate AppendEntries to bring followers to match it’s log. Notice that the previous [2 2] log entries are overwritten.
However, notice that we only commit for example, entry 3 in term 5, once a preceding log entry from term 5 is committed.
See Figure 8 in the raft paper for an additional example of the above interaction.
follower stateInstallSnapshot, which catches up followers via a saved snapshot, as perhaps they may have missed committed log entries in the snapshot and now need to be caught up via the snapshotted state itself.