IaaS, PaaS, Containers or Serverless? Choosing Where a Model API Runs
One small ticket-scoring API, four ways to run it: a virtual machine, a container service, a platform or a serverless function. What each leaves to you, how each bill behaves, why cold starts hurt a model, and three questions that pick one.
What you will learn
- Explain IaaS, a container service, PaaS and serverless functions by what is yours to look after
- Compare the shape of the bill: a flat line while it's up, or one that follows the traffic
- Explain a cold start and why it matters for a model that loads at startup
- Pick a compute option for a workload with three questions
Before you start
- Which Cloud for What
- Containerising a Model API: A Dockerfile
Virtual machine, container service, platform, serverless function. These words get thrown around a lot, but all they describe is how much of the work is yours and how the bill behaves. In this article we take one service and ask where it should run, with a reason.
No prices here. Rates change, so you read them from the pricing page. What we'll look at is the shape of each bill.
Our workload
Let's be specific. The ticket priority service is a small FastAPI app that scores support tickets:
- It's already a Docker image, 685 MB when built.
- It loads its model once at startup and keeps it in memory, so the first log line is
{"level": "info", "msg": "model loaded"}. - Each request gets back a priority, low or high. It needs no GPU.
- It has a health check, so something is expected to keep it up.
Small, CPU only, loads once, stays up. That's what we're placing. (The tickets are synthetic.)
Who looks after what
Here's the whole idea in one picture. Five layers: the machine, the operating system, the runtime, the container and your app.
- Virtual machine (IaaS, infrastructure as a service). You start just above the hardware, so the operating system and everything on top is yours.
- Container service. The operating system is handled. You bring the image.
- Platform (PaaS, platform as a service). You bring your app, often just the code.
- Serverless function. You bring one function, and it wakes up for each request.
As you go across, less is yours to look after, and less is yours to control. That's the trade.
The virtual machine
You rent a server, log in, install Docker, and our image runs on it fine. But now patching the operating system is your job, and so is restarting things when the machine goes down. And it's billed while it's on, whether tickets come in or not.
So why pick it? Control. You need a specific GPU, a particular driver, or a job that runs for days. For a training job, that's often exactly right. For our small API, it's more than we need.
The container service
On AWS this is Fargate, and its product page calls it "serverless compute for containers". AWS calls it serverless; we're calling it a container service. The words blur here, so don't go by the label.
What you do is hand over the image and set a size. For us: 256 CPU units, 512 MB of memory, and a desired count of 1. There's no server for you to patch, which is why the page uses that word. But your task stays up, and it's billed while it's up. Our image goes in with no changes, and that's the strong point here. Google Cloud Run and Azure Container Apps sit in the same family.
The platform and the function
The platform. You connect a repository or hand over the image, and you get a web address. Deploys, restarts and certificates are taken care of, and for a small team that's a great deal. The catch is fewer choices on networking, machine sizes and regions, and moving away later takes some effort. Our API would be happy here too.
The serverless function. A request arrives, your function wakes up, answers and goes away. You pay per request and for the time it takes, so when nobody's calling, the compute bill is close to nothing.
But look at our service. It loads a model at startup, so a function that's been asleep has to load it again before it can answer. That wait is a cold start, and getting around it means changing how the app starts. Functions love short work that arrives in bursts. A small model with rare calls is fine. A big model that has to answer fast is a harder fit.
The shape of the bill
A virtual machine or an always-up task is a flat line: the same in the middle of the night as at lunch. A function follows the traffic: close to nothing when it's quiet, climbing when it's busy.
The Fargate pricing page says there are no upfront costs and you pay for the vCPU, memory and storage you use. So that meter reads size and time, not requests. Steady traffic suits the flat line; rare, spiky traffic suits the function. Where those lines cross depends on your rates and your traffic, so you'd work that out from the pricing page. Cost thinking turns this into a sum.
The questions that pick one
- Does it need a GPU, or control over the machine? Then a virtual machine, at least for that part.
- Does it sit idle most of the time, with short jobs? Then try a function.
- Otherwise, how much does your team want to run? Less: a platform. More say on networking, and an image already built: a container service.
Run our service through that. No GPU. It stays up and loads a model once. We already have the image. So, a container service, and that's why Fargate is our route to AWS.
| Option | You bring | Yours to look after | It bills | It suits |
|---|---|---|---|---|
| Virtual machine | A server and your image | The OS and everything above | While it is on | GPU, drivers, long jobs |
| Container service | The image | The image and your app | While the task is up | An image you already have |
| Platform | Your app or an image | Your app | While it runs | Small teams that want less to run |
| Function | One function | The function | Per request and time | Short work in bursts |
Pick for today's workload, not for a workload you might have one day.
Common mistakes
- Going by the label. "Serverless" is on the Fargate page too. Ask what's yours and how it bills.
- Putting a model that loads at startup into a function without planning for the cold start.
- Renting a VM for a small API and then owning patching and restarts for no reason.
Recap
| Idea | Remember |
|---|---|
| What differs | What's yours: the machine, the container, the app, or one function |
| The bill | Flat while it's up, or follows the traffic; rates from the pricing page |
| The pick | Need control: VM. Short and rare: function. Otherwise: platform or container service |
| Our service | Container service (Fargate) |
Try it yourself: think of a model that's called only a few times a day, and run it through the same questions. Which would you pick, and how long a cold start could you accept?
Built this? Share your solution in the StudyEasy AI Community.
Join free on Skool →Which Cloud for What: AWS, Azure, Google Cloud, GPU Clouds, Edge and Platforms
Next →Kubernetes at a High Level: Pods, a Deployment and a Service for a Model API
StudyEasy AI Community
Learn AI engineering, share what you build, and connect with other learners.
Free resources: lesson files, notebooks and code
Ask questions and join engineering discussions
Meet real people learning and building with AI
Machine Learning Engineer: From First Model to ML Engineer
Learn machine learning in Python, then ship it: data analysis, regression, classification, tuning, deployment and MLOps.View on Udemy ↗: Machine Learning Engineer: From First Model to ML Engineer (opens in a new tab)Related articles
Python Virtual Environments: One Project, One Toolbox
Why every Python project gets its own virtual environment: two projects that need different versions of requests, python -m venv .venv, activation, pip install and the PyCharm setting that activates it for you.
Git and GitHub Fundamentals: Commits, Branches, Push and Pull
The Git you use every day, on a tiny hello-ml project: commits as save points, the staging area, a branch merged with a fast-forward, then push, clone, pull and pull requests with a teammate.
Testing a FastAPI App with pytest: Three Small Tests
A tiny FastAPI app with a Hello World route and a name route that refuses numbers, three pytest tests that check it, and what happens when the validation is deleted by mistake.
Config and Logging Instead of Hard-Coded Values in ML Training
Take the hard-coded values out of a car price training script: one config.toml read with tomllib, logging with levels and a run id on every line, and secrets read from the environment. Same RMSE, 2195, before and after.