Serverless vs containers: Lambda, Cloud Run or Kubernetes for your backend?

Serverless functions vs containers compared on cost, cold starts, scaling, limits and operations, with a decision guide by workload.

INDI TECHNOLOGY4 min read

"Should we go serverless?" usually means "should we use functions like AWS Lambda, or run containers?" The honest answer is often both: functions for event-driven and spiky work, containers for steady APIs and long-running processes. This guide explains where each fits.

We'll use AWS names, but the same applies to Google Cloud (Cloud Run functions, Cloud Run) and Azure (Functions, Container Apps).

The spectrum

Functions (Lambda) Serverless containers (Fargate, Cloud Run, Container Apps) Kubernetes (EKS, GKE, AKS)
Unit A function per handler or route A container image Containers in pods
Scaling Per request, to zero, automatic Automatic; Cloud Run scales to zero Configurable; you manage capacity (or use autoscalers)
Billing Per request and compute time Per running vCPU and memory Per node (or per pod on some managed modes)
Max execution time Limited (15 minutes on Lambda) Long-running Unlimited
Cold starts Yes; mitigations available Sometimes (scale from zero) No (warm pods)
Operations Lowest Low Highest
Portability Lower (event model is cloud-specific) High (standard containers) High
Local development Emulators; harder Run the container Run the container

Functions: great for events and spikes

Strengths:

  • No idle cost. You pay only when code runs, which is ideal for low or unpredictable traffic.
  • Automatic scaling for sudden spikes, such as flash sales or batch uploads.
  • Event glue: reacting to file uploads, queue messages, database streams, schedules and webhooks is simple.
  • Little to operate: no servers, no OS patching.

Weaknesses:

  • Cold starts add latency when a new instance starts. Usually tens to hundreds of milliseconds for Node.js, Python and Go; more for large Java apps unless you use features like SnapStart or provisioned concurrency.
  • Limits: execution time, payload size, concurrency quotas and temporary storage.
  • Cost at high steady volume: per-request pricing can cost more than containers for APIs that are busy all the time.
  • Database connections: many short-lived functions can exhaust database connections. Use a connection proxy (RDS Proxy, PgBouncer) or HTTP-based database access.
  • Harder local testing and debugging across many small functions.

Containers: great for steady services

Strengths:

  • Predictable cost for steady traffic.
  • No execution limits: long requests, websockets, background workers, streaming.
  • Portability: the same image runs locally, in CI and on any cloud.
  • Familiar frameworks: run a normal Express, FastAPI, Spring or Go service.

Weaknesses: you pay for idle capacity (unless you scale to zero on Cloud Run or similar), and you manage more configuration: scaling rules, health checks, deployments.

Serverless containers (Fargate, Cloud Run, Azure Container Apps) give most of the operational simplicity of functions with the flexibility of containers. For many teams they're the sweet spot. See Kubernetes vs ECS vs Cloud Run for that choice.

Cost: a rule of thumb

  • Low or spiky traffic: functions are usually cheapest, often nearly free.
  • Moderate steady traffic: roughly similar; choose on other factors.
  • High steady traffic: containers are usually cheaper, sometimes by a lot.

Model it with your real request volumes and durations before deciding. And remember that engineering time often costs more than compute.

Choose functions if…

  • the workload is event-driven: uploads, queues, schedules, webhooks
  • traffic is low, spiky or unpredictable
  • each task is short and stateless
  • you want the least infrastructure to run

Choose containers if…

  • you run a steady, busy API or a long-running process
  • you need websockets, streaming, long jobs or large memory
  • you want portability between clouds and easy local development
  • cold starts would hurt user experience and you don't want to pay to keep functions warm

Recommendation by workload

Workload Pick
Main product API with steady traffic Containers (Fargate or Cloud Run)
Webhook receivers (payments, partners) Functions, writing to a queue
Image and document processing on upload Functions (or containers for heavy files)
Scheduled reports and cleanup jobs Functions or scheduled containers
Websockets and real-time Containers
Flash-sale spikes in e-commerce Containers with fast autoscaling, plus functions for async tasks
ML inference with large models Containers (GPU where needed)
Early MVP with tiny traffic Functions or Cloud Run (scale to zero)

Summary

Use functions for events and spiky, short tasks; use containers for steady APIs and long-running work. Serverless containers like Cloud Run and Fargate are a strong default for product APIs, with functions around them for event handling.

We design and run serverless and container platforms on AWS, GCP and Azure through our cloud and infrastructure work. Talk to us about your workload.

Any idea in mind? Let's make it real.

Tell us what you're building. You'll hear back from an engineer, not a sales team, usually within one working day.

Book a 30-min call