System Design Lab

Advanced · How a group of servers agrees on one truth.

Consensus (Raft)

Distributed databases need one leader to order writes. When it dies, the rest must elect a new one without ever ending up with two. Raft does it with heartbeats, terms and majorities.

Wiring up the simulator…

Try this

Run each experiment in the simulator above, then tick it off.

Key ideas

Heartbeats

The leader pings followers. Silence past a random timeout triggers an election.

Majority (quorum)

A leader needs votes from a majority, and a write commits once a majority stores it. Two majorities always overlap, so there can't be two leaders in one term.

Under half alive means stop

Refusing writes beats corrupting data.

In your Pabbly workflows

You won't implement this, but it explains why managed databases come in 3 or 5 nodes (not 2 or 4), and why some services go read-only during an outage instead of losing your data.

Check yourself

0/2

Get every question right to mark this lab done. Wrong answers let you try again.

Q1. A 5-node cluster can lose how many nodes and still accept writes?

Q2. Why are election timeouts randomized?

Watch next

Searches for “raft consensus” on the channels worth your time.