Skip to content

Serverless vs containers

Both let teams deploy code without managing servers directly. The difference is how much of the runtime you control, and how you pay for it.

The line is blurring: serverless container platforms such as Google Cloud Run (opens in a new tab), AWS Fargate and Azure Container Apps run containers with scale-to-zero and per-use billing. The comparison below is about the two operating models.

Aspect Serverless functions Containers
Unit of deployment A function A container image
Scaling Automatic, per request or event, including to zero You configure autoscaling; usually a minimum number of instances
Billing Per invocation and execution time Per provisioned capacity, used or not
Cold starts Yes, when a new instance starts Only when scaling out
Execution limits Maximum duration, memory and package size Few; long-running processes are normal
State and connections Stateless; connection pooling to databases needs care Long-lived connections and in-memory caches are normal
Portability Tied to the provider’s events and APIs High; the same image runs almost anywhere
Operations Little: the provider patches and scales More: cluster, networking, scaling and patching, unless managed
Local testing Harder; emulators approximate the platform Straightforward
  • Traffic is spiky, unpredictable or often zero: webhooks, scheduled jobs, file processing, back-office tools.
  • The work is event-driven glue between managed services.
  • The team is small and wants to spend as little time as possible on operations.
  • Each piece of work finishes within the platform’s time limit.
  • Traffic is steady and high, where paying for provisioned capacity is cheaper than paying per request.
  • You need long-running processes, WebSockets, background workers or large in-memory state.
  • Latency must be consistent and cold starts aren’t acceptable.
  • Portability across clouds or on-premises matters, or you already run a container platform well.

Per-request pricing is cheap at low volume and expensive at high, steady volume. Estimate monthly cost both ways from your real request rate, duration and memory, and include what each needs around it: an API gateway for functions, a load balancer and idle capacity for containers, and people’s time for both. The total cost of ownership template helps compare them over several years.

  • Database connections. Hundreds of function instances each opening connections can exhaust a database. Use a connection proxy or a database built for it.
  • Hidden coupling. A system of many functions connected by events can be harder to understand than one service. Keep function boundaries aligned with business capabilities.
  • Running Kubernetes for three services. A container platform has a real operating cost. Use a managed or serverless container service unless you need the control.

Use serverless functions for event-driven, spiky or low-volume work where operations time is scarce. Use containers for steady, high-volume, long-running or latency-sensitive services, preferably on a managed platform. Many systems use both: containers for the core services and functions for the glue around them.

Written and edited by Abhinav Taduka, enterprise software architect.