2PC with an extra step so a crashed coordinator does not leave everyone stuck.
Three-Phase Commit (3PC) is two-phase commit with one extra step in the middle, called pre-commit. The goal is to fix 2PC's big weakness: participants getting stuck when the coordinator crashes.
Remember the problem with 2PC. After voting YES, a participant is in a ready state. If the coordinator dies, it does not know the outcome. Some others might have committed already, so it cannot abort. Someone might have voted NO, so it cannot commit. It must wait.
3PC splits the ready state into two. After the vote, the coordinator sends PRE-COMMIT, which means "everyone voted YES, and I am about to commit." Participants reply ACK. Only then does the coordinator send DO-COMMIT. The key rules are:
| Phase | Coordinator sends | Participants do |
|---|---|---|
| 1. CAN-COMMIT | Can you commit? | Check if the work is possible. Reply YES or NO. Still no locks are released and nothing is committed. |
| 2. PRE-COMMIT | Everyone said YES: prepare to commit | Record that the outcome will be commit, and reply ACK. This is the new step. |
| 3. DO-COMMIT | Commit now | Commit, release locks, reply that they are done. |
If any participant votes NO in phase 1, the coordinator sends ABORT to all, as in 2PC.
| Participant state | What it knows | Rule on timeout |
|---|---|---|
| Uncertain (voted YES, no PRE-COMMIT) | No one can have committed yet | ABORT |
| Pre-committed (got PRE-COMMIT) | Everyone voted YES | COMMIT |
| Committed or aborted | The matter is closed | Nothing to do |
All three participants voted YES. The coordinator crashed before it sent anything else.
A table of the textbook rules, not a network simulation. Real systems that need to avoid blocking use a consensus protocol (Paxos or Raft) to replicate the coordinator, instead of 3PC.
| Term | Meaning in easy words |
|---|---|
| CAN-COMMIT | Phase 1: the coordinator asks if each participant can commit |
| PRE-COMMIT | Phase 2: the coordinator says everyone voted YES, so the outcome will be commit |
| DO-COMMIT | Phase 3: the coordinator tells everyone to commit now |
| Uncertain state | Voted YES but no PRE-COMMIT yet. Safe to abort on timeout |
| Pre-committed state | Got PRE-COMMIT. Safe to commit on timeout |
| Non-blocking | Participants can decide without waiting for a failed coordinator |
| Network partition | A split where groups of machines are alive but cannot reach each other |
| Synchronous network | An assumption that messages arrive within a known time limit |
| Timeout | A deadline after which a node assumes the other side failed |
| Recovery protocol | A step where the remaining participants elect a new coordinator and decide the outcome |
| Consensus | Agreement among machines on one value, even with failures (Paxos, Raft) |
| Choice | We gain | We lose |
|---|---|---|
| 3PC instead of 2PC | No blocking when only the coordinator crashes | A round trip of latency, and safety under partitions |
| 2PC with a replicated coordinator | Safe, and not blocked by one crash | More complexity, but this is how real systems do it |
| Short timeouts in 3PC | Faster recovery | More false 'crash' detections, so more risk of a split decision |
| SAGA instead of either | No global locks and independence | Eventual consistency and compensation code |