Cloud11 min readJun 2026 Last verified Jun 2026

Compute Models: VMs vs Containers vs Serverless

Virtual machines, containers, serverless, three ways to run your code, three very different trade-offs in control, speed, and cost. Here's how to choose without overthinking it.

ComputeContainersServerlessVMsFoundations
SB

Sri Balaji

Founder ยท TheSimplifiedTech

On this page

TL;DR

VMs, containers, and serverless trade control for speed and cost in predictable ways. You'll know which to reach for per workload without overthinking it, and which default choices quietly burn money.

Three ways to run the same code

Once you've written an app, you have to *run* it somewhere. The cloud gives you three main options, and they exist on a spectrum from "you control everything" to "you control almost nothing and only pay when it runs": virtual machines โ†’ containers โ†’ serverless. None is universally best. The skill is matching the model to the job.

Who this is for

Beginners who can write an app but aren't sure how to host it. We keep it practical, when to use which, and why.

The hotel analogy

๐Ÿ  Renting a whole houseVirtual Machine
๐Ÿจ A room in a hotelContainer
๐Ÿ›Ž๏ธ Room service, billed per useServerless
How much of the building is yours, and how much is shared and managed?

A VM is a whole house, your own OS, your own everything, idle or not you pay rent. A container is a hotel room, you get an isolated space but share the building's plumbing (the host OS kernel), so it's lighter and faster to move into. Serverless is room service, you don't keep a room at all; you ask for something, it runs, you pay only for that, and it vanishes.

The trade-offs side by side

Virtual MachineContainerServerless
Startup timeMinutesSecondsMilliseconds
You manageOS + runtime + appRuntime + appJust your code
BillingPer hour, even idlePer hour (cluster)Per request / ms
Best forLegacy, full controlMicroservices, portabilitySpiky / event-driven work
Watch out forIdle waste, patchingOrchestration complexityCold starts, time limits
Left = more control + always-on cost. Right = less ops + pay-per-use, with limits.

When to reach for each

Virtual machines

Pick a VM when you need full control of the operating system, you're running legacy or specialised software, or a workload runs constantly at predictable load. You trade convenience for control, and you own patching and scaling.

Containers

The modern default for most applications. Containers package your app with its dependencies so it runs identically everywhere, start in seconds, and pack efficiently onto hosts. The cost is orchestration: at scale you'll want Kubernetes, which has its own learning curve.

Serverless

Brilliant for spiky, event-driven, or infrequent work, an image-resize on upload, a webhook handler, a nightly job. You write a function, the platform runs it on demand and scales to zero when idle (you pay nothing). The catches: cold starts (first invocation after idle is slower) and time/size limits that make it a poor fit for long-running jobs.

Pro tip

A good default for a new app in 2026: containers for your main services, serverless for the glue (events, cron, webhooks). Reach for raw VMs only when something specifically needs them.

The same job, three ways

Notice how the amount of *infrastructure* you describe shrinks as you move right. A container needs an image:

Dockerfile
Dockerfile
FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
COPY . .
EXPOSE 8080
CMD ["node", "server.js"]

The same logic as a serverless function is just the handler, no server, no port, no Dockerfile. The platform supplies everything around it:

handler.py
python
# Runs on demand, scales to zero, billed per invocation.
def handler(event, context):
    name = event.get("name", "world")
    return {"statusCode": 200, "body": f"Hello, {name}!"}

Common mistakes that cost people hours

  1. 1Running idle VMs 24/7. Paying for a always-on house when room service would do. Match the model to the load.
  2. 2Reaching for Kubernetes on day one. Three containers don't need an orchestrator. Start simple; add k8s when the pain is real.
  3. 3Putting long-running jobs on serverless. Functions have time limits. A 30-minute batch job will get killed mid-run.
  4. 4Ignoring cold starts on latency-sensitive paths. If a user is waiting, a cold function start can hurt. Keep critical paths warm or on containers.
  5. 5Lifting a legacy app onto serverless unchanged. Serverless rewards stateless, short, event-driven design. Forcing a monolith into it fights the model.

Where to go next

The whole article in 5 lines

  • VM = a whole house: full control, always-on cost, you patch it.
  • Container = a hotel room: isolated, light, portable, the modern default.
  • Serverless = room service: pay per use, scales to zero, but cold starts + time limits.
  • Match the model to the workload; don't default to the most powerful (or most complex).
  • Common 2026 mix: containers for services, serverless for the glue.

You've written an app and need to choose where to run it. Which compute model fits?

Check your understanding

1. In the hotel analogy, what makes a container lighter and faster to move into than a VM?

2. What are the two main catches of serverless functions the article warns about?

Frequently asked questions

When should I use a virtual machine instead of a container?

Pick a VM when you need full control of the operating system, you are running legacy or specialised software, or a workload runs constantly at predictable load. You trade convenience for control, which means you own patching and scaling yourself.

Why are containers considered the modern default?

Containers package your app with its dependencies so it runs identically everywhere, start in seconds, and pack efficiently onto hosts. The cost is orchestration: at scale you will want Kubernetes, which carries its own learning curve.

What are the downsides of serverless?

Serverless is brilliant for spiky, event-driven, or infrequent work, but it has two main catches. Cold starts mean the first invocation after idle is slower, and time and size limits make it a poor fit for long-running jobs.

What is a sensible default mix for a new app?

A good default in 2026 is containers for your main services and serverless for the glue such as events, cron jobs, and webhooks. Reach for raw VMs only when something specifically requires that level of control.

Was this article helpful?

Want to learn this properly?

Reading is a start. Compute models is a full interactive lesson in the Cloud Engineer path, with real terminal labs, production scenarios, and a completion record.