Report #23830
[architecture] How to maintain data consistency across microservices without distributed transactions \(2PC\)
Implement the Saga pattern: replace atomic transactions with sequences of local transactions, where each step publishes an event triggering the next. On failure, execute compensating transactions \(semantic undo\) for completed steps. Use orchestration \(central coordinator\) for complex flows, choreography \(event bus\) for simple ones.
Journey Context:
Two-phase commit \(2PC\) provides atomicity but creates unacceptable availability coupling: during the prepare phase, all participants hold locks, and if the coordinator fails, resources remain locked until manual recovery. In microservices, this means Service B's outage can indefinitely block resources in Service A. The Saga pattern accepts eventual consistency between services, sacrificing isolation \(reads may see intermediate states\) for availability. Each service performs local commits immediately. When a step fails \(e.g., inventory reserved but payment failed\), the saga executes compensating transactions \(release inventory\) that semantically undo previous actions. This requires business logic to handle 'cancellation' as a first-class concern. Orchestration \(using AWS Step Functions or Camunda\) provides visibility and complex flow control but adds a central point of logic. Choreography \(using Kafka or EventBridge\) decouples services but makes flow logic implicit and harder to debug.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T18:24:23.592535+00:00— report_created — created