Distributed Transactions
Distributed transactions coordinate writes across multiple databases or services so they either all commit or all abort, maintaining data consistency. They introduce protocols like two-phase commit and saga patterns that trade off between consistency, availability, and complexity.
itDistributed systems, messaging, and integration | OpenSkills.info
Course pathWalk it in order
Look it upDip in anytime
Go furtherLeaves this page
Don't Panic
Don't Panic — Distributed Transactions
A distributed transaction is what happens when one business decision insists on visiting several independent systems and then expects them to behave like one database. This is a reasonable ambition. It is also where the network begins filing objections in triplicate.
The job is not to make every request arrive. The job is to preserve a business invariant when inventory, payment, and an order record do not share one local transaction. A crash between two successful actions leaves a partial story behind. Retrying without a stable identity can write the sequel twice.
The first useful distinction is between the business operation and the local transaction. A local transaction can make its own changes atomic. A coordinator, message flow, or recovery record must connect those local outcomes. The awkward surprise is that a timeout reports only that somebody stopped waiting. It does not announce whether the distant participant committed, aborted, or is now contemplating its paperwork.
Two-phase commit pursues one all-or-nothing outcome. Participants prepare durable state, then wait for a recorded decision to commit or abort. That protects atomicity, but prepared work can retain locks and wait when the decision is unavailable. It is a serious guarantee with a serious bill attached.
A saga chooses a different bargain. Each service commits its own step, and a later failure starts compensating transactions for earlier work. A refund, for example, is not an eraser for a charge; it is another durable business action. This is why compensation, retries, and progress tracking need design work rather than a hopeful catch block.
The transactional outbox handles a smaller but common nuisance: a database update that must cause a message. Store the business change and message intent in one local transaction, then let a relay publish later. Delivery can repeat, so consumers still need idempotency.
Read the intro for the full map of 2PC, XA, sagas, and outboxes. Use the slides when comparing failure paths, the cheatsheet when reviewing a design, and the practice reference when turning an invariant into a recovery ledger. The quiz is there to ensure that timeouts have not quietly become verdicts.
Where this skill leads
Relevant careers
See how this topic contributes to broader role-level skill maps.
Sources
- https://www.ibm.com/docs/en/txseries/11.1.0?topic=processing-two-phase-commit-process
Supports
- Distributed transactions spanning processes and machines
- Coordinator and participant roles
- Recoverable process logs
- Prepare votes, durable promises, and final resolution
- Atomic commit despite component and communication failures
- https://www.ibm.com/docs/en/iis/11.5.0?topic=overview-distributed-transaction-processing-model
Supports
- X/Open application, transaction manager, and resource manager roles
- XA as the transaction-manager and resource-manager interface
- Prepare and commit phase behavior
- https://www.postgresql.org/docs/current/sql-prepare-transaction.html
Supports
- PostgreSQL prepared transaction behavior and recovery commands
- External transaction manager as the intended caller
- Prepared transactions retaining locks and delaying storage cleanup
- Recommendation to resolve prepared transactions promptly
- https://www.postgresql.org/docs/current/two-phase.html
Supports
- PostgreSQL support for two-phase commit
- Relationship to the X/Open XA model
- Inspection of prepared transactions
- https://www.microsoft.com/en-us/research/publication/consensus-on-transaction-commit/
Supports
- Relationship between consensus and transaction commit
- Ordinary two-phase commit blocking behavior
- Two-phase commit as lacking coordinator fault tolerance
- Paxos Commit using consensus for participant outcomes
- 2004 Paxos Commit publication
- https://learn.microsoft.com/en-us/azure/architecture/patterns/saga
Supports
- Saga as a sequence of local transactions
- Compensable, pivot, and retryable steps
- Choreography and orchestration coordination styles
- Saga benefits, drawbacks, and observable intermediate states
- Choreography dependency and integration-testing tradeoffs
- https://learn.microsoft.com/en-us/azure/architecture/patterns/compensating-transaction
Supports
- Compensation as application-specific recovery work
- Compensation ordering, parallelism, idempotency, and resumption
- Compensation failure and manual intervention
- Compensation not necessarily restoring the exact starting state
- https://docs.aws.amazon.com/prescriptive-guidance/latest/cloud-design-patterns/transactional-outbox.html
Supports
- Database-and-message dual-write failure modes
- Atomic storage of business data and outgoing message intent
- Outbox table and relay architecture
- Duplicate messages, ordering, and idempotent consumers
- Saga orchestration for operations spanning service data stores
- https://dl.acm.org/doi/10.1145/321921.321930
Supports
- 1976 distributed database transaction model milestone
- https://www.microsoft.com/en-us/research/publication/notes-on-data-base-operating-systems/
Supports
- 1978 transaction processing foundations milestone
- https://dl.acm.org/doi/10.1145/7239.7266
Supports
- 1986 R* distributed transaction management milestone
- https://dl.acm.org/doi/10.1145/38713.38742
Supports
- 1987 Sagas paper and compensating transaction model
- https://pubs.opengroup.org/onlinepubs/009680699/toc.pdf
Supports
- X/Open distributed transaction processing reference model
- https://ieeexplore.ieee.org/document/344004
Supports
- 1993 two-phase commit optimization comparison
- https://camunda.com/blog/2018/08/bpmn-microservices-orchestration-part-2-graphical-models/
Supports
- 2018 orchestration and compensation milestone
- https://arxiv.org/abs/2302.12517
Supports
- 2023 analysis of two-phase commit critical-path overhead
- https://pages.temporal.io/rs/250-WIU-007/images/tech-guide-saga-pattern-made-easy.pdf
Supports
- Retriable and idempotent saga compensation
- https://docs.aws.amazon.com/prescriptive-guidance/latest/modernization-data-persistence/saga-pattern.html
Supports
- AWS Step Functions as a saga orchestration example
- https://en.dtm.pub/
Supports
- DTM support for saga, XA, TCC, and transactional messages
