Cloud Cost Thinking for ML: Size x Count x Hours x Rate, and Three Decisions Worth Ten Times
Think about a service's cost before the bill arrives: the sum size x count x hours x rate, the smaller lines nobody watches, three decisions that each move the bill 12 to 24 times, and why a budget warns but only teardown stops it.
What you will learn
- Write most compute bills as size x count x hours x rate, and see which parts are your decisions
- List the smaller lines on a bill: registry, logs, secrets and data leaving the cloud
- Spot three decisions that can move a bill by ten times: idle time, oversizing, always-on instead of batch
- Use a budget to warn, teardown to stop, and a check to confirm
Before you start
- Deploying a Model API to AWS
- IaaS, PaaS, Containers or Serverless?
This article is about thinking through what a service costs before the bill shows up. Prices change, so the place to read them is the provider's pricing page. What you'll get here is the shape of the sum, and the decisions that can move a bill by ten times. The example is our ticket service and its route to AWS.
The machine left on
The most common surprise first. You rent a machine to train a model, and training takes two hours a day.
- 2 hours × 30 days = 60 hours a month.
- Now you forget to switch it off: 24 hours × 30 days = 720 hours.
Same machine, same model, and twelve times the hours. The cloud can't tell that you're done, so idle time is the first thing to look for.
The sum behind the bill
Most compute bills follow one sum: size × count × hours × rate.
- Size. The Fargate pricing page says there are no upfront costs and you pay for the vCPU, memory and storage you use. Our plan sets the size at 256 CPU units and 512 MB.
- Count. Desired count, 1.
- Hours. Left up all month, that's 720.
- Rate. It changes, so you read it on the pricing page.
Notice that three of the four are your decisions. The rate is the only part the provider sets.
The smaller lines
Compute is the big line, but it isn't the only one:
| Line | In our route | What makes it grow |
|---|---|---|
| Registry (ECR) | Our 685 MB image | Old versions pile up if nobody cleans them |
| Logs (CloudWatch) | Every request writes a line | Keeping them forever: set how long they stay |
| Secrets (Secrets Manager) | One key | Small, but still a line |
| Data leaving the cloud | Whatever the service sends out | Often charged too |
Each of these AWS product pages has a Pricing tab at the top. Open it before you build, not after the bill arrives.
Three decisions worth ten times
Traffic matters too, but autoscaling adds tasks only when they're needed, so traffic isn't one of the big levers. These three are:
- Leaving things on. We saw it: twelve times the hours.
- Size and count. Pick a size four times bigger just to be safe, run three copies, and that's twelve times the capacity, without one extra customer.
- Whether you need to answer right away. Say our model scores tickets in one nightly batch of about an hour. That's 30 hours a month against 720, so twenty-four times fewer hours. (The patterns are compared in online, batch or streaming, and a batch job is built in batch scoring a million rows.)
Whether a high-priority ticket can wait until morning isn't a technical question. It's a business call. If it can't wait, you pay for always-on, and you know why.
Warn, stop, check
- Warn: a budget. The AWS Budgets page talks about keeping you informed on forecasted spend. But a plain budget only warns you; it doesn't switch anything off. Our deploy plan has it as the last step, and it's worth making it the first.
- Stop: teardown, in a fixed order. Desired count 0 first, then the service, the repository, the secret and the log group.
- Check. Look at the billing page the next day and make sure that line has stopped.
It isn't gone until something tells you it's gone.
Common mistakes
- Estimating from traffic only. An always-up task bills by size and hours, busy or not.
- Treating the budget as a brake. It's a bell. The meter keeps running.
- Quoting a price from memory. Rates change. Write down size, count and hours, and fill in the rate from today's pricing page.
Recap
| Idea | Remember |
|---|---|
| The sum | Size × count × hours × rate; three of the four are yours |
| Smaller lines | Registry, logs, secrets, data leaving the cloud |
| Ten-times decisions | Idle time (12×), oversizing (12×), always-on where a batch would do (24×) |
| Warn, stop, check | A budget warns, teardown stops, a check confirms |
Try it yourself: take a service you run or plan to run. Write down its size, count and hours for a month, then fill in the rate from the pricing page.
Built this? Share your solution in the StudyEasy AI Community.
Join free on Skool →Deploying a Model API to AWS: ECR, Secrets Manager, CloudWatch and Fargate, Then Teardown
Next →Monitoring Drift and Retraining: When a Model Gets Worse With No Code Change
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.