SQS + Lambda Asynchronous Processing Architecture
Queue requests in Amazon SQS and process them asynchronously with AWS Lambda — an architecture explained for beginners.
Architecture diagram
AWS services used
Click a service name to review it on the term detail page.
Overview
This architecture queues processing requests in Amazon SQS first, then processes them asynchronously in order using AWS Lambda.
If you complete heavy processing on the spot when receiving user actions or external system requests, responses become slow and the user experience degrades when processing fails.
By placing SQS in between, you can decouple the receiving process from the execution process. This is important from the perspectives of loose coupling, scalability, and fault tolerance.
Architecture Diagram
flowchart TD
User[User / External System]
API[API Gateway / Application]
Queue[(Amazon SQS Queue)]
DLQ[(Dead Letter Queue)]
Lambda[AWS Lambda Worker]
DDB[(DynamoDB / Storage)]
CW[CloudWatch Logs]
IAM[IAM Role]User -->|Request| API
API -->|Send Message| Queue
Queue -->|Event Trigger| Lambda
Lambda -->|Store Result| DDB
Lambda -->|Output Logs| CW
Queue -->|Exceeds Max Receive Count| DLQ
IAM -.-> Lambda
IAM -.-> Queue
```
What This Architecture Achieves
| Item | Details |
|---|---|
| Asynchronous Processing | Separates user response from heavy processing |
| Loose Coupling | Receiving side and processing side are not directly dependent |
| Retry | SQS can redeliver messages when Lambda processing fails |
| Fault Isolation | Failed messages can be moved aside to a DLQ |
| Scaling | Lambda can process based on the amount queued |
AWS Services Used
| Service | Role |
|---|---|
| Amazon SQS | Queue that stores messages awaiting processing |
| AWS Lambda | Execution platform that processes SQS messages |
| Dead Letter Queue | Destination for messages that have failed a defined number of times |
| Amazon DynamoDB | Storage destination for processing results and state |
| Amazon CloudWatch Logs | Reviewing Lambda processing logs |
| IAM | Permissions for Lambda to access SQS and DynamoDB |
Request Flow
- The user or external system sends a request to the API
- The API or application sends a message to SQS
- The message is stored in SQS
- Lambda receives the SQS event and processes it
- The processing result is saved to DynamoDB or similar
- Processing logs are output to CloudWatch Logs
- Messages that fail the defined number of times are sent to the DLQ
Design Considerations
Availability
Because SQS holds processing requests, messages are unlikely to be lost even if Lambda or downstream processing temporarily fails.
Setting up a DLQ allows you to investigate failed messages later.
Security
The Lambda execution role permits only reading from the target SQS queue, writing to the target DynamoDB table, and outputting to CloudWatch Logs.
The entities allowed to send messages to SQS are also restricted via IAM.
Cost
Because SQS and Lambda are pay-per-use, you can build a configuration without always-on servers.
However, if failed processing causes the same message to be retried many times, the number of Lambda executions increases. Configure the maximum receive count and DLQ to avoid near-infinite retries.
Performance
Even if a large volume of processing requests arrive, you can queue them in SQS and process them in order.
By controlling Lambda concurrency, you can design the system so that downstream DynamoDB or external APIs are not overloaded.
SAA Exam Focus
- SQS can be used to build loosely coupled architectures
- SQS + Lambda is an option for asynchronous processing
- Use a DLQ to move aside failed messages
- SQS can be used as a buffer to absorb sudden spikes in requests
- Consider FIFO queues when order guarantee is required
Caveats for This Architecture
- Implement idempotency to prepare for duplicate message processing
- Do not set the visibility timeout shorter than the Lambda processing time
- Without a DLQ, investigating failed messages becomes difficult
- Setting Lambda concurrency to unlimited concentrates load on downstream services
- FIFO queues have different throughput characteristics than standard queues — use them only when order guarantee is required
Related Terms
Related Comparisons
Summary
SQS + Lambda is a representative pattern for implementing asynchronous processing in a serverless manner.
For SAA, when you see conditions like "defer processing," "absorb sudden increases in requests," or "loosely couple components," consider an architecture that uses SQS.
Explore more AWS architectures
For the SAA exam, understanding AWS as architecture patterns matters more than memorizing individual services.
Related architectures
Static Hosting
S3 + CloudFront Static Website Architecture
Explains the baseline architecture for delivering a static site placed in S3 quickly and securely through CloudFront.
Serverless
API Gateway + Lambda + DynamoDB Serverless API Architecture
A foundational serverless API architecture that uses API Gateway as the entry point, executes processing in Lambda, and stores data in DynamoDB. Suited for contact forms and small-scale APIs.
Three Tier
Three-Tier Web Application Architecture in a VPC
A foundational three-tier web app architecture on AWS that separates the web, application, and database layers across Public Subnets, Private Subnets, and Database Subnets.