1 of 4

Your RightSignal

Systems design · 8 of 121 / 3

Raft consensus

The concept

Why a 5-server cluster keeps working after 2 servers die

Raft lets a group of servers agree on one ordered log of commands, so every copy applies the same writes in the same order. One server is elected leader. Every write goes through it, and it copies each write to the followers.

A write counts as committed, meaning safe forever, once a majority of servers have stored it. With 5 servers that is 3, so 2 can crash or drop off the network and the other 3 still accept and commit writes.

Time runs in numbered terms, each with at most one leader. A follower that hears no leader for a random timeout (about 150–300 ms) starts a new term and asks for votes. Each server votes once per term, and a majority wins.

What it’s forSays how many servers must store a write before it is committed, and how many failures a cluster survives.

quorum = ⌊n/2⌋ + 1, failures tolerated f = n − quorum

n
number of servers in the cluster, usually 3 or 5
⌊n/2⌋
half of n, rounded down
quorum
the majority needed to commit a write or win an election
f
how many servers can fail with the cluster still working

What it givesThe majority size, and therefore how many crashed servers the cluster can survive.

  1. n = 5: quorum = 2 + 1 = 3, so f = 5 − 3 = 2
  2. n = 4: quorum = 2 + 1 = 3, so f = 4 − 3 = 1
  3. A 4th server adds no safety over 3, which is why clusters use odd sizes