tezvyn:

Raft: Understandable Distributed Consensus

AI-drafted, machine-checkedSource: Wikipedia: Raft (computer science)advanced
Raft: Understandable Distributed Consensus

Raft gets a cluster of servers to agree on a shared state by electing a leader to manage a replicated log. It's used to build fault-tolerant systems that must maintain a consistent state machine. The footgun: assuming 'easier than Paxos' means 'easy'.

WHY IT EXISTS Building reliable distributed systems requires getting all nodes to agree on the state of the world, a problem called consensus. The classic solution, Paxos, is notoriously difficult to understand and implement. Raft was designed from the ground up to be easier to understand than Paxos while providing the same safety guarantees.

THE MENTAL MODEL Think of Raft as a small government for your servers. To avoid chaos, the servers elect one leader. All changes (state transitions) must go through the leader. The leader writes the proposed change in its log and tells the other servers (followers) to do the same. A change is only committed and made official once a majority of servers have written it to their logs, ensuring agreement even if some servers fail.

HOW IT WORKS Raft's key to understandability is its separation of logic. It breaks the complex problem of consensus into three more-or-less independent parts: first, Leader Election, where servers elect a single leader; second, Log Replication, where the leader manages replicating the shared log to followers; and third, Safety, the set of rules that ensures correctness. This decomposition makes the algorithm's behavior easier to reason about compared to more monolithic approaches.

WHEN TO USE IT Use Raft when you need to distribute a state machine across a cluster and ensure every node agrees on the same series of transitions, even in the face of failures. It is a foundational component for building fault-tolerant and strongly consistent systems like distributed databases, configuration stores (like etcd), and coordination services.

WHEN NOT TO USE IT Raft enforces strong consistency, which comes with performance overhead from its communication protocol. If your application can tolerate eventual consistency, or if there is no critical shared state to manage across nodes, Raft is likely overkill. Its guarantees are unnecessary and costly for systems that don't require strict agreement.

ONE CANONICAL EXAMPLE A canonical example is not a single application but its role as a generic building block. Raft offers a way to add a fault-tolerant, replicated log to any system. The existence of full-specification, open-source implementations in languages like Go, C++, Java, and Scala shows its purpose as a foundational library for building reliable, distributed software.

Read the original → en.wikipedia.org

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.