Two-phase commit is the algorithm every distributed-transactions slide starts with: a coordinator asks participants to prepare, then tells them to commit or abort. It is also the algorithm that taught a generation of on-call engineers what "blocked" looks like — a lock held on a row in New York because a process in London died after saying "prepared" and before hearing "commit."
Gray and Lamport later showed you can recast commit as a consensus problem. That is the intellectual bridge from classic 2PC to Spanner-style and Cockroach-style coordinators that do not freeze forever when one machine vanishes.
The protocol in four messages, plus the trap
- Coordinator sends
PREPAREto all participants. - Each participant flushes enough state to recover (undo/redo), then votes
YESorNO. - If every vote is
YES, coordinator logs a commit decision and sendsCOMMIT. Otherwise it sendsABORT. - Participants ack. Coordinator forgets the transaction.
Between step 2 and step 3, a YES participant cannot unilaterally abort or commit. It has promised. If the coordinator disappears in that window, the participant is blocked: it must hold locks until a new coordinator reconstructs the decision from a surviving log, or a human unsticks it.
Participant (prepared, locks held)
|
| coordinator crash, no backup of the decision
v
blocked until timeout heuristics or operator interventionHeuristic timeouts that abort after N seconds can split the outcome: one participant commits from a late message, another aborted locally. That is how you get atomicity bugs that look like "impossible" customer reports.
Three-phase commit and why it did not save everyone
3PC adds an extra round so a participant can infer a decision from peers after a coordinator failure, under extra timing assumptions. Those assumptions fail on real networks (asynchronous delays look like crashes). Most production databases did not standardize on 3PC; they either avoided distributed commit, used compensating sagas, or put the decision in a replicated log.
Consensus on the commit record
If the commit decision itself is stored in Raft or Paxos, any majority of coordinators can finish the protocol. Participants still prepare, but they are no longer waiting on a single process's disk. That is the idea in "Consensus on Transaction Commit": the hard part is agreeing on one bit (commit vs abort) durably, then informing everyone.
This is also why "just use a transaction across two microservices" is expensive. You are buying a consensus group, prepared locks, and a recovery story — or you are buying a saga and accepting that money-shaped operations need idempotency keys and explicit compensation. Both are valid. Pretending HTTP + 2PC without a replicated coordinator is neither.
When you design a checkout that touches payments and inventory, name which of those two worlds you are in before you draw the boxes.
A worked example
2PC: coordinator asks prepare; resources lock; coordinator commits. If the coordinator dies after prepare, participants stay blocked. XA transactions across MySQL and a JMS broker show this in the wild. Raft: a majority logs the decision; there is no silent blocking on one coordinator disk forever — recovery is the log.
A chaos test: kill the 2PC coordinator vs kill a Raft follower.
Failure modes
2PC over a WAN. Timeouts that abort on one side and commit on the other. Heuristic decisions that leave branches inconsistent. Using 2PC for user-facing latency SLOs. Consensus with a cluster of 2 (no majority).
Pretending a saga is 2PC.
When this is the wrong tool
2PC is the wrong default in microservices. A single database transaction is the right tool when it fits. Consensus is the wrong tool for a shopping cart CRDT. If you need cross-region write availability during partition, neither blocking 2PC nor a single Raft group in one region will make CAP disappear. Use idempotent APIs and sagas for business workflows; use Raft inside a store, not across HTTP services.
A worked failure mode
2PC coordinator is a single VM; it dies in the prepared state and participants hold locks for hours. Timeouts abort one side and commit the other. The failure is blocking consensus with a fragile coordinator. Prefer a single DB, sagas, or a real consensus log with fencing.
2PC is the wrong tool across HTTP microservices. It is the wrong tool if you cannot staff coordinator HA. Avoid it unless a database product implements it well inside one system.
A worked anti-pattern: the team ships the architecture, then staffs it like a toy. "Two-Phase Commit, Blocking, and Why Consensus Took Over Coordination" needs boring operations—backups, timeouts, ownership, and a budget for the tax the idea always charges (compaction, replay, dual writes, extra latency, extra types). Unstaffed taxes come due at 2am. Put the tax in the design doc's cost section. If leadership wants the benefit without the tax, the honest answer is a smaller idea, not a heroic on-call rotation.