Consensus
0-day streakReview

Your progress

Level 1

0 XP100 XP to level 2
0day streak
0best streak
0topics started
0cards reviewed
    Review cards

    Progress is stored only in this browser. No account is required.

    Consensus and leader election: the 60-second story

    Consensus

    Your society’s register lives in five notebooks. The secretary just went silent.

    Who writes next? Does his last entry, copied into only two notebooks, count? Servers face exactly this with one shared log.

    Same log, same code, same state

    Servers agree on one ordered log of commands. Each feeds it to the same deterministic code, so replicas match without ever comparing state.

    2f+1

    members to survive f crashes

    Every decision needs a majority, 3 of 5. Any two majorities share a server, so someone in the next knows what the last decided.

    Is a fourth node safer?

    Bad: Four nodes

    Quorum 3, still survives one failure. A 2–2 split leaves neither side a majority.

    Good: Five nodes

    Quorum 3, survives two: one in maintenance plus one crash.

    The leader dies. Whose timer fires first?

    Each follower waits a random timeout, 150–300 ms in the paper. The first to fire starts term 2, asks for votes, and leads with 3 of 5.

    Two servers think they lead. Only one can commit.

    Raft promises at most one leader per term, not one at a time. Old S1 can’t reach 3 of 5, so its write never commits.

    Who runs the scheduler?

    Bad: Lowest IP wins

    Free, but nodes with different views pick different leaders.

    Good: Campaign on an etcd lease

    Lowest key revision leads. If it dies, its lease expires; the next takes over.

    The old leader froze for 20 seconds; a new one took over. It wakes mid-write. What stops it?

    The catch

    Not the lease. Send the term as a fencing token; receivers reject anything lower.

    Remember

    One leader per term, commit on a majority: majorities overlap, so nothing committed is lost. Use etcd; fence the leader’s writes.