Architectural Patterns for Serverless Applications with AWS Lambda
Instruction: Describe some common architectural patterns for serverless applications using AWS Lambda and explain the scenarios in which each pattern is most applicable.
Updated
Official answer
Choose the pattern from the work's response and consistency requirements:
- Request/response API: API Gateway and Lambda for bounded interactive operations. Keep durable state outside the execution environment and protect dependencies with admission control.
- Queued worker: SQS and a Lambda event source mapping for burst buffering and controlled asynchronous processing. Use idempotent handlers, visibility settings and a redrive/replay policy.
- Object processing: S3 notifications for uploads such as thumbnail generation. Prevent output-trigger loops and handle duplicate/versioned object events.
- Stream projection: Kinesis or DynamoDB Streams for ordered processing within the source's ordering scope. Plan for lag, duplicate records and poison batches.
- Orchestrated workflow: Step Functions for explicit steps, timeouts, retries and compensation. Compensation is a business action, not an automatic rollback of every external side effect.
- Web frontend: A static site delivered through an appropriate hosting/CDN setup, with an authenticated API backend. Public asset caching and private user data require different access rules.
For example, a purchase API can validate and durably accept an order, then queue fulfillment and expose job status. The accepted response should not claim shipment or payment completed. Keep state transitions and event publication reliable, such as through an outbox/change-stream design, and make consumers replay-safe.
Compare latency, sustained throughput, execution limits, failure recovery and total cost. A long-running or continuously CPU-intensive job may fit a container or batch service better than a Lambda invocation.