The idea: one more round, so nobody is stuck
A distributed transaction changes data on several machines, the participants. A coordinator makes sure they all commit or all abort. Two-phase commit (2PC) does it in two rounds: vote, then decide. Its weak spot is a coordinator crash right after the votes: the participants are left waiting. Three-phase commit (3PC), from Dale Skeen (1981), adds one round in the middle, PreCommit. After it, everyone knows that everyone voted Yes. That extra knowledge lets the participants finish without the coordinator.
The three rounds
The page uses the message names from Coulouris et al. Other books say VOTE-REQ, PRE-COMMIT and COMMIT; the protocol is the same (Demo 1: 3PC, all vote Yes → commit).
| Round | Message | Sent by | State after it |
|---|---|---|---|
| 1 | CanCommit? | coordinator | coordinator: wait |
| 1 | Yes / No | participant | Yes: uncertain, locks held. No: aborted at once |
| 2 | PreCommit | coordinator, after three Yes | participant: pre-committed |
| 2 | ack | participant | coordinator learns that this participant knows |
| 3 | DoCommit | coordinator, after every ack (or its ack timeout) | participant: committed, locks released |
| 3 | haveCommitted | participant | coordinator can forget T1 |
A single No still aborts everything: the coordinator sends DoAbort to the Yes voters, and the No voter has already aborted (Demo 2: 3PC, P3 votes No → abort).
Why 2PC blocks
In 2PC a participant that voted Yes is prepared. It has promised to commit if told to, so it may not abort alone. It does not know the decision either, so it may not commit alone. It is uncertain. If the coordinator crashes after collecting the votes, the participants time out and ask each other. Everyone answers "prepared", and nobody knows whether the coordinator logged commit just before the crash. They must wait, holding their locks, until the coordinator comes back (Demo 3: 2PC, coordinator crashes after the votes → blocked). That is why 2PC is called a blocking protocol.
2PC is lucky only when some participant has already seen the decision. Pick 2PC and "C crashes after its first decision message" in the TRY IT bar: P1 got DoCommit, so the others learn "commit" from P1.
States and the non-blocking rule
Skeen's insight is about which states sit next to each other. In 2PC the prepared state leads straight to committed and to aborted. So a prepared participant cannot tell which one the others may already be in. In 3PC no state is next to both. An uncertain participant knows nobody has committed yet, because the coordinator sends DoCommit only after every participant is pre-committed. A pre-committed participant knows everyone voted Yes, so nobody can have aborted on a No.
Timeouts and the termination protocol
A 3PC participant that hears nothing for a while (3 ticks on this page) times out. The participants that can still talk pick a new coordinator, here the lowest-numbered one. It asks every reachable participant for its state with state? and applies one rule:
| States it hears | Decision | Why it is safe |
|---|---|---|
| someone aborted | abort | the decision was abort |
| someone committed or pre-committed | commit: PreCommit the uncertain ones, wait for acks, then DoCommit | everyone voted Yes |
| everyone uncertain | abort | nobody can have committed yet |
With the same crash that blocked 2PC, the 3PC participants abort within a few ticks (Demo 4: 3PC, same crash → termination aborts). If the coordinator got one PreCommit out before it crashed, they commit instead (Demo 5: 3PC, crash after one PreCommit → termination commits). Either way, no one waits for the coordinator. When it restarts, it asks the others for the outcome.
The partition: two sides, two decisions
The rule is only safe if a participant that does not answer has really crashed. A network partition breaks that. In Demo 6: 3PC, partition cuts off P3 → split decision, the cut comes right after the votes. PreCommit reaches P1 and P2 but not P3. P3 times out, sees only itself, uncertain, and aborts. On the other side, the coordinator's ack timeout fires and it commits with P1 and P2, treating the silent P3 as crashed. Both sides followed the protocol. T1 is now committed on two machines and aborted on the third.
In the 2PC version of the same partition (pick 2PC and "partition cuts off P3"), P3 does not decide wrong: it just blocks until the network heals. So 2PC can block, and 3PC can disagree. In an asynchronous network you cannot tell a slow node from a dead one, and no commit protocol is both always safe and never blocking.
Why real systems use consensus instead
3PC costs an extra round on every commit and still fails under partitions, so it is rarely used. Real systems keep 2PC but make each "node" a replicated group that agrees by consensus. Gray and Lamport's Paxos Commit runs a Paxos instance per participant's vote, so the commit goes on as long as a majority of acceptors is up. Google Spanner and CockroachDB run 2PC where the coordinator and every participant is a Paxos or Raft group. A crashed leader is replaced within the group, so nobody blocks for long. A minority side of a partition cannot decide, so the two sides cannot disagree.
See also Two-Phase Commit for 2PC's logs, recovery and presumed abort, Saga vs Two-Phase Commit for giving up atomic commit, Paxos, Raft and Raft vs Paxos for majority agreement that survives a partition, and the CAP theorem for the general trade-off.
What the page leaves out
Logs and forced writes (see Two-Phase Commit), recovery of a restarted node, failures during the termination protocol itself (a new coordinator that crashes, re-election), electing the new coordinator by a real protocol, the precise synchrony assumptions of Skeen's proof, the FLP impossibility result, and the full Paxos Commit message flow.