When a single database grows into multiple independent services, traditional ACID transactions break down. Two-phase commit (2PC) offers strong consistency but is a blocking protocol — a crashed coordinator leaves locks held across all participants, stalling the entire system. This is why 2PC is only practical inside tightly-coupled distributed databases like Google Spanner or YugabyteDB, not across independent services. The Saga pattern is the industry-standard alternative: break the work into a chain of local transactions, each committing independently, with compensating actions (refunds, cancellations) to undo completed steps when something fails downstream. Sagas can be implemented via choreography (services react to each other's events via pub/sub) or orchestration (a central orchestrator like Temporal or AWS Step Functions directs each step). Orchestration is preferred for complex flows because it provides centralized visibility and failure handling. Key engineering concerns include idempotent compensating actions, retry logic for failed compensations, and the dual-write problem — solved by the transactional outbox pattern, which atomically writes both data and outgoing events to the same database before a background process publishes them to the message broker.

14m watch time

Sort: