Serverless Application Architecture: What It Is and When to Use It
Serverless architecture runs code on managed infrastructure that scales on demand and bills per use. Learn how it works, its trade-offs, and when it fits.
On this page
Short answer
Serverless application architecture runs your code on managed infrastructure that scales automatically and bills per request or execution time. You don't provision or patch servers; the provider handles capacity, while you own code, configuration, data and identity.
What is serverless application architecture?
Serverless application architecture is a way of building software where the cloud provider runs your code and manages all servers, capacity and scaling, and you pay only for what executes. You deploy functions, containers or managed services; the provider decides where they run and how many instances exist at any moment.
The word is a misn't: there are still servers, you just don't see or manage them. That changes the engineering job. Instead of sizing virtual machines, your team spends time on function boundaries, event contracts, identity and permissions, and data design. The operational surface shrinks, but the design surface moves.
A typical stack combines several managed pieces:
- Compute: functions or request-driven containers for business logic.
- Data: managed relational or document databases, object storage, and caches.
- Integration: queues, event buses, schedulers and API gateways.
- Identity: provider IAM plus your application's own auth layer.
If your team is weighing this against container platforms, a cloud architecture review is usually cheaper than a rewrite later. See cloud services for how migration and operations are typically scoped.
How does serverless architecture actually work?
Serverless works by mapping each request or event to a short-lived execution environment that the provider starts, runs and tears down. An API gateway receives an HTTP call, a function runtime boots with your code, the handler runs, returns a response, and the environment is reused or discarded.
The lifecycle matters for design:
- Trigger. An HTTP request, queue message, file upload, schedule or database change fires an event.
- Placement. The platform routes the event to an available environment, starting a new one if none is warm.
- Execution. Your handler runs with a time limit and memory limit you configure.
- State. Anything that must persist goes to an external store; the environment is not reliable storage.
- Scaling. Concurrency grows with traffic, subject to account-level quotas.
Because environments are recycled, code must assume it can be killed at any moment. Long-running background threads, in-memory sessions and local file writes are fragile patterns. Move that work into managed queues or durable storage.
Example: a hypothetical image upload flow. A user uploads a photo to object storage; a storage event triggers a resize function; the function writes three sizes back to storage and pushes a message to a queue; a worker updates the database record. Each step scales independently and no server is sized by hand.
What are the main trade-offs?
The main trade-offs are cold-start latency, execution limits, per-request cost at steady load, and harder local testing. Serverless is excellent for spiky or unpredictable traffic and less comfortable for long-running, latency-sensitive or stateful workloads.
Where it helps:
- Traffic that is bursty or hard to forecast.
- Event-driven jobs: file processing, webhooks, scheduled reports.
- Small teams that want to avoid patching operating systems.
Where it hurts:
- Cold starts. The first request to an idle environment is slower. Keep packages small, and keep latency-sensitive paths on provisioned capacity or containers.
- Time limits. Functions have maximum execution durations. Long batch jobs need step functions, queues or containers.
- Cost shape. Per-request billing is cheap at low volume and can exceed fixed server costs at high, steady volume. Model both.
- Testing. Emulating queues, identity and gateways locally takes setup. Invest in integration tests against a real staging account.
For teams building this in-house, software engineering services covers the architecture and review side.
How do you design data and state in a serverless system?
Design data first: because compute is stateless, the database and storage choices determine most of your performance and cost. Pick a managed database that matches your access patterns, and treat connections as a scarce resource.
Key patterns:
- Connection pooling. Functions open many short-lived database connections. Use a pooler or the database's HTTP interface to avoid exhausting connection limits.
- Idempotency. Events can be delivered more than once. Give each operation an idempotency key so retries don't duplicate writes.
- Event contracts. Define message schemas explicitly and version them. Loose JSON between services becomes a debugging tax.
- Right store per job. Object storage for blobs, a relational store for transactions, a queue for work handoff, a cache for hot reads.
- Data residency. Choose regions per market; EU and Middle East deployments often need data to stay in-region.
A worked scenario: an orders service handles a hypothetical peak of 200 requests per second for ten minutes, then near zero. A function-based API scales to the peak and costs almost nothing afterwards; a fixed cluster sized for the peak sits idle most of the day. The reverse is true if that 200 requests per second runs all day.
How do you handle security, observability and cost?
Security, observability and cost control are configuration problems in serverless, and they need to be designed in rather than added later. Each function should have its own least-privilege role, and every event source should be authenticated.
Practical steps:
- Least privilege per function. Grant only the actions and resources that function needs. Avoid one broad role shared across the stack.
- Secrets. Store credentials in a managed secret store and rotate them; never in environment variables committed to code.
- Distributed tracing. One user request may cross a gateway, three functions and a queue. Trace IDs must propagate through every event.
- Structured logs and metrics. Log JSON with request IDs; alert on error rate and p99 latency, not just averages.
- Cost guardrails. Set budgets and alarms, review invocation counts per function, and watch retries — a failing function that retries can multiply cost quietly.
Security review for this model is best done alongside architecture, not after launch. Cybersecurity services covers the review scope.
When should you not use serverless?
You should avoid serverless when workloads are long-running, stateful, latency-critical at steady load, or bound by heavy connection requirements. Functions are a poor fit for tasks that need a warm process for minutes or hours.
Common cases where containers or virtual machines are the better default:
- Long-lived connections. WebSocket servers with large fan-out, or streaming jobs that run for hours.
- Steady high throughput. When utilisation is consistently high, reserved capacity is usually cheaper.
- Heavy compute per request. Video encoding, large model inference or CPU-bound batch work often fits dedicated hardware better.
- Strict latency budgets. If every millisecond counts, warm containers remove cold-start variance.
- Complex local development. Teams that need full offline environments may prefer containerised services.
Hybrid is normal: run the API on functions, keep a container for the long-running worker, and share one managed database. Decide per workload rather than per company.
How do you choose: five steps
Choose serverless per workload, not per company. A short evaluation beats a platform debate.
- Classify the workload. Is it event-driven, request-driven, or long-running? Note peak and average traffic and any latency budget.
- Check the limits. Compare execution time, payload size, connection limits and concurrency quotas against your real requirements.
- Model the cost. Estimate invocations, execution time and data transfer for your traffic shape, and compare with a container baseline. Label it as an estimate.
- Review the team's skills. Serverless rewards teams comfortable with event contracts, IAM and managed services.
- Pilot one service. Move a single bounded service first, measure latency, cost and on-call load, then decide whether to expand.
If you need a team to run the pilot while your engineers keep shipping, staff augmentation is one way to add capacity. More engineering guides are on the blog.
Common mistakes
Most serverless failures come from carrying over assumptions from server-based systems. The model is different enough that copying old patterns produces fragile, expensive systems.
- Shared database connections. Opening a connection per invocation without a pooler exhausts database limits under load.
- State in memory. Caching sessions or files in the function environment loses data on recycle.
- One giant function. A monolithic handler with broad permissions is hard to secure and slow to deploy.
- Ignoring retries. Event sources retry; without idempotency, duplicates become data errors.
- No local contract tests. Without schema tests between services, event changes break silently.
- Skipping budgets. Per-request billing is easy to start and easy to underestimate without alarms.
Fix these in architecture review, not in production incidents. A short design checklist saves far more than it costs.
Key takeaways
- Serverless shifts capacity management to the provider; you still own code, data, IAM and networking.
- Functions are stateless by design, so state moves to managed databases, queues and object storage.
- Cold starts, execution time limits and per-request pricing shape which workloads are a good fit.
- Event-driven patterns (queues, streams, schedules) are where serverless pays off most.
- Observability and local testing need deliberate setup; they are not free with the model.
Frequently asked questions
Is serverless cheaper than running servers?
It depends on traffic shape. For spiky or low-volume workloads, per-request billing is usually cheaper because you don't pay for idle capacity. For high, steady load, reserved containers or virtual machines often cost less. Model both before deciding.
What is a cold start in serverless?
A cold start is the extra latency when the platform must create a new execution environment for a request. It is larger for heavy runtimes and large packages. Keeping dependencies small and using provisioned capacity for latency-critical paths reduces it.
Can serverless applications keep state?
The compute layer does not keep durable state; environments are recycled. State belongs in managed databases, object storage, caches or queues. Design handlers to be stateless and idempotent so retries and restarts are safe.
Is serverless secure?
It can be, but the responsibility splits. The provider secures the underlying infrastructure; you secure identity, permissions, secrets, input validation and network configuration. Least-privilege roles per function and traced, authenticated events are the baseline.
Does serverless work for regulated industries?
Yes, with care. Data residency, audit logging, encryption and access controls must be configured explicitly. Choose provider regions that match your market and document controls for your compliance reviewers before launch.
When should we use containers instead?
Choose containers for long-running processes, steady high throughput, large fan-out connections or strict latency budgets. Many teams run a hybrid: functions for event-driven pieces and containers for persistent services, sharing one managed data layer.