What Is Serverless Computing and When Should You Use It?
Serverless computing lets you run code without managing servers; the provider scales and bills per request. Learn how it works, its tradeoffs and when to use it.
On this page
Short answer
Serverless computing is a cloud model where you deploy code or managed services and the provider handles servers, scaling and availability. You pay for what you use, usually per request and compute time, not for idle capacity.
What is serverless computing?
Serverless computing is a cloud execution model in which the provider runs your code and managed services, and you are billed for usage rather than for provisioned servers. There are still servers, but they are not your responsibility to size, patch or keep available.
The term covers two related ideas. Function as a service (FaaS) runs short-lived code in response to events. Managed backends such as queues, databases, authentication and storage are also "serverless" in the sense that the provider operates them and scales them for you. Most real systems combine both: a function handles an upload, writes to object storage, enqueues a message and records state in a managed database.
The key shift is operational. Instead of asking how many instances to run, you ask what event triggers the work, what the maximum execution time is and what happens when a retry occurs. That changes both the architecture and the cost model.
How does serverless work under the hood?
The provider keeps a pool of execution environments, starts one when an event arrives, runs your handler and then freezes or discards it. Scaling is handled per event, so a sudden burst of traffic creates many small executions instead of waiting for a provisioning step.
When no warm environment is available, the platform must start one. That delay is a cold start. It depends on runtime, package size, memory settings and whether the environment can be reused. Keeping dependencies small and initialising clients outside the handler usually helps.
Execution is expected to be short and stateless. Local disk and memory are not durable between invocations, so state belongs in a database, object store or queue. Platforms also enforce timeouts and concurrency limits, which shape how you split work.
Because invocations can be retried, handlers should be idempotent. Processing the same message twice should not charge a card twice or send a duplicate email. Use idempotency keys, conditional writes or a deduplication table.
What are the main benefits?
The main benefit is that teams spend less time on infrastructure and more on product behaviour. There are no servers to patch, no cluster upgrades and no capacity planning for steady traffic.
- Elastic scaling. Traffic spikes are absorbed by the platform. A launch, a batch import or a nightly job does not require pre-provisioning.
- Consumption billing. In request-driven models you pay for invocations and execution time rather than idle capacity. For spiky or low-volume workloads this can be materially cheaper.
- Faster delivery. A small team can ship an API, a webhook handler or a scheduled job without a platform team.
- Managed security baseline. The provider patches the runtime and the managed services behind it.
- Event-driven fit. Serverless pairs naturally with queues, streams, object storage and scheduled triggers.
The tradeoff is less control. You inherit the platform's limits, runtime support and pricing shape, and you need good observability to understand distributed executions. Teams building broader platforms often pair this with software engineering services to keep architecture and delivery aligned.
What are the tradeoffs and limits?
The practical limits are cold starts, execution timeouts, concurrency ceilings, package size and testing friction. None of these is fatal, but each shapes the design.
Cold starts matter for user-facing latency. Interactive APIs notice them more than background jobs. Provisioned concurrency or smaller packages reduce the effect, at some cost.
Timeouts mean long-running work must be split. A large file conversion or a multi-step workflow becomes a chain of short steps coordinated by a queue or a workflow service. That is usually better engineering, but it is more moving parts.
Local development can diverge from the cloud. Emulators help, yet managed services behave differently in production. Integration tests in a real account are worth the effort.
Cost can also surprise you at scale. Per-request pricing is cheap at low volume and can become expensive under constant high throughput compared with reserved containers. Model your expected volume before committing. Stateful services such as relational databases may still need capacity planning even when compute does not.
When should you use serverless?
Use serverless when the work is event-driven, bursty or operationally light, and when the team would rather ship features than run infrastructure.
Good fits include:
- HTTP APIs with variable traffic, especially early-stage products.
- Webhook receivers and third-party integrations.
- File and image processing triggered by uploads.
- Scheduled jobs such as reports, cleanup and synchronisation.
- Glue code between services, queues and data stores.
- Internal tools and prototypes that may never see heavy load.
Poorer fits include:
- Long-running computations that exceed platform timeouts.
- Workloads with steady, high throughput where reserved compute is cheaper.
- Latency-critical paths where cold starts are unacceptable.
- Systems needing specialised networking, custom kernels or persistent connections.
- Stateful protocols that depend on in-memory session state.
A common pattern is hybrid: serverless for edges, events and intermittent jobs, containers for steady core services. Data pipelines are a frequent example, and data engineering services often combine both.
How do you get started safely?
Start with one bounded workload, define the event contract and instrument it before scaling out.
- Pick a narrow use case. A webhook handler or scheduled report is a good first candidate because failure is contained.
- Define the event schema. Document the payload, retries and dead-letter behaviour so consumers know what to expect.
- Make handlers idempotent. Use a deduplication key or conditional write so retries are safe.
- Set limits deliberately. Choose memory and timeout values based on measurement, not defaults.
- Add observability. Structured logs, trace IDs and metrics per function, with alerts on errors and throttling.
- Test in a real account. Run integration tests against managed services before trusting the design.
- Review cost after a month. Compare actual spend with a container estimate for the same workload.
Example (hypothetical): a team runs an image-resize function for 2 million uploads a month, averaging 400 ms per run at 512 MB. They also run a small always-on API container for interactive traffic. The function absorbs spikes; the container keeps latency predictable. The split is reviewed after the first month using real usage data.
Common mistakes
Most serverless problems come from treating it like a traditional server. Avoid these patterns.
- Assuming state persists. Local disk and memory are not durable; write state to a managed store.
- Ignoring retries. Non-idempotent handlers cause duplicate charges, emails and records.
- Oversized packages. Large dependencies slow cold starts and hit size limits.
- Chatty function-to-function calls. Synchronous chains multiply latency and failure modes; prefer queues.
- No dead-letter handling. Failed events disappear silently without a destination.
- Skipping cost modelling. Per-request pricing can grow quickly under steady load.
- Weak observability. Distributed executions are hard to debug without trace IDs and structured logs.
Key takeaways
- Serverless means the provider manages servers, scaling and patching; you focus on code and configuration.
- Billing is consumption-based, so idle time is not charged in request-driven models.
- Cold starts, execution time limits and local testing are the main practical constraints.
- It fits event-driven work such as APIs, file processing, scheduled jobs and glue between services.
- Stateful, long-running or latency-sensitive workloads often fit containers better.
- Design for idempotency and observability because retries and distributed execution are normal.
Frequently asked questions
Is serverless the same as no servers?
No. Servers still exist, but the cloud provider runs, patches and scales them. Your team manages code, configuration and data rather than machines, operating systems and capacity planning.
What is a cold start in serverless?
A cold start is the delay when the platform must create a new execution environment before running your code. It depends on runtime, package size and memory settings, and affects user-facing latency more than background jobs.
Is serverless cheaper than containers?
It depends on traffic shape. Consumption billing is often cheaper for spiky or low-volume work. Under steady, high throughput, reserved containers can cost less. Model your expected volume before choosing.
Can serverless handle long-running jobs?
Not in a single invocation beyond platform timeouts. Split the work into short steps coordinated by a queue or workflow service, or run the long part on containers.
Is serverless secure?
The provider patches the runtime and managed services, but you still own identity, permissions, secrets and input validation. Least-privilege roles per function and careful secret handling are essential.
Does serverless work for AI agents and LLM workloads?
Often yes for orchestration, webhooks and tool calls. Long model runs or streaming responses may exceed timeouts, so many teams combine serverless orchestration with containers for heavier inference work.