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.

Two time-down message diagrams side by side. 2PC: CanCommit?, Yes, DoCommit, haveCommitted. 3PC: CanCommit?, Yes, PreCommit, ack, DoCommit, haveCommitted. The participant state after each message is written next to it.
3PC puts a PreCommit / ack round between the vote and the commit: 6 message delays instead of 4.

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).

RoundMessageSent byState after it
1CanCommit?coordinatorcoordinator: wait
1Yes / NoparticipantYes: uncertain, locks held. No: aborted at once
2PreCommitcoordinator, after three Yesparticipant: pre-committed
2ackparticipantcoordinator learns that this participant knows
3DoCommitcoordinator, after every ack (or its ack timeout)participant: committed, locks released
3haveCommittedparticipantcoordinator 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.

Participant state diagrams. 2PC: initial to prepared, prepared to committed or aborted. 3PC: initial to uncertain, uncertain to aborted or to pre-committed, pre-committed to committed. In 3PC the uncertain state is next to aborted only and pre-committed is next to committed only.
In 2PC one state touches both outcomes; in 3PC no state does, so a participant's own state says what is safe.

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 hearsDecisionWhy it is safe
someone abortedabortthe decision was abort
someone committed or pre-committedcommit: PreCommit the uncertain ones, wait for acks, then DoCommiteveryone voted Yes
everyone uncertainabortnobody 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.

Left of a red partition line: coordinator C, P1 and P2, all committed. Right of it: P3 alone, uncertain, then aborted. Below: a majority rule would let only the side with 3 of 4 nodes decide, and P3 would wait.
Each side of the cut applies the 3PC rule and reaches a different decision; a majority rule lets only one side decide.

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.

On the mind map

Open the Distributed Systems mind mapDistributedSystemsReplication: copies of data · what reads seeReplicationPartitioning: split data over nodesPartitioningTime and membership: order events, know who is aliveTime and membershipConsensus: agree on one value or logConsensusTransactions: one change across many servicesTransactionsMessaging: send events between systemsMessagingKafka internals: a replicated append-only logKafka internalsRedis internals: one thread, data in memoryRedis internalsKubernetes: reconcile desired stateKubernetesResilience and speed: stay up and fast under loadResilience and speedTwo-phase commitTwo-phase commitall vote yes, then commit; can blockThree-phase commitPreCommit ends blocking; partitions split itSaga vs 2PCSaga vs 2PCsaga: local steps plus compensationOrchestration vs choreographyOrchestration vs choreographyorchestrator commands vs reacting to eventsOutbox and inboxOutbox and inboxwrite event in same DB transactionEvent sourcing and CQRSEvent sourcing and CQRSstore events, build read views from themDistributed lockDistributed lockTTL can expire; fencing token saves youIdempotency keysIdempotency keysSame key twice = one chargeCard payment flowCard payment flowAuthorize holds; settlement moves moneyOpen the Distributed Systems mind mapDistributed Systemsone change across many servicesTransactionsTwo-phase commitTwo-phase commitall vote yes, then commit; can blockThree-phase commitPreCommit ends blocking; partitions split itSaga vs 2PCSaga vs 2PCsaga: local steps plus compensationOrchestration vs choreographyOrchestration vs choreographyorchestrator commands vs reacting to eventsOutbox and inboxOutbox and inboxwrite event in same DB transactionEvent sourcing and CQRSEvent sourcing and CQRSstore events, build read views from themDistributed lockDistributed lockTTL can expire; fencing token saves youIdempotency keysIdempotency keysSame key twice = one chargeCard payment flowCard payment flowAuthorize holds; settlement moves money
This page on the Distributed Systems mind map · 104 pages in 10 branches · open it to see the whole map and test yourself in recall mode.