AWS Lambda

AWS Lambda is a serverless function platform (Functions-as-a-Service). You deploy a handler, and AWS runs it on demand in response to events — HTTP requests, queue messages, schedules, object uploads — scaling automatically and billing only for the compute you use. There are no servers to provision or patch.

It excels as event-driven glue and for bursty workloads, but it rewards a particular discipline: stateless handlers, short run times, and an awareness of concurrency's downstream effects. For the broader design patterns, see Serverless Architecture Patterns.

TL;DR

Quick Example

A handler receives an event and returns a response — AWS handles the rest:

How Lambda Works

You write a function handler; AWS runs it in a managed runtime, triggered by events:

Packaging & Deployment

Either way, keep the handler small and push heavy logic into shared libraries or downstream services.

Concurrency & Backpressure

Lambda scales concurrency fast — which is great until it overwhelms something downstream. The classic failure mode:

⚠️ Traffic spike → hundreds of concurrent Lambdas → database connection pool exhausted → cascading failures.

Mitigations:

Common Use Cases

See Message Queues.

Best Practices

Common Mistakes

Non-idempotent handler on retry

Reconnecting to the database per invocation

FAQ

How do I deal with cold starts?

A cold start is the latency when Lambda initializes a new execution environment. Reduce it by keeping deployment packages small, initializing SDK/DB clients at module scope (so they're reused on warm invocations), choosing a lean runtime, and — for latency-critical paths — enabling provisioned concurrency to keep instances warm.

Does Lambda guarantee exactly-once execution?

No. Depending on the trigger, events can be delivered more than once and functions can be retried on failure. Design idempotent handlers that dedupe on a stable key, so reprocessing the same event is harmless. Never assume exactly-once delivery.

When should I NOT use Lambda?

For long-running tasks (beyond the timeout), steady high-throughput workloads (where always-on compute is cheaper), workloads needing persistent connections or large in-memory state, and anything that hammers a connection-limited database without a proxy. In those cases use ECS/Fargate, EC2, or a queue-plus-worker design.

How do I keep Lambda from overwhelming my database?

Cap reserved concurrency, put an SQS queue in front to buffer bursts, use a connection proxy (RDS Proxy) or serverless-native driver, and cache read-heavy paths. The goal is to decouple Lambda's fast scaling from the database's finite connection capacity.

Related Topics

References