Two-Phase Commit
Subject: Computer and Technology noun /ˌtuː.feɪz kəˈmɪt/ 1 definition
- distributed-systems
- database-management
- transaction-processing
- data-consistency
-
Definition (noun)
Entry #240 · UpdatedTwo-Phase Commit (2PC) is a distributed atomic commitment protocol that guarantees a transaction spanning multiple independent nodes or resource managers either commits everywhere or aborts everywhere. Driven by a central coordinator, it splits execution into a prepare phase—where participants acquire locks, durably log state, and vote ready or abort—and a commit phase, where the coordinator broadcasts a final commit only upon unanimous readiness. Its primary purpose is preserving cross-node atomicity despite partial failures, though its defining limitation is blocking: participants that have voted ready must hold locks and wait if the coordinator crashes before delivering the final decision.
Common Forms
Standard (Basic) Two-Phase Commit: Requires durable log forces and explicit Phase 2 acknowledgments for every commit or abort outcome, prioritizing protocol simplicity over I/O and messaging overhead.
Presumed Abort Two-Phase Commit: Optimizes aborted and read-only transactions by allowing the coordinator to skip forced abort logs and forget aborted state immediately, answering unknown transaction queries with abort.
Presumed Commit Two-Phase Commit: Optimizes commit-heavy workloads by tracking active transactions via a prepare-time collecting record so participants can skip forced commit logs and acknowledgments, presuming unknown queries committed.
Hierarchical (Tree) Two-Phase Commit: Organizes participants beneath intermediate sub-coordinators in a multi-level tree, enabling federated databases or nested services to aggregate votes upward and propagate decisions downward.
Example
During a flight booking, a transaction manager runs a two-phase commit across a seat-reservation database and a payment ledger to reserve seat
14Aand charge$420atomically. When both systems lock their rows, flushPREPARErecords to disk, and replyYESin Phase 1, the coordinator durably logsCOMMITand finalizes both updates in Phase 2; if the payment ledger instead reports insufficient funds and votesABORT, the coordinator rolls back the seat hold on the reservation database as well.