Serverless, Containers or Virtual Machines: Choosing a Cloud Architecture

Every major cloud platform offers three main ways to run code: functions that run on demand and scale to zero, containers on a managed platform or orchestrator, and virtual machines the team configures itself. All three can run the same business logic. They differ in how they scale, how they are billed, what limits they impose and how much operational work they leave with the team. Most production systems end up using more than one.

At a glance

15 min
The maximum duration of a single AWS Lambda invocation; other platforms set their own limits.
Scale to 0
Functions and some container services use no compute capacity when idle.
Cold start
The delay when a function or container starts from nothing to handle a request.
OCI
The open container image format that runs across clouds and on premises.

The problem

Serverless functions look ideal until the workload does not fit: long-running jobs hit time limits, persistent connections are not supported, and steady high traffic can cost more than always-on capacity.

Virtual machines give full control but leave patching, scaling, monitoring and recovery with the team. Containers sit between the two, and a full Kubernetes cluster brings substantial operational complexity that a small team may not need.

Match the compute model to the shape of the workload: spiky and short suits functions, steady services suit containers, special requirements suit virtual machines.

Connected products in the cloud

IoT back ends show why the mix matters. Devices often hold long-lived MQTT connections, which suit a managed IoT message broker rather than functions. Messages from the broker can then trigger functions for rule processing, while containers run the APIs used by apps and dashboards.

Processing that runs for hours, needs a GPU or depends on software licensed to a machine usually belongs on virtual machines or batch services. Managed container platforms, which run containers without a cluster to administer, are a good default for web APIs.

What good looks like

Describe each workload: request pattern, duration, state, connection type, latency needs and any special hardware or licensing.

Pick the simplest model that meets each workload, preferring managed services that remove operational work the team does not need to own.

Package code in containers where practical, so it can move between functions, managed containers and virtual machines as needs change.

Comparing the compute models
ModelYou manageScalingSuits
FunctionsCode and configurationAutomatic, to zeroEvent-driven, spiky, short tasks
Managed containersImages and service settingsAutomatic, often to zeroWeb APIs and services
KubernetesCluster, workloads and add-onsConfigurableMany services, platform teams
Virtual machinesOperating system upwardScaling groups you configureLong-running, special hardware, legacy
Equivalent services exist on all major cloud platforms.
Functions and managed containers
FunctionsManaged containers
Idle costNoneNone or low
Long-running workTime limitedSupported
Persistent connectionsNot suitedSupported
Operational effortLowestLow
Local testingNeeds emulationRun the same image
The two most common choices for new cloud services.

What it changes

Right Cost Profile

Billing follows the workload, from pay per request to reserved capacity.

Less Operations

Managed services take patching and scaling off the team.

Scalability

Each part scales in the way its traffic actually behaves.

Portability

Containerised code keeps options open across platforms and providers.

Where to go next

Model costs at expected and peak load for each option before deciding. The cheapest model at launch is not always the cheapest at scale.

Infrastructure as code, with tools such as Terraform, OpenTofu or the provider templates, makes whichever choice you make reproducible.

Problems this prevents

  • Long jobs failing at function time limits
  • Persistent device connections on stateless functions
  • A cluster too complex for the team
  • Servers patched by hand

Discuss your project

Email support@aavico.com or use Get in Touch when the website finishes loading.