AWS Serverless Architecture: How to Build It Well
AWS serverless architecture runs your code on Lambda and managed services instead of servers you own. Here is how the pieces fit, and the design choices that matter.
On this page
Short answer
AWS serverless architecture builds applications from managed services — Lambda functions for code, API Gateway for HTTP, DynamoDB or Aurora Serverless for data, and SQS and EventBridge for events — so you run no servers of your own. The provider scales each piece and bills per use, while your team owns the design: function boundaries, data access patterns, permissions and observability.
What is AWS serverless architecture?
AWS serverless architecture is a way of building applications on Amazon Web Services where you deploy code and configure managed services instead of provisioning servers. AWS Lambda runs your functions, API Gateway handles HTTP, DynamoDB or Aurora Serverless stores data, and SQS and EventBridge move events between services.
You still own the design. AWS runs the infrastructure, but your team decides how functions are split, how data is modelled, which permissions each function gets, and how you observe the system when something goes wrong.
| Piece | AWS service | What it does |
|---|---|---|
| Compute | Lambda | Runs code on demand |
| HTTP | API Gateway | Routes requests to functions |
| Data | DynamoDB, Aurora Serverless | Stores records and files |
| Files | S3 | Object storage |
| Queues | SQS | Buffers work between services |
| Events | EventBridge | Routes events by rule |
| Auth | Cognito, IAM | Identity and permissions |
| Deploy | SAM, CDK | Infrastructure as code |
The model fits workloads with uneven traffic: APIs that spike, file processing, scheduled jobs and event-driven workflows. It fits badly for long-running jobs, workloads that need persistent connections, and anything with heavy in-memory state.
How does a request flow through the stack?
A request flows through the stack in a short chain, and each step is a managed service. A user calls an API endpoint, API Gateway validates the request and routes it to a Lambda function, the function reads or writes data in DynamoDB, and the response travels back the same way.
Events follow a different path. A file uploaded to S3 triggers a Lambda function, which processes the file and writes the result to DynamoDB. A message placed on an SQS queue waits until a function is ready to process it, which smooths out spikes. EventBridge routes events between services by rule, so a new order can trigger an email, an inventory update and a report without the services knowing about each other.
The pattern to learn is that nothing calls a server directly. Every step is an event, a queue message or an API call, and each service scales on its own. That independence is what makes the architecture resilient, and it is also what makes debugging harder when a request fails halfway through.
How do you design the data layer?
You design the data layer around access patterns, not around tables. DynamoDB is a key-value and document store, so you start by listing the queries your application needs — get an order by id, list orders by customer, find overdue invoices — and then design keys and indexes that answer those queries directly.
Single-table design is the common pattern: several entity types share one table, distinguished by a key prefix, so one query can fetch an order and its line items together. It is efficient, but it is a learned skill; teams that design DynamoDB like a relational database end up with slow scans and high costs.
Aurora Serverless is the alternative when you need SQL. It is a managed relational database that scales capacity up and down with demand, so you keep joins and transactions without managing a database server. The trade-off is that it is not as fast to scale to zero as DynamoDB, and it costs more at low volumes. Choose by query pattern: known key-based access favours DynamoDB, ad-hoc relational queries favour Aurora Serverless.
How do you handle cold starts and limits?
Cold starts happen when Lambda has no warm execution environment ready and must start one, which adds delay to the first request. They matter most for user-facing APIs and least for background jobs, where a delay of a second is invisible.
Reduce them by keeping functions small, choosing a fast-starting runtime, and keeping deployment packages lean. For latency-sensitive endpoints, provisioned concurrency keeps a set number of environments warm, which removes the cold start at the cost of paying for idle capacity. Use it only where latency matters; applying it everywhere removes the cost advantage of serverless.
Limits shape design too. A Lambda function runs for a maximum of 15 minutes, so long jobs must be split into steps, often with Step Functions orchestrating them. Memory settings control both speed and cost: more memory means a faster CPU, so a function that runs twice as fast at twice the memory costs the same. Test memory sizes against real workloads instead of guessing.
Example: an order API on serverless
Example (hypothetical): a small ecommerce team builds an order API on AWS serverless. API Gateway receives the order request, a Lambda function validates it and writes the order to DynamoDB, an SQS queue carries the order to a second function that charges the payment, and EventBridge notifies the warehouse system.
Traffic is uneven: 50,000 orders a month, with most of them arriving in the first week. Each order takes about 200 milliseconds of function time across the two functions. Total compute is 50,000 orders times 0.2 seconds, which is 10,000 seconds, or about 2 hours and 47 minutes of function run time in the month. The team pays for those minutes, not for servers sitting idle between orders.
When a sale doubles traffic, nothing changes in the design: API Gateway and Lambda scale on their own, and the queue absorbs the burst so the payment function processes orders at a steady rate. The failure case is also contained. If the payment function fails, the message stays on the queue and is retried, instead of losing the order.
The team deploys with SAM, keeps each function to one job, and gives each function only the IAM permissions it needs. Observability comes from CloudWatch logs and X-Ray traces, so a slow order can be followed across all four services.
What are the common mistakes?
The most common mistakes are treating Lambda like a server, ignoring the data model, and giving functions broad permissions.
- One giant function. A single function that does everything is hard to test, slow to start and impossible to scale in parts. Split by job.
- Designing DynamoDB like SQL. Relational thinking leads to scans and high costs. Design from access patterns.
- Broad IAM permissions. A function that can read every table is a breach waiting to happen. Scope permissions per function.
- No idempotency. Queues retry, so a function that runs twice must not charge twice. Design every handler to be safe on retry.
- Ignoring timeouts. A function that calls a slow external API will hit its limit. Set timeouts and handle failures explicitly.
- No tracing. Without distributed tracing, a failed request across four services is nearly impossible to debug.
How to start: a six-step plan
You start with one small service, not a full re-architecture. A single API or a single background job teaches the team the model before the stakes get high.
- Pick one bounded service, such as an order API or a file processor, with clear inputs and outputs.
- Define the data access patterns first, then choose DynamoDB or Aurora Serverless to match them.
- Build the function small, with one job, and deploy it with SAM or CDK from the start.
- Give the function scoped IAM permissions and add tracing with X-Ray before launch.
- Load test with realistic traffic, including a burst, and watch cold starts and queue depth.
- Measure cost per request for a month, then decide whether the next service moves to serverless.
If your team is weighing serverless against containers, serverless best practices covers the decision points.
For the general model behind the AWS services, what is serverless architecture explains how it works.
For billing and scaling, what is serverless computing covers the basics.
Key takeaways
- Lambda runs code, API Gateway routes HTTP, DynamoDB stores data, SQS and EventBridge move events
- Design the data layer from access patterns, not from tables
- Keep functions small and single-purpose, and scope IAM permissions per function
- Queues retry by design, so every handler must be safe to run twice
- Start with one bounded service and measure cost per request before expanding
Frequently asked questions
When is AWS serverless a bad fit?
It is a bad fit for long-running jobs over 15 minutes, workloads that need persistent connections such as WebSockets with heavy state, and applications with large in-memory data. Containers or managed compute suit those better. It is also a poor fit when your team has no experience with distributed debugging.
How much does AWS serverless cost?
You pay per request and per unit of compute time, plus the managed services you use, so cost follows traffic rather than capacity. A low-traffic service can cost very little, while a high-traffic one needs careful design to stay cheap. AWS publishes pricing per service; check the current rates for Lambda, API Gateway and DynamoDB before you estimate.
What causes cold starts, and how bad are they?
A cold start happens when Lambda must start a new execution environment because none is warm. The delay depends on the runtime and package size, from tens of milliseconds to a few seconds. They matter for user-facing APIs and little for background jobs. Provisioned concurrency removes them where latency matters.
Should we use DynamoDB or Aurora Serverless?
Use DynamoDB when your queries are known in advance and key-based, and you want fast scaling to zero. Use Aurora Serverless when you need SQL joins and transactions and your queries are ad-hoc. The choice follows the access pattern, not the size of the data.
How do we deploy serverless applications?
Use infrastructure as code from the start, usually SAM or CDK. Define functions, APIs, queues and permissions in code, deploy through a pipeline, and keep environments separate. Deploying by hand through the console works once, then becomes impossible to repeat or review.
How do we debug a request across several services?
Use distributed tracing with X-Ray and structured logs in CloudWatch, with a request id passed through every service. Without tracing, a failure that spans API Gateway, two functions and a queue is hard to follow. Add the tracing before launch, not after the first incident.