Three-Phase Commit Improvements
What you'll learn: How three-phase commit (3PC) extends two-phase commit by adding an extra phase that helps systems recover more gracefully from coordinator failures.
The Problem with Two-Phase Commit
You already know two-phase commit (2PC) from the previous lesson. Its Achilles' heel is coordinator failure during the commit phase. If the coordinator crashes after some participants have committed but before others receive the commit message, the system can get stuck—participants don't know whether to commit or abort.
How Three-Phase Commit Helps
Three-phase commit adds a "prepare-to-commit" (or "pre-commit") phase between the voting and commit phases:
- Phase 1 - Prepare: Coordinator asks all participants if they can commit (same as 2PC)
- Phase 2 - Pre-Commit: If all vote YES, coordinator sends "prepare-to-commit" to all participants. Participants acknowledge they're ready and know everyone voted YES.
- Phase 3 - Commit: Coordinator sends final commit instruction
Why This Matters
The key insight: Phase 2 creates a "point of no return" that everyone acknowledges before anyone actually commits. If the coordinator fails:
- Before pre-commit acknowledgments: Participants can safely abort (no one has committed yet)
- After pre-commit acknowledgments: Participants know everyone agreed, so they can safely commit even without the coordinator
Think of it like a synchronized dive: Phase 1 checks if everyone's ready, Phase 2 confirms "we're all jumping on three," and Phase 3 is the actual jump. If the coach faints between phases, the divers know what to do.
Limitations
3PC assumes a synchronous system with timeout-based failure detection. Network partitions can still cause problems—it doesn't handle Byzantine failures or arbitrary delays well.
Key Takeaway: Three-phase commit adds a pre-commit phase that makes coordinator failures recoverable by ensuring all participants know the global decision state before anyone commits, though it still requires synchronous system assumptions.