Instiq
Chapter 4 · Transactions & concurrency control·v1.0.0·Updated 7/10/2026·~16 min

What's changed: Initial version

4.5Distributed transactions and two-phase commit

Key points

Covers the prepare (commit-request) phase and commit phase of two-phase commit (2PC), which guarantees atomicity for a transaction spanning multiple database sites, the three-phase commit (3PC) that addresses its weakness, and the blocking problem in 2PC, building the judgment needed to decide how to ensure consistency in a distributed environment.

For an architect designing a system in which the inventory database and the payment database live on separate servers, "how to atomically commit an update spanning multiple sites" is a challenge specific to distributed systems. Unlike a COMMIT on a single database, network latency and the failure of some sites must be accounted for. This section builds the judgment needed to decide how to ensure consistency for a distributed transaction, and how to deal with the weakness that two-phase commit carries.

4.5.1The two phases of two-phase commit (2PC)

  • Two-phase commit (2PC) is a protocol that, when a single transaction spans multiple database sites (participants), guarantees that all sites commit or roll back atomically together. A coordinator communicates with each participant and drives the process through two phases.
  • In the first phase (prepare phase / commit-request phase), the coordinator asks all participants "can you commit?" Each participant writes its own updates to its log and then replies either "ready (YES)" or "refuse (NO)." In the second phase (commit phase), if YES has been received from every participant, the coordinator sends a COMMIT instruction to all participants to finalize the transaction. If even one participant replies NO, or if a reply times out, the coordinator instead sends a ROLLBACK instruction to all participants to undo it.

Continue reading — free sign-up

You're reading the free preview. Sign up free to read this section in full, plus every chapter (including 4+) and all questions.