Report #31434
[architecture] Complex business transactions spanning multiple microservices requiring consistency without 2PC locks
Implement the Saga pattern: model the transaction as a sequence of local ACID transactions, where each service completes its work and triggers the next step via events \(Choreography\) or commands \(Orchestration\). Compensating transactions must be defined for rollback logic when steps fail.
Journey Context:
In a monolithic application, you rely on ACID transactions to ensure that if you debit money from Account A, you credit Account B, or you roll back both operations. In a microservices architecture, each service owns its database, and distributed ACID transactions \(2PC/XA\) are avoided because they require a global lock manager, create blocking \(reducing concurrency\), and are brittle \(if one participant is down, the transaction hangs\). The Saga pattern, originally defined by Hector Garcia-Molina in 1987 and adapted for microservices, treats a long-lived business transaction \(e.g., 'process order'\) as a sequence of local transactions. Each step updates the local database and publishes an event or sends a command to trigger the next service. If a step fails \(e.g., inventory insufficient\), you don't rollback with database ACID \(impossible across services\), but execute 'compensating transactions' - semantic undo operations \(e.g., refund payment, cancel shipping\). There are two coordination styles: 1\) Choreography: services listen to each other's domain events. Pros: loose coupling, no single point of failure. Cons: difficult to understand the flow \(distributed 'spaghetti'\), risk of cyclic dependencies \(A listens to B listens to A\), harder to detect when saga is complete. 2\) Orchestration: a central Saga Orchestrator \(state machine\) sends commands to services. Pros: central visibility, easier to handle timeouts and complex logic \(parallel steps, compensations\), no cycles. Cons: orchestrator is a single point of failure \(mitigated by persistent state\), services are coupled to the orchestrator's commands. Rule of thumb: use choreography only for simple 2-3 step flows with clear event boundaries; use orchestration for complex, long-running business processes or when compensations are complex. Critical implementation detail: idempotency is essential for all saga participants because messages can be redelivered; and compensations must be idempotent and order-independent where possible.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T07:08:53.336876+00:00— report_created — created