Read this as How do participants reach one atomic commit or abort decision?
- Failure Trap
- Forgetting that 2PC can block when the coordinator fails at the wrong time.
- Decision Rule
- Use 2PC for short atomic boundaries; prefer sagas or idempotent recovery for long-running workflows.
Distributed Transaction Request
A client wants to perform a transaction across multiple databases: transfer $100 from Account A (Database 1) to Account B (Database 2), and log the transfer (Database 3).
A coordinator (Transaction Manager) orchestrates this across all participants (the databases).
- Single transaction spans multiple systems
- Coordinator manages the protocol
- Either ALL succeed or ALL fail (atomicity)
Phase 1: PREPARE - Can You Commit?
The coordinator sends a PREPARE request to each participant. Each participant must:
- Acquire necessary locks
- Write a prepare record to its log
- Determine if it CAN commit
The participant votes without actually committing yet.
- Resources are locked but not changed
- "Point of no return" — once you vote YES, you must be able to commit
Vote: YES or NO?
Each participant responds with its vote:
- YES: "I can commit if asked"
- NO: "Something prevents me from committing"
The rule is unanimity: every vote must be YES to commit, and a single NO forces the whole transaction to abort. In the diagram, P1 and P2 vote YES while P3 is still deciding — its vote alone can flip the outcome.
The coordinator now waits for all votes. This is the vulnerability window — participants hold their locks until the coordinator replies, so if the coordinator crashes here they are stuck (see the last step).
Phase 2: COMMIT
Since all participants voted YES, the coordinator:
- Writes "COMMIT" to its log (point of no return)
- Sends COMMIT to all participants
Participants MUST commit upon receiving this — they already promised they could.
- Coordinator logs the decision before sending
- Participants are obligated to commit
- Recovery replays the commit log
Atomic Commit Done
Each participant commits, releases its locks, and sends an ACK to the coordinator. The distributed transaction is now atomically complete — every database is consistent.
If any ACK is lost, the coordinator retries until confirmed.
- Atomicity achieved across multiple systems
- All-or-nothing guarantee
When It Goes Wrong
2PC is defined by its failure modes, not just the happy path:
- A single NO → global ABORT. One participant unable to commit cancels the whole transaction; everyone rolls back.
- Coordinator crash mid-vote → participants block. With the decision unknown, participants cannot safely commit or abort, so they wait — holding locks — until the coordinator recovers. This is the blocking problem that makes 2PC trade availability for atomicity.
This is the vulnerability window from step 3, made concrete.