NOTE

2.9 Two-Stage Implementation: 2PC

A compact implementation-oriented view of two-phase commit and XA resource coordination.

Distributed SystemsUpdated 1 min readhistorical

This is a historical learning note and may contain outdated or incomplete understanding.

1. Two-Phase Commit

2PC coordinates multiple transactional resources through two stages:

  1. Prepare: every participant durably reaches a state from which it can commit if instructed.
  2. Decision: the transaction manager records and communicates commit or rollback.

2. Main Costs

  • prepared participants can retain locks/resources while waiting;
  • transaction latency includes cross-node coordination and durable logging;
  • coordinator and participant recovery logic must preserve the final decision across crashes.

The important issue is not merely a “single point of failure”: a production transaction manager can itself be replicated. The hard part is safely recovering the global decision when failures occur mid-protocol.

3. XA

XA defines interfaces between the transaction manager and resource managers so multiple XA-capable databases/resources can participate in one 2PC transaction.

Use XA when the participating resource stack supports it and global atomic commit is worth the coupling and latency cost.

Loading helpful count