Single logo
  • Courses
  • Blog
  • About
Join for freeJoin free
Machine Learning
  • First Look at a Dataset: 6 Checks Before You Plot or Model
  • Plotting Distributions with seaborn: Histograms, KDE, Counts and log1p
  • Scatter Plots and Pair Plots: See How Two Columns Relate
  • Finding Outliers: Box Plots, Violin Plots and the IQR Rule
  • Correlation and Heatmaps: Covariance, df.corr() and What They Miss
  • Train-Test Split and Data Leakage: Split First, Learn After
  • Handling Missing Data: Count the Blanks, Then Fill Them with SimpleImputer
  • Encoding Categorical Data: OrdinalEncoder, OneHotEncoder and LabelEncoder
  • Feature Scaling: StandardScaler, MinMaxScaler and Which Models Care
  • Pipelines and ColumnTransformer: All Preprocessing and the Model in One Object
  • Feature Selection and the Curse of Dimensionality: Keep the Columns That Matter
  • Project: Preprocess Rain in Australia from Raw CSV to Model-Ready Data
    Regression
    • Linear Regression and the Cost Function: Draw a Line, Score It
    • Gradient Descent Explained: Feel the Slope, Step Downhill
    • Linear Regression in scikit-learn: Fit, Predict and Read the Price Tags
    • Regression Metrics: MAE, RMSE, R-squared and the Baseline to Beat
    • Polynomial Regression, Overfitting and Underfitting: Bend the Line, Watch the Test Score
    • Regularisation with Ridge and Lasso: Put a Price on Big Weights
    Classification and Evaluation
    • Logistic Regression and the Sigmoid: Score, Squash, Decide
    • Logistic Regression in scikit-learn: predict, predict_proba and Softmax
    • Why Accuracy Lies: The Confusion Matrix, Baselines and Type I/II Errors
    • Precision, Recall and F1 Score: Two Questions and One Balance
    • ROC Curve, AUC and Choosing a Classification Threshold
    • Handling Imbalanced Data: class_weight, SMOTE and the Resampling Leak
    • Cross-Validation: KFold, StratifiedKFold, cross_val_score and cross_validate
    Classic Algorithms
    • K-Nearest Neighbours (KNN): Distance, k and Why Scaling Is a Must
    • Naive Bayes: Prior Times Likelihood, a Spam Filter by Hand and GaussianNB
    • Support Vector Machines (SVM): The Widest Road, C, Kernels and gamma
    • Decision Trees: Gini, max_depth and Feature Importances on Rain in Australia
    • Bagging and Random Forest: Many Shaky Trees, One Steady Answer
    • Boosting: Residuals by Hand, AdaBoost, Gradient Boosting and XGBoost
    • Voting and Stacking: Does a Team of Models Beat the Best One?
    Model Selection and Tuning
    • Hyperparameter Tuning with GridSearchCV and RandomizedSearchCV
    • Which Features Matter? Feature Importances, Permutation Importance and SHAP
    • Project: The Classification Master Template, from Raw CSV to a Saved Model
    • K-Means Clustering: Find Groups in Data With No Labels
    • Choosing k for K-Means: the Elbow Method and the Silhouette Score
    • Hierarchical Clustering and DBSCAN: Dendrograms, Linkage, eps and Noise
    • Dimensionality Reduction with PCA: 13 Columns Down to 2
    • Association Rules and Market Basket Analysis: Support, Confidence, Lift and Apriori
    • Recommender Systems: Item-Based Collaborative Filtering with Cosine Similarity
    • Bag of Words with CountVectorizer: Turn Text into Word Counts
    • TF-IDF with TfidfVectorizer: Common Words Fade, Rare Words Speak
    • Build a Text Classifier with TF-IDF and a Pipeline: Naive Bayes vs LinearSVC
    • Why Neural Networks: Pixels, One Neuron and Layers
    • The Forward Pass and Activation Functions: ReLU, Sigmoid, Tanh and Softmax
    • Loss and Backpropagation: How Wrong, and Who Is to Blame
    • The Training Loop: Epochs, Mini-Batches, Learning Rate and Optimisers
    • Your First Neural Network with Keras: MNIST Digits at 97.7%
    • The Same Network in PyTorch: DataLoader, nn.Module and the Five-Line Training Loop
    • Convolutional Neural Networks (CNN) Basics: Filters, Feature Maps and Pooling
    • Embeddings: Words as Vectors, Cosine Similarity and nn.Embedding
    • Similarity Search: Finding the Closest Vectors with NumPy and NearestNeighbors
    • Dropout, Early Stopping and Batch Norm: Judge Each One by the Validation Curve
    • Transfer Learning on Images: A Frozen ResNet-18, a Small Head and an Honest Baseline
    • Attention Explained Without the Maths: Query, Key, Value and the Word "it"
    • Transformer Building Blocks in PyTorch: Follow the Shapes Through Attention and a Block
    • Pretrained Models from Hugging Face: A Sentiment Pipeline and Sentence Embeddings on a CPU
    • Loading a Language Model and Running Inference: Download, Load, Tokenize, Generate
    • Model Size and Memory: Parameters x Bytes, Quantization, and Where to Run a Model
    • Training on a GPU: Mixed Precision, Gradient Accumulation and Checkpoints That Really Resume
    • When NOT to Fine-Tune: A Decision Tree of Prompt, RAG, Tools, Then Fine-Tuning
    • Full Fine-Tuning vs LoRA vs QLoRA: What Each One Changes and What It Costs
    • LoRA Fine-Tune of a Tiny Model: Teach SmolLM2-135M Your House Style on a CPU
    • Knowledge Distillation: Teach a Model 100 Times Smaller From a Teacher's Soft Labels
    • Serving Open Models: Continuous Batching, vLLM and Cold Starts
      Engineering Basics
      • Python Virtual Environments: One Project, One Toolbox
      • Git and GitHub Fundamentals: Commits, Branches, Push and Pull
      • Testing a FastAPI App with pytest: Three Small Tests
      • Config and Logging Instead of Hard-Coded Values in ML Training
      • SQL Essentials for Python: SELECT, WHERE, JOIN and GROUP BY
      Data and Features in Production
      • Time Splits and Group Splits: Make the Split Match How the Model Is Used
      • Time Series Basics: Lags, Rolling Windows and Walk-Forward Backtesting
      • Feature Engineering Patterns, Each One Tested: Date Parts, Differences, Windows and Target Encoding
      • Point-in-Time Correctness: Join Features as of Each Event with merge_asof
      • Data Validation and Schema Checks: Stop Bad Input Before It Reaches the Model
      • Training-Serving Skew: Same Model, Different Inputs, and How to Detect It
      • Feature Stores: Offline and Online Stores, and When You Actually Need One
      • Data Versioning with DVC: Tie Every Model to the Exact Data That Trained It
      Experiments and Model Quality
      • MLOps in One Picture: Code, Data, Model and the Lifecycle Loop
      • Experiment Tracking with MLflow: Log Params, Metrics and the Model, Then Compare Runs
      • MLflow Model Registry Aliases: Serve the Champion, Ship a New Version and Roll Back in One Line
      • The Cost of Being Wrong: Baselines, a Price per Mistake and the Cheapest Threshold
      • Probability Calibration: Can You Trust the 0.8? Reliability Curves, Platt and Isotonic
      • Slice Evaluation and Fairness Checks: Score the Model Group by Group
      Serving Models
      • Saving and Loading Models with joblib: One Pipeline, One File
      • FastAPI Hello World: Routes, uvicorn and the Free Swagger Page
      • Deploy a Machine Learning Model with FastAPI: POST /predict for a Saved Model
      • Docker Essentials for ML: Images, Containers and Volumes with a Model API
      • Containerising a Model API: A Dockerfile for FastAPI and scikit-learn, Line by Line
      • Online, Batch or Streaming? Picking the Serving Pattern for an ML Model
      • A Production FastAPI for an ML Model: Input Limits, /health, /ready and a Model Version
      • Batch Scoring a Million Rows: Chunks, a Run ID and a Safe Rerun
      • Latency Math: p50, p95, p99 and Why the Tail Reaches Your Users
      • Measuring Latency of an ML API: Timing Inside with OpenTelemetry, Outside with a Load Test and Locust
      • Making ML Inference Fast: ONNX, Micro-Batching and Quantisation, Measured
      • Sizing and Autoscaling an Inference Service: From One Replica to a Replica Count
      Pipelines, CI/CD and Cloud
      • The Training Pipeline as a DAG: Steps, Files, Retries and a Safe Rerun
      • Orchestrating ML Pipelines with Airflow: Schedule, Retries and Backfill
      • Retries and Backoff for Reliable Tasks: Retry What Heals, Wait Longer, Add Jitter, Set Limits
      • CI with GitHub Actions: Run the Tests and Build the Docker Image on Every Push
      • CI/CD for ML: A Quality Gate That Blocks a Weaker Model, Even When Every Test Passes
      • Which Cloud for What: AWS, Azure, Google Cloud, GPU Clouds, Edge and Platforms
      • IaaS, PaaS, Containers or Serverless? Choosing Where a Model API Runs
      • Kubernetes at a High Level: Pods, a Deployment and a Service for a Model API
      • Managed ML Platforms: What SageMaker, Vertex AI and Azure ML Give You, and Tie You To
      • Deploying a Model API to AWS: ECR, Secrets Manager, CloudWatch and Fargate, Then Teardown
      • Cloud Cost Thinking for ML: Size x Count x Hours x Rate, and Three Decisions Worth Ten Times
      Monitoring and Release
      • Monitoring Drift and Retraining: When a Model Gets Worse With No Code Change
      • Drift Detection in Code: PSI Bin by Bin, the KS Test, Evidently and a Measured Threshold
      • Shadow, Canary and Rollback: Releasing a New Model Without Betting Everything on It
      • A/B Tests for Models: Did the New Model Make Things Better for People?
      • When Labels Arrive Weeks Late: What to Watch Before You Can Grade the Model
      • Retraining Triggers: Schedule, Drift and Performance, Wired to One Retrain Pipeline
      • The User Feedback Loop: Why Thumbs Up Isn't the Truth, and What a Small Random Review Adds
      • Debugging a Model in Production: A Four-Step Runbook, Cheap Checks First
      • Project: Car Price Predictor End to End, from CSV to a FastAPI Price API
      1. Blog
      2. /
      3. Machine Learning
      4. /
      5. MLOps and Production ML

      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.

      Chaand Sheikh

      ·27 November 2026Pipelines, CI/CD and Cloud

      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.

      Who looks after what, by option layer virtual machine IaaS container service platform PaaS function serverless your app container runtime OS machine yoursyoursyoursyourshandled yoursyourshandledhandledhandled yourshandledhandledhandledhandled one functionhandledhandledhandledhandled left to right: less to look after, and less control
      Red is yours to look after, green is handled for you.
      • 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

      Flat bill vs a bill that follows traffic cost (no prices) night lunch night one day (schematic) flat: always up follows traffic: function
      Shapes only. Where the lines cross depends on your rates and your traffic.

      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

      1. Does it need a GPU, or control over the machine? Then a virtual machine, at least for that part.
      2. Does it sit idle most of the time, with short jobs? Then try a function.
      3. 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.

      OptionYou bringYours to look afterIt billsIt suits
      Virtual machineA server and your imageThe OS and everything aboveWhile it is onGPU, drivers, long jobs
      Container serviceThe imageThe image and your appWhile the task is upAn image you already have
      PlatformYour app or an imageYour appWhile it runsSmall teams that want less to run
      FunctionOne functionThe functionPer request and timeShort 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

      IdeaRemember
      What differsWhat's yours: the machine, the container, the app, or one function
      The billFlat while it's up, or follows the traffic; rates from the pricing page
      The pickNeed control: VM. Short and rare: function. Otherwise: platform or container service
      Our serviceContainer 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 →
      ← Previous
      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
      Single logo

      StudyEasy AI Community

      Hosted onSkool

      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

      Join free on Skool
      Go deeper with a course

      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.

      On this page
      • Our workload
      • Who looks after what
      • The virtual machine
      • The container service
      • The platform and the function
      • The shape of the bill
      • The questions that pick one
      • Common mistakes
      • Recap
      Single logo

      StudyEasy AI Community

      Hosted onSkool

      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

      Join free on Skool
      Go deeper with a course

      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)

      Single logo

      Empowering Education, One Course at a Time

      About
      About usContact usFAQs
      Legal
      Terms of ServicePrivacy Policy

      © 2026 StudyEasy Organization. All rights reserved.