Skip to content
tezvyn:
Menu

Raft: Understandable Distributed Consensus

Source: Wikipedia: Raft (computer science)HardHow cards are made

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.

Interview question

What was the primary motivation behind Raft's design compared to Paxos?

  • a.To provide a simpler, more understandable approach to distributed consensus with equivalent safety.Correct
  • b.To achieve eventual consistency across a cluster with fewer communication rounds.
  • c.To offer a more performant consensus algorithm for high-throughput systems.
  • d.To enable distributed systems to function correctly without requiring a leader.
Why?

The card explicitly states that Raft was designed to be 'easier to understand than Paxos while providing the same safety guarantees,' which aligns with option A. Option C is incorrect because Raft's strong consistency often introduces performance overhead. Option D is wrong as leader election is a fundamental part of Raft. Option B is incorrect because Raft enforces strong consistency, not eventual consistency.

Just read this? Test yourself on what you have been reading.

Read the original → en.wikipedia.org

Put your scrolling time to good use

Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on distributed systems — each one lists the topics its interview covers.

See open roles