Saga Pattern with AWS Lambda Durable Functions in Python

Lambda (Durable) → Orders Table → Inventory Table → Payments Table

Multi-step order processing with automatic compensating transactions on failure using Lambda durable functions and Amazon DynamoDB.

This pattern implements the Saga pattern using AWS Lambda durable functions to orchestrate a multi-step order workflow.
Three checkpointed steps execute in sequence: reserve inventory, process payment, and confirm order.
If any step fails, compensating transactions automatically execute in reverse order to restore data consistency — cancelling payment and releasing inventory.
Each step uses @durable_step for automatic checkpointing. If interrupted, the function resumes from the last completed step without re-execution.
IAM permissions follow least privilege with DynamoDBCrudPolicy scoped to each specific table.

< Back to all patterns

GitHub icon Download this pattern (.zip)

GitHub icon View this pattern on GitHub


Clone repo

git clone https://github.com/aws-samples/serverless-patterns/cd serverless-patterns/lambda-durable-saga-python-sam

Deploy

sam buildsam deploy --guided


Testing

See the GitHub repo for detailed testing instructions.

Cleanup

Delete the stack: sam delete.

Created by:

Ajaya Shrestha

Cloud Support Engineer at AWS specializing in Lambda and serverless architectures.