Saga Pattern with AWS Lambda durable functions

AWS Lambda durable functions

Implement the saga pattern for distributed transactions using AWS Lambda durable functions with automatic compensating transactions.

This pattern demonstrates how to implement the saga pattern for distributed transactions using AWS Lambda durable functions. The example implements a travel booking system that coordinates flight, hotel, and car reservations with automatic compensating transactions (rollbacks) on failure.
The saga orchestrator is a durable Lambda function that invokes individual service functions sequentially. If any service fails, the orchestrator automatically executes compensating transactions in reverse order to maintain data consistency.
Durable functions track progress, automatically retry on failures, and can suspend execution for up to one year at defined points without paying for idle compute during waits.
This pattern deploys one durable Lambda function (orchestrator), six service Lambda functions (reserve/cancel for flight, hotel, car), three Amazon DynamoDB tables, and one Amazon SQS dead letter queue.

< 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/saga-pattern-lambda-durable-functions

Deploy

cd saga-pattern-cdknpm install./build-layer.shcdk bootstrap (first time only)cdk deploy


Testing

See the GitHub repo README for detailed testing instructions including success and failure scenarios.

Cleanup

Delete the stack: cdk destroy

Created by:

Ben Freiberg

Ben Freiberg

Ben is a Senior Solutions Architect at Amazon Web Services (AWS) based in Frankfurt, Germany.

Follow on LinkedIn