Skip to main content
Definition Website Computer and Technology

Two-Phase Commit

Subject: Computer and Technology noun /ˌtuː.feɪz kəˈmɪt/ 1 definition

  1. Definition (noun)

    Entry #240 · Updated

    Two-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 14A and charge $420 atomically. When both systems lock their rows, flush PREPARE records to disk, and reply YES in Phase 1, the coordinator durably logs COMMIT and finalizes both updates in Phase 2; if the payment ledger instead reports insufficient funds and votes ABORT, the coordinator rolls back the seat hold on the reservation database as well.