The Saga pattern in practice: compensations, pivots and the hard parts

16 November 2026 · 10 min read · Luka Engels

How the Saga pattern replaces one database transaction with a chain of local ones, why the pivot step matters most, and what goes wrong in production, with an AWS (Amazon Web Services) Step Functions example.

In a monolith with one database, a business operation runs inside a single ACID (Atomicity, Consistency, Isolation, Durability) transaction. Either everything commits or nothing does. Once each service owns its own database, that guarantee is gone.

A distributed two-phase commit is technically possible, but it locks resources across services, needs every participant to be online at the same time, and most cloud services don't support it at all. DynamoDB doesn't, Amazon Simple Queue Service doesn't, and neither do typical payment providers.

A Saga replaces that one big transaction with a sequence of local transactions. Each one commits on its own. If a later step fails, the earlier steps are undone by compensating transactions. You give up immediate consistency and get eventual consistency with an explicit, business-level undo.

The idea is older than microservices. Hector Garcia-Molina and Kenneth Salem described it in their 1987 paper "Sagas", written for long-lived database transactions. In the overview of 20 cloud design patterns it's pattern D1, next to its partner D2, Compensating Transaction. This article goes into the detail that an overview has to skip.

Three kinds of steps

This is the most useful idea when you design a real Saga. Every step belongs to one of three categories:

  1. Compensatable steps come before the point of no return, and each has an undo action. Examples are "reserve stock" (undo: release the stock) and "authorise payment" (undo: void the authorisation).
  2. The pivot step is the go or no-go decision. Once it commits, the Saga must complete. Examples are "capture payment" and "sign contract".
  3. Retriable steps come after the pivot. They have no undo action and must not fail permanently, so they are retried until they succeed. Examples are "send confirmation email" and "update search index".

Design rule: order the steps so that risky steps, the ones likely to fail, run early while they can still be compensated. Only steps that are guaranteed to succeed belong after the pivot.

Try it: a rental onboarding Saga

The running example in this article is a rental contract onboarding in proptech. It has five steps:

  1. Reserve the property, so the listing shows as "under offer". Compensatable.
  2. Run the tenant credit check. Compensatable.
  3. The tenant signs the contract. This is the pivot.
  4. Collect the deposit. Retriable.
  5. Update the listing portals. Retriable.

Retrying covers a payment service that is briefly unavailable. A tenant who never pays is a business process, such as a reminder and dunning procedure, not a compensation.

If the credit check fails, or the tenant doesn't sign within seven days, the Saga discards the credit check and releases the reservation, so the listing goes back on the market. A timeout counts as a failure too.

Click a scenario and watch what gets undone.

The four scenarios cover the cases that matter. On the happy path every step commits. A failed credit check compensates the one step before it. When the tenant doesn't sign, the failure is at the pivot itself, so everything before it is compensated. A flaky deposit service fails after the pivot, so it is retried and never compensated.

Choreography versus orchestration

Someone has to decide which step runs next. There are two ways to do that.

Comparison diagram. Left, choreography: the Order, Inventory and Payment services publish to and subscribe from a shared event bus such as EventBridge or Kafka. Right, orchestration: a central Saga orchestrator holds the state machine, sends commands to the Order, Inventory and Payment services and receives their replies.

Choreography: no central coordinator

Each service listens for events and reacts by doing its local work and publishing the next event.

Order Service      → publishes OrderCreated
Inventory Service    hears OrderCreated  → reserves stock → publishes StockReserved
Payment Service      hears StockReserved → charges card  → publishes PaymentFailed
Inventory Service    hears PaymentFailed → releases stock
Order Service        hears PaymentFailed → marks order Cancelled

Orchestration: a central coordinator

An orchestrator holds the state machine and tells each service what to do with commands.

Practical rule: start with choreography for simple reactions. Switch to orchestration once a flow has more than about four steps, needs timeouts, or has to be explainable to people who aren't engineers.

Where Sagas are used

1. E-commerce order fulfilment

The textbook case. Create the order, reserve inventory, authorise the payment, capture the payment (pivot), schedule the shipment, send a confirmation. If the payment authorisation fails, release the inventory and cancel the order.

2. Travel booking

Book a flight, book a hotel, book a rental car. If the car rental fails, cancel the hotel and the flight. This is the example most often used to explain Sagas. Compensations here often carry business costs, such as cancellation fees, which is why compensation is a business decision, not a technical rollback.

3. Banking and payments

A transfer between accounts held in different systems: debit the source account, credit the target account, notify both parties. The compensation is a reversing booking, never a delete, because ledgers are append-only. This fits naturally with Event Sourcing.

4. Insurance claims

Register the claim, verify policy coverage, run a fraud check, wait for the assessor's approval (a human step that can take days), pay out, close the claim. Long-running Sagas with human steps are where orchestration with durable timers really pays off, for example Step Functions with task tokens, or Temporal.

5. Proptech: rental contract onboarding

The running example from the demo above. Reserve the property, run the credit check, the tenant signs (pivot), collect the deposit, update the listing portals. A failed credit check or a missing signature after seven days releases the property again.

6. Customer and account provisioning in SaaS (Software as a Service)

Create the tenant, provision a database or schema, create the admin user in the identity provider, set up the billing subscription, send a welcome email. If identity provisioning fails, drop the schema and delete the tenant record. This is common after acquisitions, when accounts have to be created across several merged platforms.

7. Agentic workflows

An AI agent run that creates side effects across tools has the shape of a Saga, whether it was designed as one or not: several local steps and no transaction spanning them. What it lacks, unless someone adds them, are the compensations. For example: create a branch, generate code, open a pull request, link the ticket, notify the team channel. If the review agent rejects the change, the compensations are closing the pull request, deleting the branch and reverting the ticket status.

Treating agent tool calls as Saga steps with explicit compensations means a failed agent run leaves a clean state instead of orphaned branches and half-updated tickets. Orchestration fits best here, because the agent harness already acts as the orchestrator.

Implementation with Step Functions and the CDK (Cloud Development Kit)

Here is the rental onboarding Saga as a Step Functions state machine, defined with the AWS CDK in TypeScript. Three mechanisms do the work:

The code type-checks with tsc --strict against aws-cdk-lib 2.277.0. This example shows the control flow. Production code also needs durable recovery and escalation for failed compensations, plus idempotency in every handler. Step Functions also gives you a visual execution history, so "where is this onboarding stuck?" can be answered in the console.

The hard parts

The diagrams make Sagas look tidy. These seven things are where they go wrong in production.

1. Idempotency everywhere

Messages get delivered twice and orchestrators retry. Every step and every compensation must be safe to run more than once. Pass the Saga ID plus the step name as an idempotency key and store the keys you have processed, for example in DynamoDB with a conditional write.

2. The dual-write problem

A service must update its database and publish an event. If it crashes between the two, the Saga stalls or diverges. The fix is the Transactional Outbox: write the event into an outbox table in the same local transaction, then publish it from there. Change data capture, such as DynamoDB Streams or Debezium for PostgreSQL, or a polling relay can do the publishing.

3. Missing isolation

A Saga gives up the "I" in ACID. Other requests can see intermediate states: a second tenant might see a property as available while the first tenant's Saga is still running. Countermeasures:

4. Compensations can fail too

A refund call can time out. Compensations must be retriable and must not give up. When one finally can't succeed, route it to a dead-letter queue and alert a human. Always design a path for manual intervention.

5. Not everything can be undone

A sent email or text message can't be unsent. Either move such steps after the pivot, or compensate semantically with a "sorry, your booking was cancelled" email.

6. Timeouts are failures

A step that never answers is worse than one that fails. Each step needs a timeout and an explicit recovery path. Before the pivot, that can mean compensation. After the pivot, retry or escalate for manual intervention. Long-running Sagas need durable timers, not an in-memory setTimeout.

A timeout does not prove that nothing happened, though. The call may have succeeded and only the response got lost. In the example, the payment provider may have collected the deposit even though the Saga never heard back, and a retry without an idempotency key charges the tenant twice. So the first move after a timeout is to find out what the participant actually did. A retry with the same idempotency key is safe, because a step that already ran returns its original result instead of running again. Where a participant offers a status query by that key, it answers the question directly. If neither settles it, mark the step as in doubt and let a reconciliation job compare both sides later, rather than guessing in either direction.

7. Observability

Propagate a correlation ID, the Saga ID, through every message and log line. Store the Saga state (current step, status, history) so support can answer "what happened to this order?" With choreography, distributed tracing with OpenTelemetry or AWS X-Ray is close to mandatory.

When not to use a Saga

How it connects to the other patterns

The Saga sits in the middle of several patterns from the overview of 20 cloud design patterns:

Further reading