Skip to content

Add Saga Pattern and Human in the Loop Implementation with Lambda durable functions and CDK#2939

Open
tafaman wants to merge 3 commits intoaws-samples:mainfrom
tafaman:main
Open

Add Saga Pattern and Human in the Loop Implementation with Lambda durable functions and CDK#2939
tafaman wants to merge 3 commits intoaws-samples:mainfrom
tafaman:main

Conversation

@tafaman
Copy link

@tafaman tafaman commented Feb 9, 2026

Summary

This PR introduces two production-ready workflow patterns using AWS Lambda durable functions, demonstrating the power and flexibility of durable execution for complex serverless workflows.

Patterns Included

  1. Saga Pattern (Python)- Distributed Transaction Coordination
    A complete implementation of the Saga pattern for distributed transactions, demonstrating coordinated travel bookings (flight, hotel, car) with automatic compensating transactions on failure.

  2. Human-in-the-Loop (Node.js) - Approval Workflows
    A secure approval workflow pattern integrating human decision-making into serverless processes, using a realistic document submission and approval scenario.

Pattern 1: Saga Pattern

What It Does
Coordinates distributed transactions across multiple services with automatic rollback on failure. Uses a travel booking scenario where flight, hotel, and car reservations must all succeed or all be cancelled.

Key Features

  • Sequential Execution: Services invoked in order (flight → hotel → car)
  • State Tracking: Each successful operation tracked by the orchestrator
  • Compensating Transactions: Automatic rollback in reverse order on failure
  • Failure Simulation: Built-in failure flags for testing different scenarios

Infrastructure (CDK)

  • Lambda Functions: 7 functions total
  • 1 saga orchestrator (durable function) with 1-hour execution timeout
  • 6 service functions (reserve/cancel for flight, hotel, car) with 1-minute timeout
  • DynamoDB Tables: 3 tables for flight bookings, hotel reservations, and car rentals
  • Pay-per-request billing mode
  • CloudWatch Log Groups: Custom log groups for each function with 1-week retention
  • IAM Permissions: Properly scoped permissions for DynamoDB access and Lambda invocations

Pattern 2: Saga Pattern

Integrates human approval processes into serverless workflows. Demonstrates document submission (expense reports) requiring manager approval via email, with secure callback mechanism and automatic timeout handling.

Infrastrcuture (CDK)

  • Lambda Durable Function: Orchestrates the approval workflow
  • DynamoDB Table: Stores callback tokens with pay-per-request billing
  • SNS Topic: Sends formatted approval emails to managers
  • API Gateway: Handles callback requests from email links
  • Callback Handler: Looks up tokens and resumes execution

Workflow Steps

  1. Validate document submission
  2. Generate approval ID and store callback token in DynamoDB
  3. Send formatted approval email via SNS
  4. Pause execution with waitForCallback() (no compute charges)
  5. Manager clicks approve/reject link
  6. Callback handler looks up token from DynamoDB
  7. Resume durable execution with decision
  8. Process approval/rejection

…mentation for distributed transactions. New features include:

- travel booking system coordinating flight, hotel, and car reservations
-  saga orchestrator Lambda function with automatic compensating transactions
- individual service functions for flight, hotel, and car reservations with cancellation
@bfreiberg bfreiberg added the durable functions Pattern for AWS Lambda durable functions label Feb 10, 2026
@tafaman
Copy link
Author

tafaman commented Feb 16, 2026

Added Human in the loop Durable functions pattern for node.js

@tafaman tafaman changed the title Add Saga Pattern Implementation with Lambda Durable Functions and CDK Add Saga Pattern and Human in the Loop Implementation with Lambda durable functions and CDK Feb 16, 2026
…ect captilization. from Lambda Durable Functions to Lambda durable functions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

durable functions Pattern for AWS Lambda durable functions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants