Serverless functions and containers both run your code in the cloud, but they make different promises. Serverless platforms like AWS Lambda, Google Cloud Run functions, and Azure Functions scale to zero, bill per invocation, and hide the server entirely. Containers running on Kubernetes, Amazon ECS, or managed services like Cloud Run and Azure Container Apps give you a full runtime environment you control, with no hard execution time limit. Picking between them (or combining both) affects your cost curve, your operational workload, and how fast you can ship. This article lays out a practical decision framework: what each model actually does well, where it breaks down, and how most production systems end up using both.
What "Serverless" Actually Means in 2026
Serverless compute runs your code in a managed execution environment that starts on demand and stops when there is no work. You deploy a function (or, increasingly, a small web server) and the platform handles provisioning, scaling, and patching the underlying host. AWS Lambda remains the reference implementation: a function can run for up to 900 seconds (15 minutes) by default, and can use up to 10,240 MB of memory, with CPU allocated proportionally to memory. Container images for Lambda functions can be as large as 10 GB uncompressed.
What has changed since serverless first went mainstream is the ceiling on what counts as "serverless." AWS now offers durable functions that checkpoint state and can run well beyond the 15 minute limit for long-lived workflows, and a managed instances tier aimed at workloads that need a longer-lived execution environment than a classic function provides. Google Cloud Run and Azure Container Apps blur the line further: they run full containers, but scale to zero and bill close to per-request like a function. The practical effect is that "serverless vs containers" is no longer two cleanly separated categories. It is closer to a spectrum, from pure event-driven functions to always-on container fleets, with scale-to-zero container platforms sitting in the middle.
What Containers Give You That Functions Don't
A containerized service, whether on Kubernetes, ECS, or a managed platform, runs your application as a long-lived process. There is no hard timeout on a single request's processing, your runtime is whatever you package into the image, and you get direct control over networking, startup behavior, and resource limits per container rather than per invocation. That matters for:
- Long-running or stateful work: batch jobs, video or file processing, WebSocket connections, long-polling, or anything that needs to hold an in-memory cache or connection pool across requests.
- Steady, predictable traffic: if your service runs near capacity most of the day, an always-on container (or a small fixed fleet) is usually cheaper per unit of work than paying for scale-to-zero convenience you never use.
- Heavy runtimes: large JVM or .NET applications with slow startup are a poor fit for frequent cold starts. A container that starts once and stays warm avoids paying that cost on every scale-up event.
- Portability: a container image runs the same way on any Kubernetes cluster or container platform. Moving a large set of Lambda functions between providers means rewriting the event sources, IAM model, and deployment tooling, not just the code.
The tradeoff is operational surface area. Even a managed container platform asks you to think about image builds, autoscaling policy, health checks, and resource requests and limits. A Kubernetes cluster you run yourself adds cluster upgrades, node management, and networking configuration on top of that. This is real, ongoing engineering work, not a one-time setup cost.
Where Serverless Wins
Functions are built for event-driven, bursty, and intermittent work. They fit well when:
- Traffic is spiky or unpredictable: a webhook handler, a scheduled job, an image thumbnail generator triggered by file uploads. You pay only when the function runs, and the platform absorbs sudden spikes without any capacity planning on your part.
- You want to eliminate idle cost: a low-traffic internal tool or an API that gets occasional use does not need a server running around the clock.
- The team is small: no cluster to patch, no base image to maintain, no capacity to size. The platform's scaling and patching is someone else's job.
- Work decomposes naturally into short, independent units: order processing steps, notification sends, data transformation stages in a pipeline.
The classic complaints about serverless, cold starts and vendor lock-in, are both real but narrower than they used to be. Cold start latency depends heavily on runtime: lightweight runtimes like Node.js or Python typically start fast, while JVM-based and .NET functions see noticeably longer cold starts unless you pay for provisioned concurrency to keep instances warm. If your API has a strict sub-200ms latency requirement for every request, uncontrolled cold starts are a real risk worth load-testing before you commit. Lock-in is less about the function code itself (which is usually portable) and more about how deeply you wire into provider-specific triggers: EventBridge rules, SQS event source mappings, and IAM execution roles do not translate directly to another cloud. Using a thinner abstraction layer in your own code, rather than scattering provider SDK calls throughout your business logic, keeps a future migration realistic.
The Cost Question, Without the Guesswork
Serverless and container pricing are structured differently enough that comparing list prices in isolation is not useful. What actually determines which is cheaper for your workload is traffic shape and duration, not the platform's marketing:
- Low, bursty traffic: serverless usually wins. You are not paying for idle capacity between invocations.
- Sustained, high-throughput traffic: a right-sized container (or fleet) usually wins. Per-invocation serverless pricing adds up fast once you are running near-constant load, and the per-request overhead that made serverless convenient stops paying for itself.
- Workloads that need to avoid cold starts but also want to scale to zero: provisioned concurrency on Lambda, minimum instance counts on Cloud Run, or a premium plan on Azure Functions all close the cold-start gap, but you pay for the reserved capacity whether or not it is used. At that point you are paying container-like prices for a serverless product, so run the numbers both ways before assuming serverless is automatically cheaper.
The only reliable way to answer the cost question for your own application is to model your actual request volume and duration against both pricing structures, or run a short load test on each. A generic benchmark from a blog post will not match your workload's shape closely enough to be decision-grade.
A Practical Decision Framework
Rather than picking a side, ask these questions about the specific workload in front of you, not your whole application:
- How long does a single unit of work take? Over the function timeout ceiling (15 minutes on standard Lambda, longer with durable functions or managed instances), you need a container or a workflow-orchestration approach designed for long-running tasks.
- Is the traffic bursty or steady? Bursty and infrequent favors serverless. Steady and high-volume favors containers.
- Does it need to hold state or a persistent connection? WebSockets, in-memory caches, and connection pools fit a long-lived process better than a function that may be torn down between invocations.
- What is the team's operational capacity? A two-person engineering team running a Kubernetes cluster alongside product work is taking on real risk. A managed container platform like Cloud Run or Azure Container Apps narrows that gap without going fully serverless.
- What is the latency budget? If every millisecond of cold start matters and the runtime is heavy, either pay for provisioned concurrency or choose a container that stays warm.
Most production systems do not answer this once for the whole application. A typical pattern looks like containers (on ECS, Cloud Run, or Kubernetes) running the core API and any stateful services, with serverless functions handling webhooks, scheduled jobs, file-triggered processing, and other event-driven edges. That split lets you apply scale-to-zero economics where traffic is unpredictable and a stable, tuned runtime where it is not, instead of forcing one compute model to fit every part of the system.
What This Means for a SaaS or Web Application Build
If you are architecting a new SaaS product or scaling an existing web application, the compute model decision is easiest to get right early, since migrating a live system between models later means re-architecting around different scaling, networking, and deployment assumptions. A reasonable default for a new product: containers for the primary API and database-backed services where request volume is expected to grow steadily, serverless for background jobs, webhooks, and anything genuinely event-driven. Revisit the split as real traffic data comes in rather than guessing far in advance, and avoid hand-rolling heavy cloud-vendor-specific glue code in your core business logic so the system stays portable if your needs change.
This decision connects directly to the scaling questions covered in our guide to scaling a web application and to the service-boundary tradeoffs in microservices vs monolith: compute model, service boundaries, and database scaling strategy all need to agree with each other, not be chosen independently.
Frequently Asked Questions
Can I mix serverless and containers in the same application?
Yes, and most real systems do. A common pattern runs the core API as a container service and handles background jobs, webhooks, and scheduled tasks as functions. The two communicate through a queue, event bus, or shared database rather than direct calls, which keeps the boundary clean.
Does serverless still make sense for a long-running background job?
Not past the platform's timeout ceiling. Standard AWS Lambda functions cap out at 15 minutes; durable functions and managed-instance options raise that ceiling for specific workflow patterns, but a container or a dedicated worker process is usually simpler for jobs that routinely run longer than a few minutes.
Is Kubernetes required if I want to use containers?
No. Managed platforms like AWS Fargate, Google Cloud Run, and Azure Container Apps run containers with scale-to-zero or near-serverless billing and far less operational overhead than running your own Kubernetes cluster. Kubernetes becomes worth the overhead when you need fine-grained control over scheduling, networking, or multi-cluster operations that the managed platforms do not expose.
How much does vendor lock-in really matter for serverless?
It depends on how deeply your code depends on provider-specific triggers and services. Function code itself usually ports with moderate effort. The harder part to move is the surrounding configuration: event source mappings, IAM roles, and managed service integrations. Keeping that wiring isolated from your business logic makes a future migration realistic instead of theoretical.
Choosing between serverless and containers is ultimately an architecture decision that should be driven by your actual traffic patterns and team capacity, not by whichever model is trending. If you are evaluating this tradeoff for a new build or a scaling existing system, book a strategy call to talk through your specific workload, or see how it fits into a broader build at our web application development page.