This project demonstrates how to implement the Outbox Pattern to guarantee consistency between database writes and event emissions in a distributed microservices architecture. Leveraging AWS services, Terraform infrastructure-as-code, and LocalStack for local testing, this setup ensures reliable, event-driven communication.
You can check technical blog here : How to Build an Event-Driven Outbox Pattern with AWS, Terraform and LocalStack
- Terraform
- LocalStack
- AWS CLI or
awslocal
CLI for LocalStack - Python 3.12+ (for Lambda code)
- Two DynamoDB tables:
orders
— main business dataorders.outbox
— stores event records with DynamoDB Streams enabled
- Lambda function triggered by DynamoDB Stream on
orders.outbox
- Lambda publishes events to an SQS FIFO queue
- Full infrastructure provisioning with Terraform
- AWS services emulated locally using LocalStack
- DynamoDB tables with streams for event tracking
- SQS FIFO queue for reliable message delivery
- Lambda functions to handle:
- Writing orders and events (outbox-lambda)
- Processing outbox events and sending to SQS (sync-event lambda)
- Robust error handling and retry logic in Lambda functions