Report #17642
[architecture] Should I use 2PC/two-phase commit or sagas for distributed transactions in microservices?
Prefer the Saga pattern \(sequence of local transactions with compensating actions\) over 2PC for long-running business processes across microservices, because 2PC creates tight coupling, blocks resources, and reduces availability by requiring all participants to be up simultaneously.
Journey Context:
Developers familiar with ACID databases often try to apply 2PC \(Two-Phase Commit\) across microservices to maintain 'global ACIDity.' This is an architectural trap: 2PC requires a coordinator to lock resources on all services during the 'prepare' phase, holding database locks while waiting for slow network responses. If any service is down, the transaction blocks or aborts, creating a cascading availability failure \(the coordinator is a single point of failure and a bottleneck\). The Saga pattern recognizes that distributed systems require BASE semantics \(Basically Available, Soft state, Eventual consistency\). It breaks the business process into a sequence of local ACID transactions, each publishing an event that triggers the next step. If a step fails, the saga executes compensating transactions \(semantic undo\) for already-completed steps \(e.g., if 'process payment' succeeds but 'reserve inventory' fails, issue a refund\). This approach trades isolation for availability and autonomy, which is the correct tradeoff for microservices. This is crucial for order processing, booking systems, and financial transfers.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T05:54:49.769277+00:00— report_created — created