A new Paxos leader repairs after taking over: it asks a majority what they have accepted and finishes anything that might be chosen [1, § 3]. Raft does that work at election instead. A node votes only for a candidate whose log is at least as up to date as its own, so a winner backed by a majority already holds every committed entry [2, § 5.4.1]. "Up to date" compares the term of each log's last entry before it compares length (§5.4.1 of the Raft paper [2]). Why not just elect whoever has the longest log?
Because the longest log can be the least trustworthy one. Picture a leader that gets partitioned onto the minority side of the cluster. It doesn't know it has lost, so it keeps accepting client writes and growing its log. Meanwhile the majority side elects a new leader and moves on.
That seems to contradict "a write needs a majority." It doesn't, because a write is really two steps:
- Append: the leader writes the entry to its own log and ships it to whichever followers it can reach. No quorum needed.
- Commit: once a majority has the entry, the leader applies it and only then tells the client it succeeded.
So the cut-off leader appends forever and commits never. Its clients time out and retry against the new leader. Its long log is entirely uncommitted. If length decided elections, that log could win when the partition heals and overwrite entries the majority really committed. Comparing last terms first prevents that: to commit anything, the new leader must put an entry from its newer term on a majority, and those nodes refuse any candidate whose log ends in the old term, however long [2, § 5.4.2].