Distributed Transactions

Summary: Transactions that span multiple nodes or heterogeneous data systems, aiming to provide the same safety guarantees as local transactions.

Sources: chapter9, chapter12

Last updated: 2026-04-18


In a distributed environment, ensuring atomicity across multiple nodes is challenging because any node can fail or delay responses.

Types

  1. Database-internal Transactions: Managed within a single distributed database (source: chapter9, p. 361).
  2. Heterogeneous Transactions: Spanning two or more different systems, such as a relational database and a message broker (source: chapter9, p. 361).

Challenges

  • Failure Modes: Unlike local transactions, a distributed transaction must account for network delays and partial failures (source: chapter9, p. 362).
  • Two-Phase Commit (2PC): The classic algorithm for achieving distributed atomic commit. However, 2PC is often slow and can block indefinitely if the coordinator fails (source: chapter9, p. 363).
  • XA (eXtended Architecture): A standard interface for two-phase commit across heterogeneous systems (source: chapter9, p. 365).

Alternatives

Because distributed transactions can be fragile and slow, many systems prefer:

  • idempotence: Designing operations so they can be safely retried (source: chapter12).
  • event-sourcing: Using a sequence of events to maintain state across services (source: chapter11).
  • Compensating Transactions: Explicitly undoing operations in case of failure.