Home / Insights / Architecture and Modernization

Architecture and Modernization

Serverless or Containers? Choosing Compute for a Cloud Application

Serverless and containers are both good answers to the compute question. The right one depends on how your workload behaves over a day, not on which is more modern.

TopicsArchitecture and ModernizationWeb and SaaS Development

Key takeaways

  • Serverless functions suit spiky, event-driven or low-volume workloads where paying per invocation beats paying for idle capacity.
  • Containers suit steady, heavy or long-running workloads, and workloads that need specific runtimes, long connections or more control.
  • Managed container platforms such as Cloud Run, ECS on Fargate or Azure App Service sit in the middle and are often the pragmatic default.
  • Check hard platform limits early: execution timeouts, payload sizes and concurrency quotas rule some designs out.
  • Most real systems mix models: an API on containers, background events on functions.

When teams plan a new cloud application or re-platform an existing one, an early architectural question is where the code runs. The options range from serverless functions (AWS Lambda, Azure Functions) through managed container services (Google Cloud Run, Amazon ECS, Azure App Service) to self-managed Kubernetes clusters.

Each has passionate advocates. In practice the decision is driven by a handful of workload characteristics and organisational constraints. This guide walks through them, with a comparison table, the platform limits that most often change the answer, and some illustrative workload patterns.

The compute spectrum

It helps to see compute as a spectrum of how much the provider manages for you.

ModelExamplesYou manageProvider manages
Serverless functionsAWS Lambda, Azure FunctionsFunction code and configurationServers, scaling, runtime patching
Serverless containersGoogle Cloud Run, ECS on FargateContainer image, scaling settingsServers and cluster
Managed app servicesAzure App ServiceApplication and configurationServers, runtime, load balancing
Orchestrated containersKubernetes (EKS, AKS, GKE)Cluster configuration, workloads, upgradesControl plane (in managed offerings)

Moving down the table gives more control and portability, and more operational responsibility.

Six workload factors that decide it

1. Traffic shape

If traffic is spiky, seasonal or near zero for long periods (an internal tool used in office hours, a webhook handler, a nightly import), functions scale to zero and you pay little when idle. If traffic is steady and high around the clock, always-on containers usually cost less per request.

2. Execution duration

Functions have maximum execution times. AWS Lambda, for example, caps a standard invocation at 15 minutes. Long video processing, large report generation or data migrations either need to be broken into steps or run on containers.

3. Latency sensitivity

Functions that have been idle incur a cold start while a new execution environment initialises. For background events this rarely matters. For user-facing APIs with strict latency targets, it may require provisioned capacity or a container-based service that stays warm.

4. Connections and state

WebSockets, long-lived database connection pools and in-memory caches fit naturally on containers. Functions can open many short-lived database connections under load, which may need a connection proxy or a different database access pattern.

5. Runtime and dependencies

Unusual system libraries, large machine learning models or specific OS dependencies are easier in a container image. Function deployment packages have size limits, although container image support on platforms like Lambda has relaxed this considerably.

6. Team and operations

A small team without dedicated DevOps capacity benefits from the least infrastructure to run. Kubernetes is powerful but brings cluster upgrades, networking and security configuration that someone must own. Our article on platform engineering discusses when that investment pays off.

Platform limits to check before you commit

Hard quotas eliminate designs faster than any cost model. Using AWS Lambda as an example, the documented quotas include:

LimitAWS Lambda valueDesign implication
Maximum timeout15 minutes for standard invocationsSplit long jobs into steps or use containers
Memory128 MB to 10,240 MB; CPU scales with memoryCPU-heavy tasks may need high memory settings
Synchronous payload6 MB request and responseUpload large files directly to object storage, not through the function
Asynchronous payload1 MBPass references to data, not the data itself
Default concurrency1,000 per Region, adjustablePlan quota increases before a launch or campaign
Deployment package250 MB unzipped; 10 GB for container imagesLarge dependencies may push you to container images

Other providers have comparable limits with different values. Check the current documentation for the specific services you are considering, as quotas change and new accounts may start with lower values.

How costs behave in each model

Rather than quote prices, which vary by provider, region and commitment, it is more useful to understand how the bill responds to load.

  • Functions: cost grows roughly linearly with invocations and duration, and falls to near zero when idle. Cheap for low or bursty volume; can become expensive for sustained high throughput.
  • Serverless containers: billed for resources while handling requests or kept warm; can scale to zero or keep minimum instances. A middle ground.
  • Always-on containers or VMs: a fixed baseline whether busy or idle; the cost per request falls as utilisation rises. Commitments and reserved capacity reduce it further.

A useful exercise is to model expected monthly requests and average duration for each major component, then compare at current volume and at a plausible growth point. The crossover is often clearer than expected. Remember data transfer, logging and managed database costs, which can outweigh compute. See common cloud cost mistakes for what tends to be missed.

Illustrative workload patterns

WorkloadUsual fitWhy
Webhook receivers and integrationsFunctionsEvent-driven, bursty, short
Scheduled imports and nightly jobsFunctions or scheduled containersIdle most of the day; containers if long-running
Main product API with steady trafficServerless containers or app serviceWarm, predictable latency, connection pooling
Real-time features (chat, live tracking)ContainersLong-lived connections
Document or image processing pipelineFunctions triggered by queue or storage eventsParallel, event-driven, scales with volume
AI model serving with GPUsContainers on GPU-capable servicesLarge models, specialised hardware

For example, a delivery platform might run its customer API on Cloud Run, use Pub/Sub-triggered functions for notifications and status updates, and keep a container service for live driver tracking over WebSockets.

Portability and lock-in

Functions tend to couple code to provider-specific triggers and services. Containers are more portable but still rely on the provider’s networking, identity and managed databases. Reasonable safeguards include keeping business logic in plain modules separate from function handlers, defining infrastructure as code with Terraform, and using standard protocols where possible. Our article on how much cloud lock-in is acceptable covers this trade-off in more depth.

PoliteTech’s cloud application development service works across AWS, Azure and Google Cloud and starts by agreeing workload, availability targets and cost model before choosing compute.

Frequently asked questions

Is serverless always cheaper?

No. It is usually cheaper for spiky or low-volume workloads because you do not pay for idle capacity. Steady, heavy workloads often cost less on containers or reserved compute.

Do we need Kubernetes?

Many products do not. Managed container services such as Cloud Run, ECS on Fargate or App Service cover most needs with far less operational work. Kubernetes makes sense when you run many services, need fine-grained control or have a platform team to own it.

How do we deal with cold starts?

Keep functions small with minimal initialisation, choose runtimes that start quickly, and use provisioned or minimum instances for latency-sensitive paths. Background workloads usually tolerate cold starts without changes.

Can we change our mind later?

Yes, if business logic is kept separate from the hosting layer. Moving a well-structured service from functions to containers, or the reverse, is mostly a packaging and deployment change.

Sources and methodology

Guidance reflects PoliteTech delivery experience. The external references below informed specific points in this article.

  1. AWS Documentation: Lambda quotas — Supported the timeout, memory, payload, concurrency and deployment package limits used as examples.

Unsure whether your workload belongs on functions or containers?

Tell us how your traffic, jobs and data behave and we will recommend a compute model with the cost assumptions written down.