Phase 2: Commit Phase
What You'll Learn
You'll understand how the coordinator makes the final decision to commit or abort based on participant votes, completing the two-phase commit protocol.
The Final Decision
After collecting votes from all participants in Phase 1 (the Prepare Phase), the coordinator must now make a binding decision. This is where the transaction either succeeds or fails as a whole.
The coordinator follows a simple but critical rule: unanimity required. If every single participant voted "yes" (prepared successfully), the coordinator issues a COMMIT command. If even one participant voted "no" or failed to respond, the coordinator issues an ABORT command.
The Commit Decision Flow
Coordinator checks all votes:
- All participants voted YES → Send COMMIT to all
- Any participant voted NO → Send ABORT to all
- Any participant timed out → Send ABORT to all
Once participants receive the coordinator's decision, they execute it. A COMMIT means they permanently apply the changes they prepared. An ABORT means they roll back and discard those changes.
Why Unanimity Matters
Think of it like a synchronized group acrobatic stunt. Every performer must be ready and in position (prepared). If one person isn't ready, the whole stunt must be cancelled—attempting it anyway would cause disaster. Similarly, partial transaction commits would violate data integrity across your distributed system.
Point of No Return
Once the coordinator sends COMMIT messages, there's no turning back. Participants must commit, even if they encounter issues. This is why the prepare phase is so thorough—participants only vote "yes" if they're absolutely certain they can commit.
Key Takeaway: The commit phase enforces all-or-nothing atomicity: the coordinator commits only if all participants agree, ensuring the distributed transaction succeeds or fails as a single unit.