# The saga pattern on AWS: orchestrate it in Step Functions, or choreograph it with events

> Orchestrate a saga in a Step Functions Standard workflow when every step and undo must be auditable in one place. The two lines that make compensations work, the execution name that stops duplicate sagas, and when choreography is worth its debugging cost.

- Canonical: https://www.alpacamango.com/docs/saga-pattern-step-functions
- Author: Space Dog Vin
- Published: 2026-11-26 · Updated: 2026-11-21
- Topics: AWS, Event-driven, Architecture

**If an order touches three services and three databases, and someone will one day ask "why was this customer charged but never shipped?", orchestrate the saga in a Step Functions Standard workflow. Every step, every failure and every undo is then recorded in one execution history. Choreograph it with events instead only when separate teams own the steps and have agreed to debug across each other's logs, because that is the price.**

## What a saga gives you, and what it does not

A saga replaces one database transaction you cannot have with a chain of local ones: reserve stock, take payment, book the courier. Identify the steps that can be undone and design a compensation for each. This example compensates completed steps in reverse order. If a payment times out after possibly charging the customer, reconcile it by payment key before treating it as a failure. Two things are missing compared with a real transaction, and both decide the design.

- **No isolation.** Between "stock reserved" and "payment failed", other requests can see the reservation. Mark records as pending (a semantic lock) so nothing else acts on half-finished work.
- **No guarantee that an undo runs once.** Retries and redelivery mean every participant, and every compensation, must be safe to call twice. [Idempotent consumers on SQS and Lambda](/docs/idempotent-consumers-sqs-lambda) covers the techniques.

## Orchestration: the state machine is the audit trail

In Step Functions the saga is a state machine. Each forward step is a Task with a `Catch` that jumps to the compensation for the work done so far, and the compensations chain backwards to a `Fail` state. Choose a Standard workflow, not Express. Standard runs each state exactly once unless you ask for retries, keeps the execution history for 90 days, can run for up to a year, and is the only type that can pause on `.waitForTaskToken` for a person or an outside system. Asynchronous Express is at least once, while Synchronous Express is at most once. Both have a five-minute limit and rely on CloudWatch Logs for execution history.

Two lines in each step carry most of the design:

```json
"TakePayment": {
  "Type": "Task",
  "Resource": "arn:aws:states:::lambda:invoke",
  "Parameters": { "FunctionName": "take-payment", "Payload.$": "$" },
  "ResultPath": "$.payment",
  "Catch": [{ "ErrorEquals": ["States.ALL"], "ResultPath": "$.error", "Next": "ReleaseStock" }],
  "Next": "BookCourier"
},
"ReleaseStock": {
  "Type": "Task",
  "Resource": "arn:aws:states:::lambda:invoke",
  "Parameters": { "FunctionName": "release-stock", "Payload.$": "$" },
  "Retry": [{ "ErrorEquals": ["States.ALL"], "MaxAttempts": 20, "BackoffRate": 2, "MaxDelaySeconds": 300, "JitterStrategy": "FULL" }],
  "ResultPath": null,
  "Catch": [{ "ErrorEquals": ["States.ALL"], "ResultPath": "$.undoError", "Next": "AlertOnCall" }],
  "Next": "CancelOrder"
}
```

`"ResultPath": "$.error"` is the one people forget. Without it, a catcher replaces the state's whole input with the error, so `ReleaseStock` receives only the error instead of the order it is meant to undo. The long `Retry` on the compensation is deliberate too: a forward step may give up, but an undo that gives up leaves the books wrong. Retry it for minutes, and if it still fails, end in a state that raises an alarm for a person rather than one that quietly fails.

## Name the execution after the order

The cheapest protection against a double-submitted checkout costs one argument. Start each saga with the order ID as the execution name:

```bash
aws stepfunctions start-execution \
  --state-machine-arn "$SAGA_ARN" \
  --name "order-81723" \
  --input file://order.json
```

For a Standard workflow, a second start with the same name and input while the first is running just returns the first execution. Once that execution has finished, or if the input differs, the call fails with `ExecutionAlreadyExists`, and the name stays reserved for 90 days. A retried API request or a redelivered message therefore cannot start a second saga for the same order. Express workflows do not do this, which is one more reason to keep sagas on Standard.

## When choreography is the better answer

In a choreographed saga there is no coordinator. The order service publishes `OrderPlaced` to an EventBridge bus, the stock service reacts and publishes `StockReserved`, and each service listens for the failure events it must undo. AWS's guidance suits it to sagas with few participants, and it has no central workflow to fail or to bottleneck. It suits organisations where the payment team will not let another team's state machine call its API directly.

The cost is that the saga exists only as a pattern of events. Nobody can open one page and see where order 81723 stopped, so you need a correlation ID on every event, an EventBridge archive to replay from, and tracing across services before the first incident. Each service must also publish its event reliably after its own write; the [transactional outbox with DynamoDB Streams](/docs/transactional-outbox-dynamodb-streams) is how. As the number of participants grows, especially if compensation needs an audit trail, a single execution history becomes more valuable.

A third option has arrived on AWS: Lambda durable functions, which express the same saga as ordinary code with checkpointed steps. [Step Functions or Lambda durable functions](/docs/step-functions-or-lambda-durable-functions) compares the two.

## On Google Cloud and Azure

Google Cloud Workflows is the nearest equivalent: a YAML workflow with `try`, `retry` and `except` blocks, where compensations sit in the `except` branch, and an execution can last a year. On Azure, Durable Functions writes the orchestrator as code; compensation is a `try`/`catch` that calls the undo activities, and the framework replays the history to recover. Choreography maps to Eventarc with Pub/Sub on Google Cloud and Event Grid or Service Bus on Azure. The trade-off is the same on all three.

## The diagram

An orchestrated order saga: Step Functions calls the order, stock and payment services in turn, and when payment fails it runs the stock and order compensations in reverse before ending in Fail. [Open it in archhy](https://archhy.com/d/TdygLcMQOiTg?utm_source=alpacamango) and make a copy to map your own steps and their undos.

Reference documentation: [Workflow types](https://docs.aws.amazon.com/step-functions/latest/dg/choosing-workflow-type.html), [Catch and retry behaviour](https://docs.aws.amazon.com/step-functions/latest/dg/concepts-error-handling.html), [StartExecution idempotency](https://docs.aws.amazon.com/step-functions/latest/apireference/API_StartExecution.html), [Workflows quotas](https://docs.cloud.google.com/workflows/quotas), [Azure Durable Functions error handling](https://learn.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-error-handling).
