Try
↑ ↓ move↵ openesc close

Interview prep / Raft and consensus

Mid · Raft and consensus · System design interview question

A node that was down for a while restarts and immediately runs for election. Can it win and lose committed entries? What stops that?

Sketch your own answer first, then compare it with the one below.

A strong answer

It can run, but it should not win if its log is behind. A voter grants its vote only to a candidate whose log is at least as up to date as the voter's own. Up to date is decided by the term of the last entry first, and then by the length. Since a committed entry is on a majority, and the candidate needs a majority of votes, at least one voter has the entry and will refuse a candidate that lacks it.

So the stale node loses, adopts the higher term from the responses, and becomes a follower. The leader then repairs its log by stepping back through the follower's entries until the two agree and sending everything after that point.

Restarts matter here too. Raft persists the term, the vote and the log before responding to any message, so a restarted node cannot vote twice in one term or forget entries it acknowledged.

Sources

Learn it by running it

The raft consensus lesson explains the mechanism behind this question, and its lab lets you change the parameters and watch the effect.

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms