System Design
5. Advanced Database ArchitectureAnimated
Two-Phase Commit (2PC)
A protocol with prepare and commit phases.
The idea
The coordinator asks everyone to prepare; if all say yes, it tells them to commit.
Watch it work
Press play, pause, or step through. Some animations have settings you can change.
- current message
- earlier
- failure or attack
Phase 1: the coordinator asks everyone if they can commit.
- step:
- 1/7
- from:
- Coordinator
- to:
- Participant A
1/7
Time runs downward. Solid arrows are requests, dashed arrows are replies.
Step by step
- 1Coordinator sends PREPARE
- 2Participants vote yes or no
- 3If all yes, send COMMIT
- 4Otherwise ABORT
Where it is used
Classic distributed transactions.
Watch out for
Blocks if the coordinator crashes after prepare.