Distributed Systems
Distributed Consensus and Commit Protocols
Distributed consensus and commit protocols let several machines act as one, even when some of them crash. Paxos and Raft make a group agree on a value or a log. Two-phase and three-phase commit make a group all commit or all abort a transaction. Quorum reads and writes keep replicas consistent without a leader. Here is the comparison table first, then each protocol in depth.
At a glance
Machines fail, and networks drop messages. Yet we want a group of machines to behave like one reliable computer. Consensus protocols solve this by getting the group to agree. They are the base layer under databases, lock services and cluster managers.
These protocols are related, but they do not solve the same problem. Paxos and Raft make a group agree on a value or a log. Two-Phase Commit and Three-Phase Commit make a group all commit or all abort one transaction. Quorum Consensus is a read and write rule that keeps replicas consistent. Use the table to compare them, then open each page for an interactive walkthrough.
| Distributed Systems | Problem solved | Fault model | Nodes to tolerate f faults | Blocking? | Message rounds (normal case) | Used in |
|---|---|---|---|---|---|---|
| Paxos | Consensus: agree on a value (or a log with Multi-Paxos) | Crash-recovery, lossy and delayed messages; not Byzantine | 2f + 1 | Safe always; makes progress only while a majority is up and a leader is stable | 2 round trips (prepare, accept); 1 with a stable leader in Multi-Paxos | Chubby, Spanner and other Google systems (Paxos variants) |
| Raft | Consensus on a replicated log (replicated state machine) | Crash-recovery, lossy and delayed messages; not Byzantine | 2f + 1 | Safe always; no writes while no leader or no majority | 1 round trip from the leader to a majority | etcd, Consul, CockroachDB, TiKV |
| Two-Phase Commit | Atomic commit: all participants commit or all abort | Crash-recovery with durable logs; assumes the failed coordinator eventually returns | All participants must vote yes; a crashed coordinator is a single point of failure unless it is replicated | Yes: prepared participants wait if the coordinator crashes | 2 round trips (prepare/vote, commit/ack) | XA transactions in SQL databases and message brokers; Spanner (with Paxos-replicated participants) |
| Three-Phase Commit | Atomic commit: all participants commit or all abort | Crash-stop with a reliable network and trusted timeouts; unsafe under partitions | All participants must vote yes; timeouts let survivors finish after a crash | No under crash-stop; can break safety (split outcome) under partitions | 3 round trips (can-commit, pre-commit, do-commit) | Mostly textbooks; almost no production use |
| Quorum Consensus | Consistent replicated reads and writes (not agreement on one value or atomic commit) | Crash failures and slow replicas; partitions handled by the choice of R and W | Depends on R and W; majority quorums tolerate f failures with 2f + 1 replicas | Operations fail if fewer than R or W replicas respond | 1 round trip to R or W replicas, no leader | Cassandra, Dynamo-style stores, Riak |
Each algorithm in depth
Click any card for the full article with an interactive visualization, complexity analysis, code examples, and FAQ.
-
Paxos
A family of protocols that lets a group agree on one value, even if machines crash and messages are lost. A proposer asks a majority to promise, then asks them to accept. Multi-Paxos repeats this to build a log.
View interactive ↗ -
Raft
A consensus algorithm built to be easy to understand. One elected leader takes client requests, copies log entries to followers, and commits an entry once a majority has it.
View interactive ↗ -
Two-Phase Commit
A coordinator asks every participant to prepare and vote. If all vote yes, it tells them to commit. Otherwise it tells them to abort. Simple, but a prepared participant must wait if the coordinator dies.
View interactive ↗ -
Three-Phase Commit
Two-phase commit plus a pre-commit step, so participants can finish on their own by timeout if the coordinator crashes. It avoids blocking on crashes but is not safe when the network partitions.
View interactive ↗ -
Quorum Consensus
A replication rule, not a full consensus protocol. Write to W of N replicas and read from R. If R + W > N, every read overlaps the latest write. There is no leader and no single agreed order.
View interactive ↗
Consensus, atomic commit, and quorums are different problems
Consensus means several nodes each propose a value, and they all end up choosing the same one. Once a value is chosen it never changes. Paxos and Raft do this. They work as long as a majority of nodes is alive and can talk to each other. A group of 2f + 1 nodes tolerates f crashed nodes. So 3 nodes tolerate 1 failure, and 5 nodes tolerate 2.
Atomic commit is narrower. Several databases each did part of one transaction. Every one of them must commit, or every one must abort. One 'no' vote forces an abort, so the answer is not a free choice of value. Two-Phase Commit and Three-Phase Commit solve this. They need every participant to answer, not just a majority.
Quorum reads and writes are a third idea. With N replicas, a write waits for W acknowledgements and a read asks R replicas. If R + W > N, a read always meets at least one replica that saw the latest write. That gives fresh reads, but it does not by itself order concurrent writes or make a multi-step transaction atomic. See Quorum Consensus.
Paxos vs Raft
Both reach the same kind of agreement, using majorities and the same 2f + 1 node count. The difference is how they are built and explained.
Paxos was published by Leslie Lamport. Single-decree Paxos agrees on one value in two phases: prepare/promise, then accept/accepted. Real systems need a log of many values, so they use Multi-Paxos. A stable leader skips the first phase, which drops the steady-state cost to one round trip. The original paper leaves many details open, such as leader election and membership change. Each team had to fill the gaps on its own.
Raft fixes the whole design up front. It splits the problem into leader election, log replication, and safety. A node is a follower, a candidate, or the leader. Time is divided into numbered terms. The leader sends entries to followers and commits one when a majority holds it. Raft's authors, Diego Ongaro and John Ousterhout, designed it for understandability. Their user study found students learned Raft more easily than Paxos.
In practice, Raft and Multi-Paxos with a stable leader have similar performance. Raft gives you a complete, specified recipe. Paxos gives you a more flexible family. That flexibility is useful in research variants such as Flexible Paxos and leaderless designs.
Two-phase vs three-phase commit
In two-phase commit, the coordinator sends 'prepare'. Each participant logs its state to disk and votes yes or no. If everyone votes yes, the coordinator logs 'commit' and sends it. Otherwise it sends 'abort'.
The weak spot is the window after a participant votes yes. It can no longer abort on its own, because the others may have committed. It cannot commit on its own, because another vote may have been no. If the coordinator crashes now, the participant must wait. It holds its locks while it waits. This is why 2PC is called a blocking protocol.
Three-phase commit inserts a pre-commit step. A participant in pre-commit knows that everyone voted yes. So after a coordinator crash, the survivors can decide by timeout and finish the transaction. This removes blocking when nodes simply crash and the network is reliable. It does not survive a network partition. One side can time out and commit while the other side times out and aborts, which breaks atomicity. It also costs an extra round trip and an extra log write. That is why real systems rarely use it.
Modern systems take a different path. They keep 2PC, but replicate the coordinator and the participants with a consensus protocol. If the coordinator's state lives on a Paxos or Raft group, a crash just causes a new leader to take over and finish the job. Google Spanner works this way.
FLP impossibility and what it means in practice
In 1985, Fischer, Lynch and Paterson proved the FLP result. In a fully asynchronous system, where message delays have no upper bound, no deterministic consensus protocol can guarantee that it always terminates if even one node may crash. The reason is that you cannot tell a crashed node from a very slow one.
This does not mean consensus is impossible. It means you cannot have all of safety, liveness and full asynchrony with a deterministic algorithm. Paxos and Raft keep safety in every case. They never choose two different values. They give up guaranteed liveness. They only make progress when the network is reasonably timely. In practice they use timeouts and randomised election delays, so a stable leader appears quickly. Two candidates can still keep splitting votes in theory, but with random timeouts it is very unlikely to continue.
Real systems
- etcd and Consul use Raft. etcd stores Kubernetes cluster state. Consul uses it for its service catalog and key-value store.
- CockroachDB and TiKV run many small Raft groups, one per data range.
- Chubby and Spanner are Google systems built on Paxos variants. Spanner also runs two-phase commit across Paxos groups for transactions that touch several shards.
- XA transactions are the standard way relational databases and message brokers do two-phase commit across separate resources.
- Cassandra, Riak and Dynamo-style stores use quorum reads and writes with tunable R and W.
Decision guide
- You need a small, strongly consistent store for configuration, locks or leader election. Use a Raft-based system such as etcd or Consul. Do not write your own.
- You are building a replicated log or database from scratch. Raft is the easier path. Choose Multi-Paxos only if you have a reason, such as an existing Paxos codebase or a need for its variants.
- One transaction spans several separate databases. You need atomic commit. Use two-phase commit, and put the coordinator's decision on a replicated log if you cannot accept blocking.
- You want high availability and can accept eventual or tunable consistency. Use quorum reads and writes, and pick R and W for the balance of speed and freshness you want.
- Nodes may lie or be hacked. None of these protocols are enough. You need Byzantine fault tolerant protocols, which need 3f + 1 nodes.
Frequently asked questions
What is the difference between Paxos and Raft?
Both solve consensus with majority quorums and need 2f + 1 nodes to tolerate f crashes. Paxos is a family of protocols whose original description leaves out details like leader election and membership changes. Raft is a complete design built around a strong leader, a replicated log and numbered terms, and it was made to be easier to understand and implement. In steady state, Raft and Multi-Paxos with a stable leader both need about one round trip per decision.
What is the difference between two-phase commit and three-phase commit?
Two-phase commit has a prepare/vote phase and a commit/abort phase. If the coordinator crashes after participants vote yes, they must wait, so it blocks. Three-phase commit adds a pre-commit phase so survivors can decide by timeout and not block when nodes crash. The price is an extra round trip, and it is unsafe under network partitions, so it is rarely used in practice.
Is two-phase commit a consensus protocol?
It is related, but it solves a different problem. Consensus lets nodes choose one value and tolerates a minority of crashes. Two-phase commit is atomic commit: every participant must commit or every one must abort, and one no vote or one unreachable participant can force an abort. It also needs all participants to answer, not just a majority.
Why do consensus systems need an odd number of nodes?
They need a majority to agree. With 2f + 1 nodes, you can lose f and still have f + 1 left, which is a majority. Going from 3 to 4 nodes does not let you survive more failures (still 1), and it raises the number of acknowledgements you need. So 3, 5 and 7 are the usual cluster sizes.
What does the FLP impossibility result say?
In a fully asynchronous network, no deterministic protocol can guarantee that nodes reach consensus in finite time if even one node can crash. Real systems get around it by assuming the network is usually timely. Paxos and Raft never break safety, but they may stall for a while during bad network periods. They use timeouts and random delays so stalls are short.
Can Paxos or Raft handle malicious nodes?
No. They assume nodes either work correctly or crash. A node that sends false messages can break them. To survive Byzantine (arbitrary or malicious) faults you need a protocol such as PBFT, Tendermint or HotStuff, which needs 3f + 1 nodes to tolerate f bad ones.
Does quorum consensus (R + W > N) give the same guarantees as Raft or Paxos?
No. With R + W > N a read overlaps the latest acknowledged write, but concurrent writes can still conflict. Replicas can also disagree during failures or with sloppy quorums. The system needs extra rules, such as timestamps, to resolve this. Raft and Paxos give a single agreed order of operations, which is stronger.
Which protocol does etcd, Consul or Spanner use?
etcd and Consul use Raft. Google's Chubby and Spanner use Paxos variants. Spanner also uses two-phase commit across Paxos groups when a transaction spans several shards.