The Short Answer
Should I use serverless, containers or virtual machines?
For most new web applications, containers on a managed platform are the sensible default: predictable, portable and simple to run. Serverless functions suit spiky or event-driven work, such as processing uploads or webhooks, where paying only for use saves money. Virtual machines suit software that needs full control of the operating system or cannot be containerised.
Read the transcript
Where your code runs decides three things. Your monthly bill. How you scale. And how much work your team carries. There are three main options. Virtual machines: a whole server you look after. Containers: your app packaged up, run by a platform. Serverless: code that runs only when called, billed per use. So which should you choose? For most web apps, containers on a managed platform are the sensible default. Serverless suits spiky, occasional jobs, like processing uploads or webhooks. Virtual machines suit software that needs full control of the server. And watch the cost at scale. Serverless is cheap when idle, but steady heavy traffic is often cheaper on containers. Pick the simplest option that fits. You can mix them later. The full guide is free at loomstrat.com.
What Each One Is
| Model | What you hand over | What you manage |
|---|---|---|
| Virtual machine | A slice of a physical server with its own operating system | Operating system, patches, runtime, application, scaling |
| Container | A packaged application with its dependencies, run by a container platform | The container image and its configuration; the platform handles much of the rest |
| Serverless function | A piece of code run on demand by the provider | The code and its settings; the provider runs and scales it |
Containers are usually built with Docker and run on a managed service or on Kubernetes. Serverless functions include AWS Lambda, launched in 2014. Some services blur the line: Google Cloud Run runs containers but scales them to zero like serverless.
How They Compare
| Virtual machines | Containers | Serverless | |
|---|---|---|---|
| Billing | Per hour, whether busy or idle | Per running instance; some platforms scale to zero | Per request and execution time |
| Scaling | Manual or slow automatic | Fast automatic scaling | Instant and automatic, within limits |
| Cold starts | None | None unless scaled to zero | Possible delay after idle periods |
| Run time limits | None | None | Time limits per execution |
| Portability | Moderate | High; runs on any container platform | Low; tied to provider services |
| Operations work | Highest | Moderate | Lowest |
| Local development | Straightforward | Straightforward | Harder to reproduce exactly |
Cost: Where Each Wins
- Low or spiky traffic: serverless or scale-to-zero containers are cheapest, because idle time costs nothing.
- Steady, high traffic: always-on containers or VMs are usually cheaper per request than serverless.
- Hidden costs: serverless designs often depend on other paid services for queues, storage and orchestration. Amazon Prime Video publicly described moving one monitoring tool from a serverless design to a single process and cutting its infrastructure cost by more than 90 per cent; see monolith vs microservices.
- People cost: the cheapest bill can be the most expensive option if it needs a specialist to run. See cloud hosting costs.
Which to Choose
| Workload | Usually best |
|---|---|
| Standard web app or API | Containers on a managed platform |
| Background jobs triggered by events | Serverless functions |
| Webhook receivers and scheduled tasks | Serverless functions |
| Long-running processing, video, large batch work | Containers or VMs |
| Legacy software that expects a full server | Virtual machines |
| Machine learning model hosting with GPUs | Containers or VMs with GPUs, or a managed AI service |
Many products mix them: the main application in containers, with serverless functions for occasional jobs. Avoid splitting into many small serverless functions too early; it brings the same complexity as microservices.
Do You Need Kubernetes?
Kubernetes is powerful and complex. Most small and medium products do not need to run it themselves. Managed container services give most of the benefits with far less to operate. Consider Kubernetes when you run many services, need fine control over scheduling, or have a platform team to look after it.
Frequently Asked Questions
Is serverless cheaper?
For low or irregular traffic, usually. For steady high traffic, containers or virtual machines are often cheaper per request.
What is a cold start?
A delay when a serverless function, or a container scaled to zero, runs after being idle, while the provider starts it up.
Are containers the same as virtual machines?
No. A VM includes a whole operating system. Containers share the host’s operating system kernel, so they are lighter and start faster.
Can I move from serverless to containers later?
Yes, but code that relies heavily on provider-specific services takes more work to move. Keeping business logic separate from those services helps.
Which is most secure?
All can be secure. Serverless leaves more patching to the provider; VMs leave the most to you.