Try
↑ ↓ move↵ openesc close

Interview prep / Raft and consensus

Mid · Raft and consensus · System design interview question

Why are Raft election timeouts randomised, and how should they relate to the heartbeat interval and the network delay?

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

A strong answer

If every follower used the same timeout, they would all time out together after a leader died, all become candidates for the same term, and split the vote. Nobody would get a majority, they would all time out again at the same moment, and the cluster could loop. Drawing each timeout at random from a range means one node usually fires first, wins before the others time out, and its heartbeats stop them.

The ordering is heartbeat interval, well below election timeout, well below the typical time between failures. Heartbeats must arrive several times per election timeout so that normal jitter does not trigger elections. The election timeout, and especially the width of its random range, must be large compared with the message delay, so that a candidate's votes come back before a second node times out.

When the range is tight relative to delay, split votes become common. Each adds a full timeout of leaderless time. So the timeout is a tradeoff too: longer means fewer split votes and more time without a leader after a crash.

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