← Lessons

quiz vs the machine

Gold1400

Databases

Raft For SQL Replication

How a consensus log keeps shard replicas consistent and survives failure.

5 min read · core · beat Gold to climb

Replicating Each Shard

Distributed SQL databases split data into shards and keep several copies of each shard for durability. Raft is the consensus algorithm that keeps those copies in lock step, one Raft group per shard.

How Raft Works

  • One replica is the leader; the rest are followers.
  • Clients send writes to the leader, which appends an entry to its log.
  • The leader replicates the entry to followers and waits for a majority to acknowledge.
  • Once a majority has the entry it is committed and applied to the state machine.

A majority of three replicas is two, so the system tolerates one node failure while staying available.

Leader Election

If followers stop hearing from the leader, they time out and start an election, voting for a candidate. A candidate that wins a majority becomes the new leader. Because commits already required a majority, no committed write is ever lost during a leader change.

Key idea

Raft runs one consensus group per shard, committing writes only after a majority acknowledges, which keeps replicas consistent and survives minority failures.

Check yourself

Answer to earn rating on the learn ladder.

1. When is a Raft log entry considered committed?

2. How many node failures can a three replica Raft group tolerate?