Module 10

MLOps & Cloud

MLOps and cloud — versioning, deploying, monitoring, and operating machine learning systems in production.

20 lessonsAI & MLHarinIT Academy
Module 10 · Lesson 10.1

Git & GitHub

Chapter 10.1 – Git & GitHub

  • Git is the backbone of modern software development and MLOps.

Every AI engineer, Data Engineer, Software Engineer, and MLOps Engineer uses Git every day to track code changes, collaborate with teams, and manage projects.

Learning Objectives

By the end of this chapter, you will be able to

  • Understand Version Control Systems (VCS).
  • Learn Git architecture.
  • Install Git.
  • Use essential Git commands.
  • Work with branches.
  • Merge code changes.
  • Resolve merge conflicts.
  • Use GitHub effectively.
  • Collaborate using Pull Requests.
  • Understand GitHub Actions.

Apply Git best practices in AI/ML projects.

1. Introduction

Imagine you are developing a Machine Learning model.

Day 1

You create

  • house_price_model.py
  • Day 5
  • You improve the model.
  • Day 10

You accidentally delete an important section of code.

How do you recover it?

Without Git

  • Very difficult.

With Git

✅ Simply restore the previous version.

This is why Git exists.

2. What is Git?

Definition

Git is a distributed Version Control System (VCS) that tracks changes in files, allowing developers to collaborate, maintain history, and restore previous versions.

Git was created by Linus Torvalds in 2005 to support Linux kernel development.

3. What is Version Control?

Version Control is the process of tracking changes made to files over time.

Instead of

  • Project_Final.py
  • Project_Final2.py
  • Project_Final3.py
  • Project_Final_Final.py
  • Project_Final_Really_Final.py

Git stores every change in an organized history.

4. Why Do We Need Git?

Suppose three developers work on the same project.

Developer A
Developer B
Developer C

Without Git

  • Files get overwritten.
  • Changes are lost.
  • Collaboration becomes difficult.

With Git

  • Everyone works independently.
  • Changes are merged safely.
  • History is preserved.

5. What is GitHub?

Git stores your project locally.

GitHub is a cloud platform that hosts Git repositories online, making collaboration easier.

Think of it this way

GitGitHub
Version Control SystemCloud hosting platform for Git repositories
Installed on your computerAccessible through the web
Tracks code historyEnables collaboration, code review, and repository hosting

6. Git Architecture

Working Directory

git add

Staging Area

git commit

Local Repository

git push

GitHub Repository

7. Working Directory

The Working Directory contains your project files.

Example

Project/

app.py

model.py

requirements.txt

Changes here are not yet tracked until you stage them.

8. Staging Area

The Staging Area is a temporary place where you choose which changes will be included in the next commit.

Example

git add app.py

Only app.py is staged.

9. Commit

A commit is a snapshot of your project at a specific point in time.

Example

git commit -m "Added prediction API"

Good commit messages describe what changed and, when useful, why.

10. Local Repository

The Local Repository stores the complete history of your project on your computer.

Example

Commit 1
Commit 2
Commit 3
Commit 4

11. Remote Repository

The Remote Repository is hosted on platforms such as GitHub.

Example

Local Repository

git push

GitHub

This enables collaboration and backup.

12. Git Workflow

Modify Files

git status

git add

git commit

git push

13. Installing Git

Windows

Download Git from

https://git-scm.com/

Verify Installation

git --version

Example Output

git version 2.45.0

(The version number will vary.)

14. Configure Git

Before using Git

git config --global user.name "Sreehari"
git config --global user.email "your_email@example.com"

Check configuration

git config --list

15. Initialize a Repository

Create a new Git repository.

git init

Output

Initialized empty Git repository

16. Check Repository Status

git status

Example Output

On branch main

Untracked files

app.py

17. Add Files

Add one file

git add app.py

Add all files

git add .

18. Commit Changes

git commit -m "Initial commit"

This creates the first snapshot.

19. View Commit History

git log

Example

  • Commit 1
  • Commit 2
  • Commit 3

A more compact view

git log --oneline

20. Clone a Repository

Download an existing repository

git clone https://github.com/user/project.git

21. Connect to GitHub

Add a remote repository

git remote add origin https://github.com/user/project.git

View configured remotes

git remote -v

22. Push Changes

Upload commits

git push origin main

23. Pull Changes

Download updates

git pull origin main

This fetches changes from the remote repository and merges them into your current branch.

24. Branches

Branches allow multiple developers to work independently.

main
├── feature/login
├── feature/chatbot
└── bugfix/api

25. Create a Branch

git branch feature-api

Switch to it

git checkout feature-api

Or create and switch in one command

git checkout -b feature-api

Modern Git also supports

git switch -c feature-api

26. Merge Branches

git checkout main
git merge feature-api

Now the feature becomes part of the main branch.

27. Merge Conflict

Suppose

Developer A edits

learning_rate = 0.01

Developer B edits

learning_rate = 0.001

Git cannot decide automatically.

Conflict markers appear

<<<<<<< HEAD

learning_rate = 0.01

=======

learning_rate = 0.001

>>>>>>> feature

Resolve manually.

Then

git add .
git commit

28. Pull Requests (PR)

Instead of merging directly,

developers create a Pull Request.

Workflow

Feature Branch
Push to GitHub
Open Pull Request
Code Review
Approve
Merge

Benefits

  • Code review
  • Automated testing
  • Team collaboration

29. GitHub Actions (CI)

GitHub Actions automate workflows.

Example

Every push

Run tests
Build project
Deploy automatically

Example workflow file

name: Python Tests

on: [push]

jobs

test

runs-on: ubuntu-latest

30. Common Git Commands

CommandPurpose
git initCreate a repository
git cloneDownload a repository
git statusCheck status
git add .Stage all changes
git commit -mSave changes
git logView history
git branchList branches
git checkoutSwitch branches
git mergeMerge branches
git pullDownload changes
git pushUpload changes

31. Git in Machine Learning Projects

Example project

HousePricePrediction/

├── data/

├── notebooks/

├── models/

├── src/

├── app/

  • ├── requirements.txt
  • ├── README.md
  • └── .gitignore

Git tracks

  • Source code
  • Configuration files
  • Documentation

Large datasets and trained models are often managed using tools like DVC, cloud storage, or model registries rather than storing them directly in Git.

32. The .gitignore File

Some files should not be committed.

Example

  • __pycache__/
  • .env
  • *.log
  • venv/
  • .ipynb_checkpoints/

This prevents unnecessary or sensitive files from entering the repository.

33. Best Practices

  • Write meaningful commit messages.
  • Commit small, logical changes.
  • Pull before pushing to avoid conflicts.
  • Use feature branches.
  • Review Pull Requests before merging.
  • Never commit secrets (API keys, passwords).
  • Keep the main branch stable.

34. Common Mistakes

  • Committing passwords or API keys.
  • Working directly on the main branch.
  • Making one huge commit with unrelated changes.
  • Ignoring merge conflicts.
  • Forgetting to pull before pushing.

35. Interview Questions

Beginner

  • What is Git?
  • What is GitHub?
  • What is Version Control?
  • What is a Commit?
  • What is the Staging Area?

Intermediate

  • Difference between Git and GitHub?
  • What is a Branch?
  • What is Merge?
  • What is a Pull Request?
  • What is a Merge Conflict?

Advanced

  • Explain the Git workflow.
  • What is GitHub Actions?
  • How would you manage large ML datasets in Git?
  • Why should secrets never be committed?
  • How do you resolve merge conflicts?

Mini Project

Version-Control an ML Project

  • Objective
  • Create a Git repository for a machine learning project.
  • Tasks
  • Initialize a repository.
  • Add a .gitignore file.
  • Commit the initial project.
  • Create a feature branch.
  • Add a new prediction feature.

Merge the branch using a Pull Request.

Push the project to GitHub.

Chapter Summary

Git is a distributed version control system that tracks changes to your code, while GitHub is a cloud-based platform for hosting Git repositories and collaborating with others. Together, they enable developers to work efficiently, maintain a complete project history, review code through Pull Requests, and automate workflows using GitHub Actions. Git is a foundational skill for software engineering, data engineering, machine learning, and MLOps.

Git Workflow Cheat Sheet

Create Project

git init

Modify Files

git status

git add .

git commit -m "message"

git push origin main

GitHub Repository

What's Next?

In Chapter 10.2 – Docker, you'll learn how to package your machine learning application—including Python code, dependencies, and configuration—into a portable container that runs consistently on your laptop, a server, or the cloud. Docker is one of the most important technologies in modern MLOps because it eliminates the classic "it works on my machine" problem.

Module 10 · Lesson 10.2

Docker

Chapter 10.2 – Docker

  • Docker is one of the most important technologies in MLOps.

Almost every production AI application—whether it's deployed on Azure, AWS, Google Cloud, or Kubernetes—runs inside a Docker container.

Learning Objectives

By the end of this chapter, you will be able to

  • Understand what Docker is.
  • Learn why Docker is important.
  • Understand Containers vs Virtual Machines.
  • Learn Docker Architecture.
  • Work with Docker Images and Containers.
  • Write Dockerfiles.
  • Use Docker Compose.
  • Build Docker images.
  • Deploy ML applications in Docker.
  • Learn Docker best practices.

1. Introduction

  • Imagine you build a Machine Learning application on your laptop.
  • It works perfectly.
  • You send it to another developer.

They run it and get

ModuleNotFoundError

No module named 'scikit-learn'

Another developer gets

Python version not supported

Someone else gets

TensorFlow version mismatch

This problem is called

"It works on my machine."

Docker solves this problem.

2. What is Docker?

Definition

Docker is an open-source platform that packages an application along with its dependencies, libraries, and runtime into a portable container that can run consistently on any system that supports Docker.

  • Think of Docker as a shipping container.
  • Just as a shipping container carries goods safely across ships, trains, and trucks,
  • Docker containers carry software safely across laptops, servers, and cloud platforms.

3. Why Do We Need Docker?

Suppose your ML application requires

  • Python 3.11
  • TensorFlow 2.18
  • NumPy 2.x
  • Pandas
  • FastAPI
  • CUDA libraries

Without Docker

Every server must be configured manually.

With Docker

Everything is packaged together.

Run

docker run house-price-api

The application runs the same everywhere.

4. Containers vs Virtual Machines

Virtual Machine

Application
Guest Operating System
Hypervisor
Host Operating System
Hardware

Each Virtual Machine contains its own operating system.

Advantages

Strong isolation

Disadvantages

  • Large size
  • Slower startup
  • Higher memory usage
  • Docker Container
Application
Libraries
Docker Engine
Host Operating System
Hardware

Containers share the host operating system kernel.

Advantages

  • Lightweight
  • Fast startup
  • Lower memory usage
  • Easier to deploy
  • Containers vs Virtual Machines
DockerVirtual Machine
LightweightHeavyweight
Shares host OSSeparate guest OS
Starts in secondsStarts in minutes
Uses less memoryUses more memory
Ideal for MLOpsIdeal for full OS isolation

5. Docker Architecture

Docker Client
Docker Commands

Docker Engine

┌─────────────┴─────────────┐

▼ ▼

Docker Images Docker Containers

6. Docker Components

Docker Client

This is where you type commands.

Example

docker build
  • Docker Engine
  • The service that creates and manages containers.
  • Docker Image

An Image is a blueprint or template for creating containers.

Example

Python
Install FastAPI
Install NumPy
Install Pandas
Copy Application
Image

Docker Container

A Container is a running instance of an image.

Example

Docker Image

docker run

Running Container

7. Image vs Container

ImageContainer
BlueprintRunning application
Read-onlyRead-write while running
Stored on diskRunning in memory and on disk
Can create many containersCreated from one image

Example

Python Image
Container 1
  • Container 2
  • Container 3
  • One image can create multiple containers.

8. Installing Docker

Windows

  • Download
  • Docker Desktop
  • After installation

Check version

docker --version
  • Example Output
  • Docker version 27.x.x
  • (The version number will vary.)

9. First Docker Command

docker run hello-world

Docker will

  • Download the image (if needed).
  • Create a container.
  • Run the program.
  • Display a success message.

10. Docker Workflow

Application

Dockerfile

docker build

Docker Image

docker run

Docker Container

11. Dockerfile

A Dockerfile contains instructions to build an image.

Example

  • FROM python:3.11
  • WORKDIR /app
  • COPY . .
  • RUN pip install -r requirements.txt
  • CMD ["python", "app.py"]

Explanation

  • FROM → Base image.
  • WORKDIR → Working directory.
  • COPY → Copy project files.
  • RUN → Execute commands during image build.
  • CMD → Default command when the container starts.

12. Build Docker Image

docker build -t house-price-api .

Meaning

docker build

Create Image
Name

house-price-api

13. View Images

docker images

Example

RepositoryTag
house-price-apilatest
python3.11

14. Run a Container

docker run house-price-api

If your application is a web API, expose a port

docker run -p 8000:8000 house-price-api

Here

First 8000 → Host machine port.

Second 8000 → Container port.

15. Running Containers

List running containers

docker ps

List all containers

docker ps -a

16. Stop a Container

docker stop container_id

17. Remove a Container

docker rm container_id

18. Remove an Image

docker rmi image_name

19. Docker Hub

Docker Hub is a cloud repository for Docker images.

Examples

  • Python
  • Ubuntu
  • PostgreSQL
  • Redis
  • MongoDB
  • Nginx

Workflow

Docker Hub
Pull Image
Run Container

20. Docker Compose

Suppose your project uses

  • FastAPI
  • PostgreSQL
  • Redis
  • Instead of starting each container manually,
  • Docker Compose starts them together.

Example

version: "3"

services

app

build: .

ports

- "8000:8000"

db

image: postgres

redis

image: redis

Start everything

docker compose up

21. Docker Volumes

Containers are temporary.

  • If a container is deleted,
  • its internal data may also be lost.
  • Volumes store data outside the container.
Container
Volume
Persistent Data

Example

  • Database files
  • Model files
  • Logs
  • Uploaded documents

22. Docker Networking

Containers communicate through networks.

Example

FastAPI
Docker Network
PostgreSQL

23. Docker for Machine Learning

Typical ML project

ML Model
FastAPI
Docker
Cloud

Your Docker image may contain

  • Python
  • NumPy
  • Pandas
  • Scikit-learn
  • FastAPI
  • Trained Model
  • API Code
  • Everything is packaged together.

24. Dockerizing a FastAPI Model

Project

HousePriceAPI/

  • ├── app.py
  • ├── model.pkl
  • ├── requirements.txt
  • └── Dockerfile

Dockerfile

  • FROM python:3.11
  • WORKDIR /app
  • COPY . .
  • RUN pip install -r requirements.txt
  • EXPOSE 8000

CMD ["uvicorn","app:app","--host","0.0.0.0","--port","8000"]

This creates a production-ready API container.

25. Docker in MLOps Pipeline

Train Model

Save Model

FastAPI

Docker Image

Docker Registry

Kubernetes

Production

26. Advantages

  • Consistent environments.
  • Easy deployment.
  • Lightweight.
  • Portable.
  • Faster than virtual machines.
  • Simplifies dependency management.

27. Limitations

  • Containers share the host kernel, so they are not the same as full virtual machines.
  • Large ML images can become very large if unnecessary packages are included.
  • GPU support requires additional configuration (for example, NVIDIA Container Toolkit).

28. Best Practices

  • Use lightweight base images when possible.
  • Pin dependency versions.
  • Keep images small.
  • Use .dockerignore to exclude unnecessary files.
  • Store secrets outside the image.
  • Use multi-stage builds for production images when appropriate.

29. Common Mistakes

  • Copying unnecessary files into the image.
  • Running applications as the root user when avoidable.
  • Hardcoding passwords or API keys.
  • Forgetting to expose the required port.
  • Building very large images with unused packages.

30. Interview Questions

Beginner

  • What is Docker?
  • What is a Container?
  • What is an Image?
  • What is Docker Hub?
  • Difference between Image and Container?

Intermediate

  • Docker vs Virtual Machine?
  • What is Docker Compose?
  • What is a Dockerfile?
  • What are Docker Volumes?
  • What are Docker Networks?

Advanced

  • How would you Dockerize a Machine Learning application?
  • How would you reduce Docker image size?
  • Why use Docker in MLOps?
  • How do containers communicate?
  • How would you deploy a FastAPI application using Docker?

Mini Project

  • Dockerize a House Price Prediction API
  • Project Structure
  • HousePriceAPI/
  • ├── app.py
  • ├── model.pkl
  • ├── requirements.txt
  • ├── Dockerfile
  • └── .dockerignore
  • Tasks
  • Train a regression model.
  • Save it as model.pkl.
  • Build a FastAPI prediction API.
  • Create a Dockerfile.
  • Build the Docker image.
  • Run the container.

Test the API using a browser or Postman.

Chapter Summary

Docker packages an application and all of its dependencies into a portable container, ensuring it runs consistently across development, testing, and production environments. It has become a cornerstone of modern MLOps because it simplifies deployment, improves reproducibility, and integrates seamlessly with orchestration platforms like Kubernetes and cloud services.

Docker Workflow Cheat Sheet

Application

Dockerfile

docker build

Docker Image

docker run

Container

Docker Hub / Registry

Kubernetes / Cloud

What's Next?

In Chapter 10.3 – Kubernetes, you'll learn how to deploy and manage multiple Docker containers at scale. You'll explore concepts such as Pods, Deployments, Services, ReplicaSets, Auto Scaling, and Rolling Updates, which enable highly available and production-ready AI applications.

Module 10 · Lesson 10.3

Kubernetes

Chapter 10.3 – Kubernetes

  • Docker creates containers. Kubernetes manages them.

Modern companies such as Google, Microsoft, Amazon, Netflix, Uber, Spotify, and OpenAI use Kubernetes (often abbreviated as K8s) to deploy, scale, and manage thousands of containerized applications.

Learning Objectives

By the end of this chapter, you will be able to

  • Understand what Kubernetes is.
  • Learn why Kubernetes is needed.
  • Understand Kubernetes architecture.
  • Learn Pods, Nodes, Clusters, Deployments, ReplicaSets, and Services.
  • Understand Load Balancing and Auto Scaling.
  • Deploy Machine Learning models on Kubernetes.
  • Learn Kubernetes best practices.
  • Prepare for Kubernetes interview questions.

1. Introduction

Imagine you built an AI model using FastAPI and Docker.

You deploy it.

Initially

10 Users

Everything works well.

One month later

100,000 Users

Problems begin

  • Server crashes.
  • API becomes slow.
  • Memory usage reaches 100%.
  • Some containers stop unexpectedly.

How do you automatically

  • Restart failed containers?
  • Scale to handle more users?
  • Distribute traffic?
  • Update applications without downtime?

Kubernetes solves these problems.

2. What is Kubernetes?

Definition

Kubernetes is an open-source container orchestration platform that automates the deployment, scaling, networking, and management of containerized applications.

Kubernetes was originally developed by Google based on its internal container management systems and is now maintained by the Cloud Native Computing Foundation (CNCF).

3. Why Do We Need Kubernetes?

Docker can run containers.

Example

Docker
Run Container
Application Starts

But Docker alone doesn't automatically handle

  • High availability
  • Auto scaling
  • Load balancing
  • Self-healing
  • Rolling updates
  • Kubernetes provides these capabilities.

4. Kubernetes vs Docker

DockerKubernetes
Creates containersManages containers
Single-host focusMulti-node cluster management
Packages applicationsOrchestrates applications
Manual scalingAutomatic scaling
Basic networkingAdvanced service networking

Important: Kubernetes uses container runtimes—it does not replace Docker images. Modern Kubernetes clusters commonly use runtimes such as containerd or CRI-O, while still running images built with Docker.

5. Kubernetes Architecture

Kubernetes Cluster

┌─────────────────┴─────────────────┐

│ │

▼ ▼

Control Plane Worker Nodes

│ │

│ ┌────────┴────────┐

▼ ▼ ▼

Scheduler Pod 1 Pod 2

API Server (Container) (Container)

Controller

etcd

6. What is a Cluster?

A Cluster is a group of computers (nodes) working together.

Example

  • Cluster
  • ├── Node 1
  • ├── Node 2
  • ├── Node 3
  • └── Node 4
  • Together, they run your application reliably.

7. What is a Node?

A Node is a physical or virtual machine in a Kubernetes cluster.

Each node contains

  • Operating System
  • Container Runtime
  • Kubelet
  • Running Pods

8. Control Plane vs Worker Node

Control PlaneWorker Node
Manages the clusterRuns application workloads
SchedulingRuns Pods
API ServerExecutes containers
Stores cluster stateProvides compute resources

9. What is a Pod?

A Pod is the smallest deployable unit in Kubernetes.

A Pod usually contains one application container, though it can contain multiple closely related containers.

Example

Pod
FastAPI Container

10. Pod Example

Node

├── Pod A

│ └── FastAPI

├── Pod B

│ └── FastAPI

└── Pod C

└── FastAPI

11. Why Pods?

Instead of running containers directly,

Kubernetes manages Pods because they provide

  • Networking
  • Shared storage
  • Lifecycle management
  • Health monitoring

12. ReplicaSet

Suppose you need

3 API Instances

ReplicaSet ensures

  • Pod 1
  • Pod 2
  • Pod 3
  • If Pod 2 crashes,
  • Kubernetes automatically creates another Pod.
  • This behavior is called self-healing.

13. Deployment

A Deployment manages ReplicaSets and Pods.

Example

Deployment
ReplicaSet
Pods

Benefits

  • Rolling updates
  • Rollbacks
  • Scaling
  • Self-healing

14. Kubernetes Service

  • Pods receive dynamic IP addresses.
  • Users should not connect directly to Pods.
  • A Service provides a stable endpoint.
Users
Service
Pods

15. Load Balancing

Suppose there are four Pods.

Service
Pod 1
  • Pod 2
  • Pod 3
  • Pod 4

Incoming requests are distributed across the Pods.

This improves performance and reliability.

16. Auto Scaling

Initially

2 Pods

Traffic increases.

Kubernetes automatically scales

8 Pods

Traffic decreases.

Scale back to

2 Pods

This helps optimize resource usage.

17. Self-Healing

Suppose

Pod 3
Crash

Kubernetes detects the failure.

Automatically

Create New Pod

No manual intervention required.

18. Rolling Updates

Version 1
Version 2

Instead of stopping everything,

Kubernetes updates Pods gradually.

Old Pod
New Pod
Old Pod
New Pod

Users continue accessing the application during the rollout.

19. Rollback

Suppose Version 2 has a bug.

Kubernetes can roll back to Version 1.

Version 2
Rollback
Version 1

20. Kubernetes Objects

ObjectPurpose
PodRuns containers
DeploymentManages Pods
ReplicaSetMaintains desired number of Pods
ServiceExposes Pods
ConfigMapStores configuration
SecretStores sensitive information
NamespaceOrganizes cluster resources
IngressManages external HTTP/HTTPS access

21. ConfigMap

Store configuration separately.

Example

  • DATABASE_NAME
  • API_URL
  • MODEL_PATH

This allows configuration changes without rebuilding the image.

22. Secret

Sensitive values should never be stored in source code.

Examples

  • Database Password
  • API Key
  • Azure Credentials
  • AWS Keys
  • Store them securely using Secrets.

23. Ingress

Instead of exposing many services separately,

Ingress routes external traffic.

Example

internet
Ingress
AI API
Chatbot
Dashboard

24. Kubernetes Workflow

Application

Docker Image

Deployment

ReplicaSet

Pods

Service

Users

25. Kubernetes Commands

Create deployment

kubectl create deployment ml-api --image=house-price-api

View Pods

kubectl get pods

View Deployments

kubectl get deployments

View Services

kubectl get services

Delete Pod

kubectl delete pod pod-name

Scale Deployment

kubectl scale deployment ml-api --replicas=5

26. Kubernetes YAML

Example Deployment

apiVersion: apps/v1

kind: Deployment

metadata

name: ml-api

spec

replicas: 3

selector

matchLabels

app: ml-api

template

metadata

labels

app: ml-api

spec

containers

- name: api

image: house-price-api

This configuration ensures three replicas of the application.

27. Kubernetes in MLOps

A typical production workflow

Train Model

Save Model

Docker Image

Container Registry

Kubernetes Deployment

REST API

Users

28. Real-World Example

Suppose Netflix receives

10 Million Requests

One server is not enough.

Kubernetes automatically

  • Creates additional Pods.
  • Distributes traffic.
  • Restarts failed Pods.
  • Updates applications without downtime.

The same concepts apply to large-scale ML inference services.

29. Advantages

  • Automatic scaling.
  • Self-healing.
  • High availability.
  • Rolling updates.
  • Rollbacks.
  • Load balancing.
  • Portable across cloud providers.

30. Limitations

  • Steeper learning curve than Docker alone.
  • More operational complexity.
  • Requires careful monitoring and resource management.
  • Small projects may not need Kubernetes.

31. Best Practices

  • Use Docker images with Kubernetes.
  • Define CPU and memory requests/limits.
  • Store secrets using Kubernetes Secrets.
  • Use health probes (liveness and readiness).
  • Monitor clusters using tools such as Prometheus and Grafana.
  • Use rolling updates instead of deleting all Pods at once.

32. Common Mistakes

  • Running everything in a single Pod.
  • Hardcoding passwords.
  • Ignoring resource limits.
  • Not using health checks.
  • Deploying directly to production without testing.

33. Interview Questions

Beginner

  • What is Kubernetes?
  • What is a Pod?
  • What is a Node?
  • What is a Cluster?
  • Difference between Docker and Kubernetes?

Intermediate

  • What is a Deployment?
  • What is a ReplicaSet?
  • What is a Kubernetes Service?
  • What is Ingress?
  • What is ConfigMap?

Advanced

  • Explain Kubernetes Architecture.
  • How does Kubernetes perform self-healing?
  • How do rolling updates work?
  • How would you deploy a FastAPI application?
  • How would you deploy an ML model on Kubernetes?

Mini Project

  • Deploy a House Price Prediction API on Kubernetes
  • Project Structure
  • HousePriceAPI/
  • ├── app.py
  • ├── model.pkl
  • ├── Dockerfile
  • ├── deployment.yaml
  • └── service.yaml
  • Tasks
  • Build the Docker image.
  • Push the image to a container registry.
  • Create a Kubernetes Deployment.
  • Expose it with a Service.
  • Scale to five replicas.
  • Verify load balancing.

Perform a rolling update with a new image version.

Chapter Summary

Kubernetes is an open-source container orchestration platform that automates the deployment, scaling, networking, and management of containerized applications. While Docker packages applications into containers, Kubernetes ensures those containers remain available, scalable, and resilient in production through features such as Pods, Deployments, ReplicaSets, Services, Auto Scaling, Self-Healing, and Rolling Updates.

Kubernetes Workflow Cheat Sheet

Build Application

Docker Image

Container Registry

Kubernetes Deployment

ReplicaSet

Pods

Service

Load Balancer

Users

What's Next?

In Chapter 10.4 – MLflow, you'll learn how to track machine learning experiments, compare model performance, store trained models in a Model Registry, manage model versions, and streamline the transition from experimentation to production—one of the core practices in modern MLOps.

Module 10 · Lesson 10.4

MLflow

Chapter 10.4 – MLflow

  • MLflow is one of the most widely used open-source MLOps platforms for managing the complete Machine Learning lifecycle.

It helps Data Scientists and ML Engineers track experiments, compare models, register models, and deploy them to production.

Learning Objectives

By the end of this chapter, you will be able to

  • Understand what MLflow is.
  • Learn why MLflow is important.
  • Understand experiment tracking.
  • Learn about parameters, metrics, and artifacts.
  • Understand the Model Registry.
  • Learn model versioning.
  • Deploy models using MLflow.
  • Build an end-to-end ML workflow.
  • Prepare for MLflow interview questions.

1. Introduction

  • Imagine you are training a Machine Learning model.
  • Experiment 1
  • Algorithm: Random Forest
  • Trees: 100
  • Accuracy: 91%
  • Experiment 2
  • Algorithm: Random Forest
  • Trees: 200
  • Accuracy: 93%
  • Experiment 3
  • Algorithm: XGBoost
  • Learning Rate: 0.05
  • Accuracy: 95%

After one month your manager asks

  • Which model was the best?
  • What parameters did you use?
  • Can you reproduce Experiment 2?
  • If you didn't record everything,
  • you probably won't remember.
  • MLflow solves this problem.

2. What is MLflow?

Definition

MLflow is an open-source MLOps platform that manages the Machine Learning lifecycle, including experiment tracking, model packaging, model registry, and deployment.

MLflow was originally developed by Databricks and is now maintained as an open-source project.

3. Why Do We Need MLflow?

Suppose you train

  • 20 Random Forest models
  • 15 XGBoost models
  • 12 Neural Networks

Questions arise

  • Which model performed best?
  • Which hyperparameters produced the best accuracy?
  • Which model is in production?
  • Which dataset version was used?

MLflow automatically stores this information.

4. Machine Learning Without MLflow

Experiment 1

Accuracy = 92%
------------------
Experiment 2
Accuracy = ??

------------------

  • Experiment 3
  • Learning Rate = ??
  • After a few weeks,

it becomes difficult to remember what was done.

5. Machine Learning With MLflow

Experiment
Parameters
Metrics
Artifacts
Model
Model Registry
Deployment

Everything is tracked automatically.

6. MLflow Components

MLflow consists of four main components

  • MLflow
  • ├── Tracking
  • ├── Projects
  • ├── Models
  • └── Model Registry

7. MLflow Tracking

Tracking records every experiment.

It stores

  • Parameters
  • Metrics
  • Model
  • Artifacts
  • Tags
  • Execution Time

Example

Experiment
Accuracy
Precision
Recall
F1 Score

8. Parameters

Parameters are values chosen before training.

Examples

Learning Rate = 0.01

Batch Size = 32

Epochs = 100

Max Depth = 10

These influence model training.

9. Metrics

Metrics measure model performance after or during training.

Examples

  • Accuracy
  • Precision
  • Recall
  • F1 Score
  • ROC-AUC
  • RMSE
  • MAE

Example

Accuracy = 96%
F1 Score = 0.94
Precision = 0.95

10. Artifacts

Artifacts are files generated during training.

Examples

  • Trained Model
  • Confusion Matrix
  • ROC Curve
  • Feature Importance Plot
  • Log Files
  • Training Dataset Sample

Example

Model.pkl
ConfusionMatrix.png
ROC.png
FeatureImportance.csv

11. Experiments

An experiment is a collection of related training runs.

Example

House Price Prediction

  • ├── Run 1
  • ├── Run 2
  • ├── Run 3
  • └── Run 4

Each run stores different hyperparameters and results.

12. Runs

Every training execution is called a Run.

Example

Run 1

Algorithm = Random Forest
Accuracy = 91%
------------------
Run 2
Algorithm = XGBoost
Accuracy = 95%

Runs can be compared easily.

13. MLflow Architecture

ML Training

MLflow Tracking

Experiment Database

Artifacts

Model Registry

Deployment

14. Install MLflow

Install using pip

pip install mlflow

Check version

mlflow --version

15. Start MLflow UI

  • mlflow ui
  • Default URL
  • http://127.0.0.1:5000

The UI displays

  • Experiments
  • Runs
  • Metrics
  • Parameters
  • Artifacts

16. First MLflow Example

import mlflow

with mlflow.start_run()

mlflow.log_param("learning_rate", 0.01)

mlflow.log_metric("accuracy", 0.95)

Now MLflow records

Learning Rate = 0.01

Accuracy = 95%
17. Logging Parameters

mlflow.log_param("epochs",100)

mlflow.log_param("batch_size",32)

18. Logging Metrics

  • mlflow.log_metric("accuracy",0.97)
  • mlflow.log_metric("precision",0.95)
  • mlflow.log_metric("recall",0.94)

19. Logging Artifacts

mlflow.log_artifact("model.pkl")

Or save a chart

mlflow.log_artifact("roc_curve.png")

20. Logging Models

Example using Scikit-learn

import mlflow.sklearn
  • mlflow.sklearn.log_model(
  • model,
  • "house_price_model"

)

MLflow stores the trained model along with metadata.

21. Model Registry

The Model Registry is a centralized repository for trained models.

Model Registry
Version 1
Version 2
Version 3

It helps manage different versions of a model.

22. Model Stages

A model typically moves through stages

None
Staging
Production
Archived
  • None
  • Newly registered model.
  • Staging
  • Being tested.
  • Production
  • Currently serving users.
  • Archived

Retained for history but no longer active.

23. Model Versioning

Suppose

House Price Model

Version 1
Version 2
Version 3

If Version 3 performs poorly,

you can roll back to Version 2.

24. Compare Experiments

MLflow UI displays

RunAccuracyPrecision
Run 191%90%
Run 295%94%
Run 397%96%

Choosing the best model becomes much easier.

25. MLflow Projects

MLflow Projects package ML code into a reusable format.

Typical structure

  • HousePriceProject/
  • ├── MLproject
  • ├── train.py
  • ├── requirements.txt

└── data/

This improves reproducibility.

26. MLflow Models

MLflow supports many frameworks.

Examples

  • Scikit-learn
  • TensorFlow
  • PyTorch
  • XGBoost
  • LightGBM
  • CatBoost

27. Deploy Model

Serve a model locally

mlflow models serve \

-m runs:/RUN_ID/model

MLflow creates a REST API endpoint for inference.

28. MLflow Workflow

Train Model

Log Parameters

Log Metrics

Log Artifacts

Register Model

Deploy

29. MLflow in MLOps

Git
Train Model
MLflow Tracking
Model Registry
Docker
Kubernetes
Production

MLflow fits naturally into an end-to-end MLOps pipeline.

30. Real-World Example

Suppose you build a Customer Churn Prediction model.

You try

  • Logistic Regression
  • Random Forest
  • XGBoost
  • LightGBM

MLflow records

  • Hyperparameters
  • Accuracy
  • Precision
  • Recall
  • F1 Score
  • Training Time
  • Model File

You compare results and promote the best model to Production.

31. Advantages

  • Complete experiment tracking.
  • Easy model comparison.
  • Centralized model registry.
  • Framework independent.
  • Supports reproducibility.
  • Integrates well with cloud platforms.

32. Limitations

  • Requires storage for artifacts and metadata.
  • Team deployments benefit from configuring a shared tracking server.
  • Does not replace orchestration tools such as Kubernetes or Airflow.
  • Large-scale deployments require proper infrastructure planning.

33. Best Practices

  • Log every experiment.
  • Track all important hyperparameters.
  • Save evaluation metrics.
  • Store important artifacts.
  • Register only validated models.
  • Use meaningful experiment names.
  • Version datasets separately (for example, with DVC).

34. Common Mistakes

  • Forgetting to log hyperparameters.
  • Logging only accuracy.
  • Not saving trained models.
  • Overwriting production models without validation.
  • Ignoring experiment organization.

35. Interview Questions

Beginner

  • What is MLflow?
  • Why is MLflow used?
  • What is Experiment Tracking?
  • What are Parameters?
  • What are Metrics?

Intermediate

  • What are Artifacts?
  • What is Model Registry?
  • What is Model Versioning?

Explain MLflow Architecture.

How do you compare experiments?

Advanced

  • How would you use MLflow in a production ML pipeline?
  • How do you deploy a model using MLflow?
  • How would you manage multiple model versions?
  • How does MLflow integrate with Docker and Kubernetes?
  • How would you track experiments for hundreds of models?

Mini Project

  • MLflow Experiment Tracking for House Price Prediction
  • Project Structure
  • HousePricePrediction/
  • ├── train.py

├── data/

  • ├── models/
  • ├── requirements.txt
  • └── MLproject
  • Tasks
  • Train three different algorithms (Linear Regression, Random Forest, XGBoost).
  • Log all hyperparameters.
  • Log Accuracy/RMSE/MAE (depending on the problem type).
  • Save trained models.
  • Compare experiments in the MLflow UI.
  • Register the best-performing model.
  • Serve the model locally using MLflow.
  • MLflow Workflow Cheat Sheet
  • Train Model

Log Parameters

Log Metrics

Log Artifacts

Register Model

Deploy

Production

Chapter Summary

MLflow is an open-source MLOps platform that simplifies the machine learning lifecycle by tracking experiments, logging parameters and metrics, storing artifacts, registering models, and supporting deployment. It helps teams build reproducible, organized, and production-ready machine learning workflows, making it an essential tool for modern MLOps.

Learning Progress

  • Git & GitHub

  • Docker

  • Kubernetes

  • MLflow

You now know how to

  • Version your code with Git.
  • Package applications using Docker.
  • Orchestrate containers with Kubernetes.

Track and manage machine learning experiments using MLflow.

What's Next?

In Chapter 10.5 – DVC (Data Version Control), you'll learn how to version datasets, trained models, and ML pipelines. While Git tracks your source code, DVC manages large data files and ensures your machine learning experiments are fully reproducible. This combination of Git + DVC + MLflow forms the foundation of many production MLOps workflows.

Module 10 · Lesson 10.5

DVC

Chapter 10.5 – DVC (Data Version Control)

  • Git is excellent for versioning code, but it is not designed for large datasets and machine learning models.

DVC (Data Version Control) solves this problem by versioning datasets, models, and ML pipelines while working seamlessly with Git.

Learning Objectives

By the end of this chapter, you will be able to

  • Understand what DVC is.
  • Learn why DVC is needed.
  • Understand Git vs DVC.
  • Track datasets and ML models.
  • Version machine learning pipelines.
  • Use remote storage.
  • Build reproducible ML workflows.
  • Integrate DVC with Git and MLflow.
  • Prepare for DVC interview questions.

1. Introduction

Imagine you're building a customer churn prediction model.

Your project contains

  • Source Code
  • 20 MB
  • Dataset
  • 15 GB
  • Trained Model
  • 3 GB

Git works perfectly for the source code.

But Git struggles with

  • Large datasets
  • Large model files
  • Frequent updates to binary files

This is where DVC comes in.

2. What is DVC?

Definition

DVC (Data Version Control) is an open-source version control system for machine learning datasets, models, and pipelines that integrates with Git.

Think of DVC as Git for Data.

Git tracks

Python Code

DVC tracks

  • Datasets
  • Models
  • ML Pipelines

3. Why Do We Need DVC?

  • Suppose your project evolves over time.
  • Version 1
  • Dataset
  • 10,000 Rows
  • Version 2
  • Dataset
  • 100,000 Rows
  • Version 3
  • Dataset
  • 2 Million Rows

Now imagine someone asks

Which dataset was used to train Model Version 2?

Without DVC

  • Difficult to answer.

With DVC

✅ Every dataset version is linked to the corresponding Git commit.

4. Git vs DVC

GitDVC
Tracks source codeTracks data and models
Optimized for text filesOptimized for large binary files
Stores files in Git repositoryStores metadata in Git, large files in external storage
Manages code historyManages dataset and model history

5. How DVC Works

Instead of storing a 10 GB dataset inside Git

Dataset.csv
DVC
Hash Generated
Metadata File (.dvc)
Git Stores Metadata
Actual Data Stored in Remote Storage

Git remains lightweight while DVC manages large files efficiently.

6. DVC Architecture

Project

Git Repository

DVC Metadata

Remote Storage

(Azure, AWS, GCP, Local)

7. Install DVC

Install using pip

pip install dvc

Check version

dvc version

8. Initialize DVC

Inside your Git repository

dvc init

This creates

.dvc/

.dvcignore

Commit the initialization

git add .
git commit -m "Initialize DVC"

9. Add a Dataset

Suppose you have

data/

customer.csv

Track it with DVC

dvc add data/customer.csv

DVC creates

customer.csv.dvc

The .dvc file stores metadata such as the file hash and location.

10. Commit Dataset Metadata

git add customer.csv.dvc
git commit -m "Track customer dataset"

Notice

Git stores only the small metadata file—not the large dataset itself.

11. Remote Storage

Large files are stored in remote storage.

Supported options include

  • Local Storage
  • Amazon S3
  • Azure Blob Storage
  • Google Cloud Storage
  • SSH Server
  • Network File System

Example

Git
Metadata
Azure Blob Storage
Dataset

12. Configure Remote Storage

Example

dvc remote add -d storage s3://my-dvc-storage

Or Azure Blob Storage

dvc remote add -d storage azure://mlstorage

(Additional authentication configuration is required.)

13. Push Data

Upload datasets

dvc push

Workflow

Local Dataset
Remote Storage

14. Pull Data

Download datasets

dvc pull

Useful when another developer clones the repository.

15. DVC Pipeline

A Machine Learning pipeline consists of multiple stages.

Example

Raw Data
Data Cleaning
Feature Engineering
Model Training
Evaluation

DVC can define and reproduce these stages.

16. Create a Pipeline Stage

Example

  • dvc stage add \
  • -n train \
  • -d train.py \
  • -d data/customer.csv \
  • -o model.pkl \
python train.py

This tells DVC

  • Input files
  • Output files
  • Command to execute

17. Reproduce Pipeline

Run

  • dvc repro
  • DVC checks whether dependencies have changed.
  • If data or code changed,
  • only the necessary stages are executed.

18. Pipeline Graph

Raw Data

Cleaning

Feature Engineering

Training

Evaluation

Each stage depends on the previous one.

19. DVC Lock File

DVC creates

dvc.lock

This file records

  • Input versions
  • Output versions
  • Command used
  • Dependency hashes
  • It enables reproducibility.

20. Versioning Models

Suppose

model.pkl

Track it

dvc add model.pkl

Now every trained model version is linked to a Git commit.

21. DVC + Git + MLflow

Together they provide a complete MLOps workflow.

Git
Code

────────────

DVC
Dataset
Model

────────────

MLflow
Experiments
Metrics

Responsibilities

  • Git → Source code
  • DVC → Data and models
  • MLflow → Experiments and model lifecycle

22. Typical MLOps Workflow

Git Commit
DVC Dataset
Train Model
MLflow Logs
Model Registry
Docker
Kubernetes
Production

23. Real-World Example

Suppose you build a loan approval model.

Dataset Version 1
Random Forest
Accuracy 91%
Dataset Version 2
XGBoost
Accuracy 95%

Using DVC,

you can always identify

  • Which dataset trained each model.
  • Which Git commit contains the code.
  • Which MLflow run contains the metrics.

24. Advantages

  • Handles large datasets efficiently.
  • Version controls ML models.
  • Works with Git.
  • Supports cloud storage.
  • Creates reproducible ML pipelines.
  • Enables collaboration among teams.

25. Limitations

  • Requires remote storage for large teams.
  • Adds additional tooling to the workflow.
  • Team members need to understand both Git and DVC.
  • Binary file transfers can still take time.

26. Best Practices

  • Store datasets using DVC—not Git.
  • Commit .dvc files to Git.
  • Use remote storage.
  • Version trained models.
  • Build reproducible pipelines.
  • Keep datasets organized.

27. Common Mistakes

  • Committing 20 GB datasets directly to Git.
  • Forgetting to run dvc push.
  • Not versioning trained models.
  • Ignoring dvc.lock.
  • Mixing temporary files with tracked datasets.

28. Interview Questions

Beginner

  • What is DVC?
  • Why do we need DVC?
  • Difference between Git and DVC?
  • What is a .dvc file?
  • What is dvc.lock?

Intermediate

  • How does DVC store large datasets?
  • What is dvc push?
  • What is dvc pull?
  • What is a DVC pipeline?
  • How does DVC ensure reproducibility?

Advanced

  • Explain Git + DVC + MLflow architecture.
  • How would you version datasets?
  • How would you reproduce an ML experiment?
  • How would you manage multiple dataset versions?
  • How would you build a production ML pipeline using DVC?

29. Mini Project

  • Version a House Price Dataset
  • Project Structure
  • HousePricePrediction/

├── data/

│ └── house_prices.csv

  • ├── train.py
  • ├── model.pkl
  • ├── dvc.yaml
  • ├── dvc.lock

└── .dvc/

  • Tasks
  • Initialize DVC.
  • Track the dataset.
  • Configure remote storage.
  • Build a training pipeline.
  • Track the trained model.
  • Push data to remote storage.
  • Clone the project on another machine.
  • Pull the dataset.
  • Reproduce the pipeline.

30. Complete MLOps Architecture

Developer

Git Repository

DVC

(Data Versioning)

MLflow

(Experiment Tracking)

Docker

Kubernetes

Cloud Deployment

Chapter Summary

DVC extends Git by providing version control for datasets, machine learning models, and ML pipelines. It stores lightweight metadata in Git while keeping large files in external storage, making collaboration and reproducibility practical for machine learning projects. When combined with Git for source code and MLflow for experiment tracking, DVC becomes a key component of modern MLOps workflows.

DVC Workflow Cheat Sheet

Dataset

dvc add

.dvc Metadata

Git Commit

dvc push

Remote Storage

Another Developer

git clone

dvc pull

Learning Progress

  • Git & GitHub

  • Docker

  • Kubernetes

  • MLflow

  • DVC

You have now learned how to

  • Version source code with Git.
  • Package applications with Docker.
  • Orchestrate containers using Kubernetes.
  • Track experiments with MLflow.
  • Version datasets and machine learning pipelines with DVC.
  • Together, these technologies form the foundation of a professional MLOps workflow.
  • What's Next?

In Chapter 10.6 – FastAPI, you'll learn how to expose your trained machine learning models as REST APIs. You'll build high-performance prediction services, generate interactive API documentation automatically, validate input data, and prepare your models for production deployment using Docker and Kubernetes.

Module 10 · Lesson 10.6

FastAPI

Chapter 10.6 – FastAPI

  • FastAPI is one of the most popular frameworks for deploying Machine Learning and AI models as REST APIs.

Companies such as Microsoft, Netflix, Uber, NVIDIA, and many AI startups use FastAPI because it is fast, modern, easy to use, and automatically generates API documentation.

Learning Objectives

By the end of this chapter, you will be able to

  • Understand what FastAPI is.
  • Learn why FastAPI is widely used.
  • Build REST APIs.
  • Create GET and POST endpoints.
  • Validate request data using Pydantic.
  • Deploy Machine Learning models.
  • Understand asynchronous programming.
  • Generate API documentation.
  • Deploy FastAPI with Docker and Kubernetes.
  • Prepare for FastAPI interview questions.

1. Introduction

Imagine you've trained a House Price Prediction Model.

You want a website to use your model.

Without an API

Website
Cannot directly use Python Model

With FastAPI

Website
FastAPI
Machine Learning Model
Prediction

FastAPI acts as the bridge between your model and the outside world.

2. What is FastAPI?

Definition

FastAPI is a modern, high-performance Python web framework used to build REST APIs quickly with automatic data validation, documentation, and support for asynchronous programming.

It is built on

Starlette (web framework)

Pydantic (data validation)

3. Why FastAPI?

Suppose you build an AI model.

Many applications need to use it

  • Mobile App
  • Website
  • Chatbot
  • Power BI
  • Other APIs

FastAPI allows all of them to communicate with the model.

4. Why Not Just Run Python?

Without FastAPI

model.py

Runs only on your computer

With FastAPI

User
HTTP Request
FastAPI
Model
Prediction

The model becomes accessible over the network.

5. REST API

FastAPI creates REST APIs.

REST (Representational State Transfer) is an architectural style for building web services using HTTP.

Example

Client
HTTP Request
FastAPI
HTTP Response

6. HTTP Methods

MethodPurpose
GETRetrieve data
POSTCreate or process data
PUTUpdate existing data
PATCHPartially update data
DELETERemove data

7. Install FastAPI

pip install fastapi

Install an ASGI server (Uvicorn)

pip install uvicorn

8. First FastAPI Program

from fastapi import FastAPI
app = FastAPI()

@app.get("/")

def home():
return {"message": "Welcome to FastAPI"}

Save as

app.py

Run

uvicorn app:app --reload

Output

INFO: Uvicorn running on http://127.0.0.1:8000

9. Access API

Open

http://127.0.0.1:8000

Output

{

"message":"Welcome to FastAPI"

}

10. Automatic API Documentation

  • One of FastAPI's biggest advantages is automatic documentation.
  • Swagger UI
  • http://127.0.0.1:8000/docs
  • Interactive documentation where you can test APIs.
  • ReDoc
  • http://127.0.0.1:8000/redoc
  • Alternative documentation interface.

11. GET API Example

from fastapi import FastAPI
app = FastAPI()

@app.get("/hello")

def hello():
return {"message":"Hello World"}
  • Request
  • GET /hello
  • Response

{

"message":"Hello World"

}

12. Path Parameters

@app.get("/square/{number}")

def square(number: int):
return {"square": number * number}
  • Request
  • GET /square/5
  • Response

{

"square":25

}

13. Query Parameters

@app.get("/add")

def add(a: int, b: int):
return {"sum": a + b}
  • Request
  • /add?a=10&b=20
  • Response

{

"sum":30

}

14. POST API

POST is commonly used for ML predictions.

Example

from pydantic import BaseModel
class Student(BaseModel):
    name: str

age: int

@app.post("/student")

def create_student(student: Student):
return student

Request

{

"name":"Hari",

"age":30

}

Response

{

"name":"Hari",

"age":30

}

15. What is Pydantic?

Pydantic automatically validates input data.

Example

class Person(BaseModel):
    age: int

If the client sends

{

"age":"ABC"

}

FastAPI returns an error because "ABC" is not an integer.

16. Machine Learning Prediction API

Suppose you trained

house_price_model.pkl

Load model

import joblib
model = joblib.load("model.pkl")

Create request model

class House(BaseModel):
    area: float
  • bedrooms: int
  • Prediction endpoint
  • @app.post("/predict")
def predict(data: House):
prediction = model.predict(
\[[data.area, data.bedrooms]\]

)

return {

"predicted_price"

prediction[0]

}

17. Request Example

{

"area":1500,

"bedrooms":3

}

Response

{

"predicted_price":7500000

}

18. API Workflow

Client
POST Request
FastAPI
Load Model
Prediction
JSON Response

19. Asynchronous Programming

FastAPI supports asynchronous endpoints.

Example

@app.get("/status")

async def status()

return {"status":"Running"}
  • Benefits
  • Better concurrency
  • Efficient I/O handling
  • High throughput for many simultaneous requests

Use async mainly for operations like database queries, API calls, or file access. CPU-intensive ML inference may still run synchronously or be handled using background workers.

20. Error Handling

Example

from fastapi import HTTPException

@app.get("/user/{id}")

def get_user(id:int):
    if id < 1:
        raise HTTPException(
            status_code=400,
            detail="Invalid ID"
        )
return {"id":id}

21. Dependency Injection

FastAPI provides dependency injection.

Example

from fastapi import Depends
def verify_api_key():
return True

@app.get("/secure")

def secure(
auth=Depends(verify_api_key)

)

return {"message":"Authorized"}

Useful for

  • Authentication
  • Database connections
  • Logging
  • Configuration

22. Project Structure

HousePriceAPI/

  • ├── app.py
  • ├── model.pkl
  • ├── schemas.py
  • ├── services.py
  • ├── requirements.txt
  • ├── Dockerfile
  • └── tests/

Large applications should separate routes, business logic, schemas, and utilities.

23. Docker + FastAPI

  • Dockerfile
  • FROM python:3.11
  • WORKDIR /app
  • COPY . .
  • RUN pip install -r requirements.txt
  • EXPOSE 8000
  • CMD [
  • "uvicorn",
  • "app:app",

"--host",

"0.0.0.0",

"--port",

"8000"

]

Run

docker build -t house-api .
docker run -p 8000:8000 house-api

24. FastAPI in Kubernetes

User
Load Balancer
FastAPI Pods
Machine Learning Model

Multiple FastAPI instances can serve requests simultaneously.

25. FastAPI in MLOps

Train Model
MLflow
Model Registry
FastAPI
Docker
Kubernetes
Production

26. Real-World Applications

  • Banking
  • Loan approval prediction
  • Healthcare
  • Disease prediction APIs
  • Retail
  • Recommendation systems
  • Manufacturing
  • Predictive maintenance
  • Agriculture
  • Crop disease prediction
  • Chatbots
  • LLM inference APIs

27. Advantages

  • Very high performance.
  • Automatic validation.
  • Automatic API documentation.
  • Built-in type hints.
  • Easy integration with ML libraries.
  • Async support.

28. FastAPI vs Flask

FastAPIFlask
Async supportPrimarily synchronous
Automatic validationManual validation
Swagger documentationRequires extensions
Type hintsNative support
High performanceLightweight and flexible

Both frameworks are excellent; FastAPI is often preferred for new ML APIs because of its built-in validation and documentation.

29. Best Practices

  • Use Pydantic models.
  • Separate business logic from routes.
  • Validate all inputs.
  • Handle exceptions gracefully.
  • Use environment variables for secrets.
  • Add logging and monitoring.
  • Write automated tests.

30. Common Mistakes

  • Loading the model inside every request instead of once at startup.
  • Hardcoding database credentials.
  • Returning unhandled exceptions.
  • Skipping input validation.
  • Mixing routing and business logic in one large file.

31. Interview Questions

Beginner

  • What is FastAPI?
  • Why is FastAPI used?
  • What is REST API?
  • What is Pydantic?
  • What is Swagger UI?

Intermediate

  • Difference between GET and POST?
  • What are path parameters?
  • What are query parameters?
  • What is async in FastAPI?
  • How does FastAPI validate input?

Advanced

  • How would you deploy an ML model using FastAPI?
  • FastAPI vs Flask?
  • How would you secure a FastAPI application?
  • How would you scale FastAPI with Kubernetes?
  • How would you monitor a FastAPI service in production?

Mini Project

  • House Price Prediction API
  • Project Structure
  • HousePriceAPI/
  • ├── app.py
  • ├── model.pkl
  • ├── schemas.py
  • ├── requirements.txt
  • ├── Dockerfile
  • └── tests/
  • Features
  • Predict house prices.
  • Input validation using Pydantic.
  • Interactive Swagger documentation.
  • Docker support.
  • Kubernetes-ready deployment.
  • Complete FastAPI Workflow
  • Train Model

Save model.pkl

FastAPI API

Swagger Documentation

Docker

Kubernetes

Production

Chapter Summary

FastAPI is a modern Python framework for building high-performance REST APIs. It is particularly well suited for serving machine learning models because it provides automatic request validation, interactive API documentation, excellent performance, and straightforward integration with Docker, Kubernetes, and cloud platforms. These features make it one of the most widely adopted frameworks for production AI services.

Learning Progress

  • Git & GitHub

  • Docker

  • Kubernetes

  • MLflow

  • DVC

  • FastAPI

You have now learned how to

  • Manage source code with Git.
  • Package applications using Docker.
  • Orchestrate containers with Kubernetes.
  • Track ML experiments with MLflow.
  • Version datasets using DVC.
  • Serve ML models through FastAPI.

Together, these technologies form the backbone of a modern production MLOps platform.

What's Next?

In Chapter 10.7 – Flask, you'll learn another popular Python web framework used for building web applications and REST APIs. You'll compare Flask and FastAPI, understand their strengths and trade-offs, and learn when to choose one over the other in machine learning and production environments.

Module 10 · Lesson 10.7

Flask

Chapter 10.7 – Flask

  • Flask is one of the most popular lightweight Python web frameworks for building web applications and REST APIs.

Before FastAPI became popular, Flask was the preferred framework for deploying Machine Learning models. Even today, thousands of production systems use Flask because of its simplicity, flexibility, and large ecosystem.

Learning Objectives

By the end of this chapter, you will be able to

  • Understand what Flask is.
  • Learn Flask architecture.
  • Build REST APIs.
  • Create GET and POST endpoints.
  • Deploy Machine Learning models using Flask.
  • Understand Flask project structure.
  • Compare Flask and FastAPI.
  • Deploy Flask using Docker.
  • Prepare for Flask interview questions.

1. Introduction

Suppose you have trained a Customer Churn Prediction Model.

The model exists as

model.pkl

Your company wants

  • A website
  • A mobile application
  • Power BI dashboards
  • Other applications
  • to use the model.
  • How can they communicate with your Python model?

The answer is

Flask REST API

2. What is Flask?

Definition

Flask is a lightweight Python web framework used to build web applications and REST APIs.

It provides the essentials needed to create web services while allowing developers to choose additional libraries as required.

3. Why Flask?

Suppose your Machine Learning model predicts house prices.

Without Flask

Python Model
Only runs locally

With Flask

User
HTTP Request
Flask API
Machine Learning Model
Prediction
HTTP Response

The model becomes accessible over the network.

4. Features of Flask

  • Lightweight
  • Easy to learn
  • Flexible
  • REST API support
  • Template engine (Jinja2)
  • Large ecosystem
  • Works well with ML models

5. Install Flask

pip install flask

Check installation

python -c "import flask; print(flask.__version__)"

6. First Flask Application

from flask import Flask
app = Flask(__name__)

@app.route("/")

def home():
    return "Welcome to Flask!"
    if __name__ == "__main__":
        app.run(debug=True)

Run

python app.py

Output

Running on http://127.0.0.1:5000

7. Flask Architecture

Client
HTTP Request

Flask Server
Business Logic
Machine Learning Model

HTTP Response

8. Routing

Routes define URLs.

Example

@app.route("/hello")

def hello():
return "Hello World"

Access

http://127.0.0.1:5000/hello

Response

Hello World

9. GET Request

@app.route("/square/<int:number>")

def square(number):
    return {
        "square": number * number
    }

Request

GET /square/5

Response

{

"square":25

}

10. POST Request

from flask import request

@app.route("/add", methods=["POST"])

def add():
    data = request.json
    total = data["a"] + data["b"]
    return {
        "sum": total
    }

Request

{

"a":10,

"b":20

}

Response

{

"sum":30

}

11. Request Object

Flask provides the request object to access client data.

Examples

  • request.json
  • request.form
  • request.args
  • request.files

These are used for

  • JSON payloads
  • HTML forms
  • Query parameters
  • File uploads

12. Returning JSON

from flask import jsonify

@app.route("/status")

def status():
    return jsonify({
        "status":"Running"
    })

Response

{

"status":"Running"

}

13. Machine Learning API

Load model

import joblib
model = joblib.load("model.pkl")

Prediction API

@app.route("/predict", methods=["POST"])

def predict():
    data = request.json
    prediction = model.predict([[
        data["area"],
        data["bedrooms"]
    ]])
return jsonify({

"prediction"

prediction[0]

})

14. Request Example

{

"area":1500,

"bedrooms":3

}

Response

{

"prediction":7500000

}

15. Templates

Flask supports HTML templates using Jinja2.

Project

templates/

index.html

Example

from flask import render_template

@app.route("/")

def home():
return render_template("index.html")

Useful for building traditional web applications with server-rendered HTML.

16. Static Files

  • Store CSS, JavaScript, and images.
  • static/
  • style.css
  • app.js
  • logo.png

17. Flask Project Structure

HousePriceAPI/

  • ├── app.py
  • ├── model.pkl
  • ├── templates/
  • ├── static/
  • ├── requirements.txt
  • ├── Dockerfile
  • └── tests/

For larger applications, routes, models, and services are often separated into multiple modules or packages.

18. Error Handling

from flask import abort

@app.route("/user/<int:id>")

def user(id):
    if id < 1:
        abort(400)
return {"id": id}

Flask returns an HTTP 400 Bad Request error.

19. Flask Workflow

Client
HTTP Request
Flask Route
Business Logic
ML Model
JSON Response

20. Flask + Docker

  • Dockerfile
  • FROM python:3.11
  • WORKDIR /app
  • COPY . .
  • RUN pip install -r requirements.txt
  • EXPOSE 5000
  • CMD ["python","app.py"]
  • Build
docker build -t flask-api .

Run

docker run -p 5000:5000 flask-api

21. Flask in MLOps

Train Model
Save model.pkl
Flask API
Docker
Kubernetes
Production

22. Flask Extensions

Popular extensions include

  • Flask-SQLAlchemy (database ORM)
  • Flask-Login (authentication)
  • Flask-Migrate (database migrations)
  • Flask-CORS (Cross-Origin Resource Sharing)
  • Flask-JWT-Extended (JWT authentication)

23. Flask vs FastAPI

FlaskFastAPI
LightweightLightweight
Manual request validationAutomatic validation with Pydantic
Manual API documentationAutomatic Swagger & ReDoc
Primarily synchronousSupports async and sync
Large ecosystemModern design with Python type hints
Good for web apps & APIsExcellent for high-performance APIs

24. When to Choose Flask?

Choose Flask when

  • Building traditional web applications.
  • You need complete flexibility over project structure.
  • Working with an existing Flask codebase.
  • Your application doesn't require advanced async features.

Choose FastAPI when

Building new REST APIs.

  • Serving Machine Learning models.
  • Automatic validation and API documentation are important.
  • High concurrency is required.

25. Advantages

  • Easy to learn.
  • Flexible architecture.
  • Large community.
  • Extensive extension ecosystem.
  • Good integration with Machine Learning projects.

26. Limitations

  • Request validation is mostly manual.
  • No built-in interactive API documentation.
  • Asynchronous support is more limited compared to FastAPI.
  • Large projects require careful organization.

27. Best Practices

  • Organize routes into blueprints for larger projects.
  • Separate business logic from route handlers.
  • Validate all input data.
  • Store configuration in environment variables.
  • Write unit tests.
  • Add logging and monitoring.

28. Common Mistakes

  • Putting all code into a single app.py file.
  • Hardcoding database credentials.
  • Not validating input.
  • Returning raw exceptions to users.
  • Loading the ML model for every request instead of once during startup.

29. Interview Questions

Beginner

  • What is Flask?
  • Why is Flask popular?
  • What is routing?
  • What is the request object?
  • What is jsonify()?

Intermediate

  • Difference between GET and POST?
  • What are Flask templates?
  • What are static files?
  • How would you deploy an ML model using Flask?
  • How do you handle errors in Flask?

Advanced

  • Flask vs FastAPI?
  • How would you Dockerize a Flask application?
  • How would you scale Flask using Kubernetes?
  • How would you secure a Flask REST API?
  • How would you structure a large Flask project?

30. Mini Project

  • Customer Churn Prediction API
  • Project Structure
  • CustomerChurnAPI/
  • ├── app.py
  • ├── model.pkl
  • ├── requirements.txt
  • ├── Dockerfile
  • ├── templates/
  • └── static/
  • Features
  • Predict customer churn.
  • JSON API.
  • HTML dashboard.
  • Docker support.
  • Kubernetes deployment.
  • Logging.

31. Flask Workflow Cheat Sheet

Train Model

Save model.pkl

Flask API

JSON Response

Docker

Kubernetes

Production

32. Flask vs FastAPI Decision Guide

Need a modern ML REST API?

├── Yes ──► FastAPI

└── No

Need a traditional web application?

├── Yes ──► Flask

└── API only?

├── High performance ──► FastAPI

└── Existing Flask project ──► Flask

Chapter Summary

Flask is a lightweight and flexible Python web framework used to build web applications and REST APIs. It has long been a popular choice for deploying Machine Learning models because of its simplicity and extensive ecosystem. While FastAPI has become the preferred option for many new AI APIs due to its automatic validation, documentation, and async capabilities, Flask remains a strong choice for many production systems, especially existing applications and traditional web projects.

Learning Progress

  • Git & GitHub

  • Docker

  • Kubernetes

  • MLflow

  • DVC

  • FastAPI

  • Flask

You now know how to

  • Track code with Git.
  • Package applications using Docker.
  • Manage containers with Kubernetes.
  • Track ML experiments using MLflow.
  • Version datasets with DVC.
  • Build modern APIs using FastAPI.
  • Build web applications and APIs using Flask.
  • What's Next?

In Chapter 10.8 – Streamlit, you'll learn how to build interactive AI and Machine Learning web applications without needing frontend technologies like HTML, CSS, or JavaScript. You'll create dashboards, data visualizations, and ML prediction interfaces that can be shared with users in just a few lines of Python code.

Module 10 · Lesson 10.8

Streamlit

Chapter 10.8 – Streamlit

  • Streamlit is one of the easiest and most popular Python frameworks for building interactive Data Science, Machine Learning, and AI web applications.

It allows Data Scientists and ML Engineers to build professional web applications without writing HTML, CSS, or JavaScript.

Learning Objectives

By the end of this chapter, you will be able to

  • Understand what Streamlit is.
  • Learn why Streamlit is widely used.
  • Build interactive ML web applications.
  • Create forms, buttons, sliders, and file uploaders.
  • Display tables, charts, and images.
  • Integrate Machine Learning models.
  • Deploy Streamlit applications.
  • Build AI dashboards.
  • Prepare for Streamlit interview questions.

1. Introduction

Imagine you've built a House Price Prediction Model.

Normally, users would need to

  • Install Python.
  • Install libraries.
  • Run scripts.
  • Use the command line.
  • That's not practical.

Instead, you create a simple web application

---------------------------------------

House Price Prediction

Area: [1500]

Bedrooms: [3]

\[Predict\]

Predicted Price

₹75,00,000

---------------------------------------

The user simply opens a browser and uses the application.

This is where Streamlit shines.

2. What is Streamlit?

Definition

Streamlit is an open-source Python framework that allows developers to build interactive web applications for data science, machine learning, and AI using only Python.

Unlike traditional web development,

you don't need

  • HTML
  • CSS
  • JavaScript
  • Everything is written in Python.

3. Why Streamlit?

Without Streamlit

Python Script
Command Prompt
Prediction

With Streamlit

User
Browser
Streamlit App
Machine Learning Model
Prediction

It provides a user-friendly interface for your model.

4. Install Streamlit

pip install streamlit

Check installation

streamlit --version

5. First Streamlit App

Create

app.py

Code

import streamlit as st

st.title("Welcome to Streamlit")

st.write("My First Streamlit Application")

Run

streamlit run app.py

Your browser opens automatically.

6. Streamlit Architecture

User
Browser
Streamlit Server
Python Code
Machine Learning Model
Result

7. Titles and Headers

import streamlit as st
  • st.title("Machine Learning Dashboard")
  • st.header("House Price Prediction")
  • st.subheader("Enter Property Details")

Output

  • Machine Learning Dashboard
  • House Price Prediction
  • Enter Property Details

8. Display Text

  • st.write("Welcome")
  • st.text("Simple Text")
  • st.markdown("**Bold Text**")
  • st.success("Prediction Successful")
  • st.warning("Missing Data")
  • st.error("Model Not Found")

9. User Input

Text Box

name = st.text_input("Enter Name")

Number Input

age = st.number_input("Age")

Slider

area = st.slider(
    "Area",
    500,
    5000,
    1500
)

Select Box

city = st.selectbox(
    "City",
    [
        "Hyderabad",
        "Bangalore",
        "Chennai"
    ]
)

Radio Button

gender = st.radio(
    "Gender",
    [
        "Male",
        "Female"
    ]
)

Checkbox

agree = st.checkbox(
    "Accept Terms"
)

10. Buttons

if st.button("Predict"):
    st.write("Prediction Started")

11. Columns

col1, col2 = st.columns(2)

with col1

st.write("Left")

with col2

st.write("Right")

Useful for creating professional dashboards.

12. Sidebar

st.sidebar.title("Navigation")

model = st.sidebar.selectbox(
    "Model",
    [
        "Random Forest",
        "XGBoost"
    ]
)

Sidebar is commonly used for settings and navigation.

13. Display Tables

import pandas as pd
df = pd.DataFrame({
    "Name":["A","B"],
    "Age":[20,25]
})

st.dataframe(df)

Interactive features include sorting and scrolling.

14. Display Charts

import pandas as pd
chart = pd.DataFrame({
    "Sales":[10,15,8,20]
})

st.line_chart(chart)

Other built-in chart options include

Bar charts

Area charts

For advanced visualizations, you can integrate libraries such as Matplotlib, Plotly, or Altair.

15. Display Images

from PIL import Image
image = Image.open("house.jpg")

st.image(image)

16. File Upload

uploaded = st.file_uploader(
    "Upload CSV"
)

Supported uploads include

  • CSV
  • Excel
  • PDF
  • Images
  • Text files

17. Machine Learning Prediction

Load model

import joblib
model = joblib.load(
    "model.pkl"
)

User input

area = st.number_input(
    "Area"
)
bedrooms = st.number_input(
    "Bedrooms"
)

Prediction

if st.button("Predict"):
prediction = model.predict(
\[[area, bedrooms]\]

)

st.success(

prediction[0]

)

18. Complete Workflow

User
Streamlit Form
Python
ML Model
Prediction
Display Result

19. Session State

Session State remembers values during a user's interaction.

Example

if "count" not in st.session_state:
    st.session_state.count = 0
if st.button("Click"):
    st.session_state.count += 1

st.write(st.session_state.count)

Useful for

  • Chat history
  • Login state
  • Multi-step workflows

20. Multipage Applications

Example structure

AI_Dashboard/
├── Home.py

├── pages/

│ Prediction.py

│ Dashboard.py

│ Reports.py

Each file becomes a page in the Streamlit app.

21. Streamlit + FastAPI

A common production architecture

User
Browser
Streamlit UI
FastAPI REST API
Machine Learning Model
  • Why?
  • Streamlit handles the frontend.
  • FastAPI serves the backend API.
  • They can be deployed independently.

22. Streamlit + Docker

  • Dockerfile
  • FROM python:3.11
  • WORKDIR /app
  • COPY . .
  • RUN pip install -r requirements.txt
  • EXPOSE 8501
  • CMD [
  • "streamlit",

"run",

"app.py",

"--server.address=0.0.0.0"

]

Run

docker build -t streamlit-app .
docker run -p 8501:8501 streamlit-app

23. Streamlit in MLOps

Train Model
MLflow
FastAPI
Streamlit Dashboard
Docker
Kubernetes
Production

24. Real-World Applications

House Price Prediction

Input property details.

  • Display predicted price.
  • Customer Churn Dashboard
  • Display churn probability.
  • Stock Market Dashboard
  • Interactive charts.
  • Medical Diagnosis
  • Upload reports.

AI prediction.

ChatGPT Interface

Build a conversational chatbot using Streamlit as the frontend.

25. Streamlit vs Flask vs FastAPI

StreamlitFlaskFastAPI
Interactive UIWeb frameworkAPI framework
Dashboard developmentWeb appsREST APIs
Minimal frontend codingFlexible architectureHigh-performance APIs
Best for ML demosFull web applicationsML model serving

26. Advantages

  • Very easy to learn.
  • Rapid application development.
  • Excellent for AI demos.
  • Interactive widgets.
  • Built-in chart support.
  • Pure Python development.

27. Limitations

  • Less customizable than full frontend frameworks like React or Angular.
  • Not ideal for very large, highly customized web applications.
  • Complex authentication often requires additional components.
  • High-traffic production systems may benefit from separating the frontend and backend.

28. Best Practices

  • Keep business logic separate from UI code.
  • Cache expensive operations using Streamlit caching features.
  • Validate user input.
  • Store secrets securely.
  • Organize multipage apps.
  • Add logging and error handling.

29. Common Mistakes

  • Loading the model every time a widget changes.
  • Mixing model training and UI code.
  • Not validating uploaded files.
  • Keeping all code in one large file.
  • Hardcoding API keys.

30. Interview Questions

Beginner

  • What is Streamlit?
  • Why is Streamlit popular?
  • How do you create a Streamlit app?
  • How do you take user input?
  • What is st.write()?

Intermediate

  • What is Session State?
  • How do you upload files?
  • How do you display charts?
  • How do you integrate ML models?
  • Streamlit vs Flask?

Advanced

  • Streamlit vs FastAPI?
  • How would you deploy Streamlit using Docker?
  • How would you build an AI dashboard?
  • How would you integrate Streamlit with Kubernetes?
  • How would you optimize Streamlit performance?

31. Mini Project

  • House Price Prediction Dashboard
  • Project Structure
  • HousePriceDashboard/
  • ├── app.py
  • ├── model.pkl
  • ├── requirements.txt
  • ├── Dockerfile
  • ├── pages/
  • └── images/
  • Features
  • Enter house details.
  • Predict house prices.
  • Display charts.
  • Upload CSV files.
  • Compare predictions.
  • Deploy using Docker.

32. Enterprise AI Dashboard

User

Streamlit Dashboard

┌─────────┴─────────┐

▼ ▼

FastAPI API MLflow Metrics

│ │

▼ ▼

ML Model Service Experiment Logs

Prediction Result

33. Chapter Summary

Streamlit is a Python framework for rapidly building interactive web applications for Machine Learning, Data Science, and AI. It enables developers to create dashboards, prediction tools, and data exploration interfaces using only Python. Combined with FastAPI, Docker, and Kubernetes, Streamlit forms an excellent frontend for modern MLOps applications.

Streamlit Workflow Cheat Sheet

Train Model

Save Model

Streamlit App

User Input

Prediction

Display Result

Deploy with Docker

Learning Progress

  • Git & GitHub

  • Docker

  • Kubernetes

  • MLflow

  • DVC

  • FastAPI

  • Flask

  • Streamlit

You now have all the essential tools to build a complete AI application

  • Git → Version control
  • Docker → Containerization
  • Kubernetes → Container orchestration
  • MLflow → Experiment tracking
  • DVC → Dataset and model versioning
  • FastAPI → High-performance backend APIs
  • Flask → Lightweight web framework
  • Streamlit → Interactive AI dashboards

Together, these technologies form the foundation of a modern production-ready MLOps stack.

What's Next?

In Chapter 10.9 – Azure Machine Learning, you'll learn how to use Microsoft's cloud platform to train, register, deploy, monitor, and manage machine learning models at scale. You'll explore Azure ML Workspaces, Compute Instances, Pipelines, Model Registry, Managed Endpoints, AutoML, and Responsible AI, enabling enterprise-grade AI deployments on Azure.

Module 10 · Lesson 10.9

Azure Machine Learning

Chapter 10.9 – Azure Machine Learning

  • Azure Machine Learning (Azure ML) is Microsoft's cloud platform for building, training, deploying, monitoring, and managing Machine Learning models at enterprise scale.

It provides a complete MLOps platform that integrates with GitHub, Azure DevOps, MLflow, Docker, Kubernetes, Azure Storage, Azure Data Factory, Synapse Analytics, Power BI, and Azure Monitor.

Learning Objectives

By the end of this chapter, you will be able to

  • Understand Azure Machine Learning.
  • Learn Azure ML architecture.
  • Create an Azure ML Workspace.
  • Understand Compute Instances and Compute Clusters.
  • Work with Datasets and Datastores.
  • Train Machine Learning models.
  • Register models.
  • Deploy models as online endpoints.
  • Monitor deployed models.
  • Build Azure ML Pipelines.
  • Understand AutoML and Responsible AI.
  • Prepare for Azure ML interview questions.

1. Introduction

Imagine your company has developed a Customer Churn Prediction Model.

Management wants it to

  • Serve predictions to millions of customers.
  • Scale automatically.
  • Track model versions.
  • Monitor performance.
  • Retrain models when data changes.
  • Integrate with enterprise systems.

Doing all of this manually is difficult.

Azure Machine Learning provides a managed platform to accomplish these tasks.

2. What is Azure Machine Learning?

Definition

Azure Machine Learning is a cloud-based platform for the complete Machine Learning lifecycle, including data preparation, model training, experiment tracking, deployment, monitoring, and MLOps automation.

Azure ML supports

  • Machine Learning
  • Deep Learning
  • NLP
  • Computer Vision
  • Generative AI
  • Responsible AI
  • MLOps

3. Why Azure ML?

Suppose you train a model on your laptop.

Problems

  • Limited CPU/GPU.
  • Difficult collaboration.
  • Manual deployment.
  • No centralized model management.

Azure ML solves these by providing scalable cloud infrastructure and managed services.

4. Azure ML Architecture

Azure Machine Learning

┌───────────────────────┼────────────────────────┐

│ │ │

▼ ▼ ▼

Workspace Compute Datastores

│ │ │

▼ ▼ ▼

Experiments Training Jobs Datasets

Model Registry

Managed Online Endpoint

Applications / Users

5. Azure ML Workspace

The Workspace is the central resource for Azure ML.

It stores

  • Experiments
  • Models
  • Compute resources
  • Datasets
  • Endpoints
  • Pipelines
  • Monitoring information

Think of it as the "project folder" for all ML resources.

6. Azure ML Components

ComponentPurpose
WorkspaceCentral management hub
Compute InstanceDevelopment machine
Compute ClusterScalable training compute
DatastoreConnection to storage
Dataset / Data AssetManaged data reference
ExperimentCollection of runs
Model RegistryStore model versions
EndpointServe predictions
PipelineAutomate ML workflows

7. Compute Instance

A Compute Instance is a managed virtual machine for development.

Typical uses

  • Jupyter notebooks
  • VS Code
  • Data exploration
  • Model development
  • Debugging
Developer
Compute Instance
Python / Notebook

8. Compute Cluster

A Compute Cluster is used for scalable training.

Example

Training Job
8 Virtual Machines
Parallel Training

Clusters can automatically scale up when jobs are submitted and scale down when idle.

9. Datastore

A Datastore securely connects Azure ML to external storage.

Common storage options

  • Azure Blob Storage
  • Azure Data Lake Storage Gen2
  • Azure Files
  • SQL Database

The datastore stores connection information, not the data itself.

10. Data Assets (Datasets)

Azure ML manages datasets as reusable Data Assets.

Example

Customer Data
Azure Blob Storage
Azure ML Data Asset

Benefits

  • Reusability
  • Versioning
  • Team collaboration

11. Training a Model

Typical workflow

Dataset
Training Script
Compute Cluster
Trained Model

Training can use CPUs or GPUs depending on the workload.

12. Azure ML Experiment

An Experiment groups multiple training runs.

Example

House Price Prediction

  • ├── Run 1
  • ├── Run 2
  • └── Run 3

Each run logs metrics, parameters, and outputs.

13. Experiment Tracking

Azure ML records

  • Hyperparameters
  • Accuracy
  • Precision
  • Recall
  • F1 Score
  • Training duration
  • Logs
  • Artifacts

Azure ML also supports MLflow, allowing familiar experiment tracking workflows.

14. Model Registry

After training, register the model.

Model
Register
Version 1
Version 2
Version 3

Benefits

  • Centralized storage
  • Version management
  • Easier deployment

15. Model Deployment

Azure ML supports multiple deployment targets.

Registered Model
Managed Online Endpoint
REST API
Users

Deployment options include

  • Managed Online Endpoints
  • Kubernetes (AKS)
  • Batch Endpoints

16. Online Endpoints

Use Online Endpoints for real-time predictions.

Example

Customer
REST API
Prediction

Typical use cases

  • Fraud detection
  • Recommendation systems
  • Chatbots
  • Price prediction

17. Batch Endpoints

Use Batch Endpoints for large-scale offline inference.

Example

1 Million Records
Batch Endpoint
Predictions Stored

Ideal for nightly or scheduled processing.

18. Azure ML Pipelines

Automate ML workflows.

Data Collection
Data Cleaning
Feature Engineering
Training
Evaluation
Deployment

Pipelines improve reproducibility and automation.

19. AutoML

AutoML automatically tries multiple algorithms and hyperparameters.

Example

Dataset
AutoML
Random Forest
XGBoost
LightGBM
Best Model

Useful when you want Azure ML to search for a strong baseline model.

20. Responsible AI

Azure ML provides tools for

  • Model explainability
  • Fairness analysis
  • Error analysis
  • Data insights

These features help teams build trustworthy AI systems.

21. Monitoring

After deployment, monitor

  • Latency
  • Request volume
  • Errors
  • Resource usage
  • Prediction performance

Monitoring helps detect issues before they affect users.

22. End-to-End Azure ML Workflow

Prepare Data

Upload Data

Train Model

Track Experiment

Register Model

Deploy Endpoint

Monitor

Retrain

23. Integration with Azure Services

Azure ML integrates with many Azure services.

Azure ServicePurpose
Azure StorageData storage
Azure Data FactoryData ingestion
Azure Synapse AnalyticsAnalytics and data warehousing
Azure Key VaultSecret management
Azure MonitorMonitoring and alerts
Azure Kubernetes Service (AKS)Container orchestration
Microsoft Entra IDAuthentication and authorization

24. Azure ML + MLOps

GitHub
Azure DevOps / GitHub Actions
Azure ML Training
Model Registry
Managed Endpoint
Monitoring
Retraining

This creates a complete cloud-based MLOps workflow.

25. Real-World Example

A bank builds a loan approval model.

Workflow

  • Data stored in Azure Data Lake.
  • Azure ML trains multiple models.
  • Best model registered.
  • Model deployed as an online endpoint.
  • Loan application portal calls the endpoint.
  • Azure Monitor tracks usage and performance.
  • New data triggers retraining through pipelines.

26. Advantages

  • Fully managed ML platform.
  • Scalable CPU and GPU training.
  • Integrated experiment tracking.
  • Built-in model registry.
  • Managed deployment.
  • Enterprise security.
  • Deep integration with Azure services.

27. Limitations

  • Azure costs depend on compute and storage usage.
  • Initial setup can be complex.
  • Requires understanding of Azure resources.
  • Cloud permissions and networking must be managed carefully.

28. Best Practices

  • Use separate workspaces for development, testing, and production.
  • Register every production model.
  • Use managed identities where possible instead of storing credentials.
  • Automate deployments using CI/CD.
  • Monitor endpoints continuously.
  • Use versioned data assets and pipelines.

29. Common Mistakes

  • Training large models on a small compute instance.
  • Deploying models without monitoring.
  • Not versioning datasets or models.
  • Hardcoding secrets instead of using Azure Key Vault.
  • Skipping testing before production deployment.

30. Interview Questions

Beginner

  • What is Azure Machine Learning?
  • What is an Azure ML Workspace?
  • What is a Compute Instance?
  • What is a Compute Cluster?
  • What is a Model Registry?

Intermediate

  • Difference between Online Endpoint and Batch Endpoint?
  • What is AutoML?
  • What are Azure ML Pipelines?
  • How do you track experiments?
  • What are Data Assets?

Advanced

  • Design an end-to-end Azure ML architecture.
  • How would you deploy a model to production?
  • How would you integrate Azure ML with GitHub Actions?
  • How would you monitor production models?
  • Explain an enterprise MLOps workflow using Azure ML.

31. Mini Project

  • Customer Churn Prediction on Azure ML
  • Project Workflow
  • Customer Dataset

Azure Blob Storage

Azure ML Data Asset

Training Job

Experiment Tracking

Model Registry

Managed Online Endpoint

  • Customer Prediction API
  • Tasks
  • Create an Azure ML Workspace.
  • Upload the dataset as a Data Asset.
  • Train a classification model.
  • Register the best model.
  • Deploy it as a Managed Online Endpoint.
  • Test predictions using REST API.
  • Monitor endpoint performance.

32. Azure ML Workflow Cheat Sheet

Workspace

Data Asset

Training Job

Experiment

Model Registry

Online Endpoint

Applications

Monitoring

Chapter Summary

Azure Machine Learning is Microsoft's cloud platform for building, training, deploying, and managing machine learning models at scale. It provides managed infrastructure, experiment tracking, model versioning, automated pipelines, online and batch deployment options, and enterprise-grade security. Azure ML is a core service for organizations implementing production MLOps on Microsoft Azure.

Learning Progress

  • Git & GitHub

  • Docker

  • Kubernetes

  • MLflow

  • DVC

  • FastAPI

  • Flask

  • Streamlit

  • Azure Machine Learning

At this point, you have learned the essential building blocks of an enterprise MLOps platform:

  • Git for source code management.
  • Docker for containerization.
  • Kubernetes for orchestration.
  • MLflow for experiment tracking.
  • DVC for data and model versioning.
  • FastAPI and Flask for serving models.
  • Streamlit for interactive dashboards.

Azure Machine Learning for cloud-based model training, deployment, and lifecycle management.

What's Next?

In Chapter 10.10 – AWS SageMaker, you'll learn Amazon's managed Machine Learning platform. You'll explore SageMaker Studio, training jobs, processing jobs, model registry, hosted endpoints, batch inference, monitoring, and MLOps integration, and compare it with Azure Machine Learning.

Module 10 · Lesson 10.10

AWS SageMaker

Chapter 10.10 – AWS SageMaker

  • Amazon SageMaker is Amazon Web Services' fully managed Machine Learning platform that enables data scientists and ML engineers to build, train, deploy, monitor, and manage machine learning models at scale.

It provides everything needed for an end-to-end ML lifecycle, from data preparation to production deployment, without managing the underlying infrastructure.

Learning Objectives

By the end of this chapter, you will be able to

  • Understand Amazon SageMaker.
  • Learn SageMaker architecture.
  • Understand SageMaker Studio.
  • Train Machine Learning models.
  • Process datasets.
  • Register and version models.
  • Deploy models to endpoints.
  • Perform batch inference.
  • Monitor deployed models.
  • Integrate SageMaker with MLOps.
  • Compare SageMaker with Azure ML.
  • Prepare for SageMaker interview questions.

1. Introduction

Suppose your company wants to build an AI-powered fraud detection system.

Requirements

  • Train on 100 million transactions.
  • Use GPUs for deep learning.
  • Deploy globally.
  • Handle thousands of requests per second.
  • Automatically monitor models.
  • Retrain models periodically.
  • Managing servers manually would be difficult.

Amazon SageMaker provides managed infrastructure to simplify these tasks.

2. What is Amazon SageMaker?

Definition

Amazon SageMaker is a fully managed Machine Learning service provided by AWS that enables developers to build, train, deploy, and monitor ML models at scale.

It supports

  • Machine Learning
  • Deep Learning
  • Computer Vision
  • Natural Language Processing
  • Generative AI
  • Reinforcement Learning

3. Why SageMaker?

Without SageMaker

Buy Servers
Install Python
Install CUDA
Install TensorFlow
Configure GPUs
Train Model

With SageMaker

Upload Dataset
Choose Algorithm
Train
Deploy
Monitor

AWS manages the underlying infrastructure.

4. SageMaker Architecture

Amazon SageMaker

┌─────────────────────────┼─────────────────────────┐

▼ ▼ ▼

Studio Training Jobs Processing Jobs

Model Registry

Endpoints

Applications

5. SageMaker Components

ComponentPurpose
SageMaker StudioML development environment
Notebook InstanceInteractive notebooks
Processing JobsData preparation
Training JobsTrain ML models
Model RegistryStore model versions
EndpointsReal-time inference
Batch TransformBatch predictions
PipelinesWorkflow automation
Model MonitorMonitor deployed models

6. SageMaker Studio

SageMaker Studio is the primary development environment.

Features

  • Jupyter notebooks
  • Experiment management
  • Model development
  • Visualization
  • Debugging
  • Collaboration

Think of it as an integrated IDE for Machine Learning on AWS.

7. Notebook Instance

Notebook Instances provide managed Jupyter notebook environments.

Typical uses

  • Data exploration
  • Feature engineering
  • Model development
  • Visualization

8. Processing Jobs

Processing Jobs prepare data before training.

Typical workflow

Raw Data
Cleaning
Feature Engineering
Processed Dataset

Common tasks

  • Missing value handling
  • Encoding categorical variables
  • Feature scaling
  • Data validation

9. Training Jobs

Training Jobs execute model training on managed compute.

Dataset
Training Script
CPU / GPU Instances
Trained Model

You can choose different instance types depending on workload.

10. Built-in Algorithms

SageMaker provides several built-in algorithms.

Examples

  • Linear Learner
  • XGBoost
  • Random Cut Forest
  • K-Means
  • PCA
  • Object Detection
  • Image Classification

You can also use custom training code with frameworks such as TensorFlow, PyTorch, and Scikit-learn.

11. Bring Your Own Algorithm

If your model isn't built using SageMaker's built-in algorithms,

you can package it inside a Docker container.

Example

Custom Python Code
Docker Image
SageMaker Training

12. Experiment Tracking

SageMaker records

  • Parameters
  • Metrics
  • Logs
  • Model artifacts

It also integrates with MLflow if your organization prefers a common experiment tracking platform.

13. Model Registry

The Model Registry stores approved models.

Model
Version 1
Version 2
Version 3

Each version includes

  • Metadata
  • Approval status
  • Associated artifacts

14. Deploying Models

Deploy the registered model

Model
Endpoint
REST API
Prediction

Endpoints provide real-time inference.

15. Real-Time Endpoints

Use when predictions are needed immediately.

Examples

  • Fraud detection
  • Loan approval
  • Recommendation systems
  • Chatbots

16. Batch Transform

Batch Transform performs predictions on large datasets.

Example

1 Million Records
Batch Transform
Prediction File

Ideal for nightly or scheduled inference jobs.

17. SageMaker Pipelines

Automate ML workflows.

Data Collection
Processing
Training
Evaluation
Model Registration
Deployment

18. Model Monitor

Model Monitor continuously checks production models.

It monitors

  • Data quality
  • Feature distributions
  • Prediction quality
  • Drift

Example

Production Data
Model Monitor
Alert
Retraining

19. Automatic Scaling

Suppose

100 Users

One endpoint instance.

Traffic increases

100,000 Users

Additional endpoint instances are created automatically (if auto scaling is configured).

20. Security

AWS provides

  • IAM (Identity and Access Management)
  • Encryption
  • VPC Integration
  • CloudTrail Auditing
  • AWS KMS
  • These help secure ML workloads.

21. SageMaker Workflow

Collect Data
Processing Job
Training Job
Model Registry
Endpoint

Applications

Monitoring

22. Integration with AWS Services

AWS ServicePurpose
Amazon S3Dataset storage
AWS LambdaServerless automation
Amazon CloudWatchMonitoring and logs
Amazon ECRDocker image registry
AWS CodePipelineCI/CD
AWS Step FunctionsWorkflow orchestration
Amazon ECS / EKSContainer orchestration

23. SageMaker + MLOps

GitHub
AWS CodePipeline
SageMaker Training
Model Registry
Endpoint
Monitoring
Retraining

24. Real-World Example

An e-commerce company builds a product recommendation system.

Workflow

  • Customer data stored in Amazon S3.
  • Processing Jobs clean the data.
  • Training Jobs build recommendation models.
  • Best model registered.
  • Endpoint serves recommendations.
  • Model Monitor checks prediction quality.
  • Pipeline retrains periodically.

25. Azure ML vs SageMaker

Azure MLAWS SageMaker
Microsoft Azure ecosystemAWS ecosystem
Azure ML WorkspaceSageMaker Studio
Managed Online EndpointSageMaker Endpoint
Azure Blob StorageAmazon S3
Azure MonitorAmazon CloudWatch
Azure ML PipelinesSageMaker Pipelines
Azure Key VaultAWS Secrets Manager / IAM integration

26. Advantages

  • Fully managed platform.
  • Excellent scalability.
  • GPU support.
  • Strong AWS integration.
  • Built-in monitoring.
  • Enterprise security.
  • Flexible deployment options.

27. Limitations

  • Costs can increase with large compute resources.
  • Many AWS services require learning.
  • Initial setup can be complex.
  • Proper IAM permissions are essential.

28. Best Practices

  • Store datasets in Amazon S3.
  • Register every production model.
  • Monitor deployed endpoints.
  • Automate training with SageMaker Pipelines.
  • Use infrastructure as code where possible.
  • Optimize instance selection to control costs.

29. Common Mistakes

  • Using oversized instances unnecessarily.
  • Ignoring endpoint monitoring.
  • Not versioning models.
  • Hardcoding AWS credentials.
  • Deploying without testing.

30. Interview Questions

Beginner

  • What is Amazon SageMaker?
  • What is SageMaker Studio?
  • What is a Training Job?
  • What is Batch Transform?
  • What is a Model Registry?

Intermediate

  • Difference between Processing Job and Training Job?
  • What is a SageMaker Endpoint?
  • What is Model Monitor?
  • What are SageMaker Pipelines?
  • Difference between Batch Transform and Real-Time Endpoints?

Advanced

  • Design a SageMaker architecture for fraud detection.
  • Azure ML vs SageMaker?
  • How would you deploy a deep learning model?
  • How would you automate retraining?
  • How would you build an enterprise MLOps workflow on AWS?

31. Mini Project

Customer Churn Prediction using SageMaker

Workflow

Customer Data
Amazon S3
Processing Job
Training Job
Model Registry
Endpoint
Customer Prediction API
  • Tasks
  • Upload dataset to Amazon S3.
  • Create a Processing Job.
  • Train a classification model.
  • Register the model.
  • Deploy it to a real-time endpoint.
  • Test predictions.
  • Configure Model Monitor.
  • Create a retraining pipeline.

32. Complete SageMaker Workflow

Amazon S3
Processing
Training
Experiment
Model Registry
Endpoint
Monitoring
Retraining

Chapter Summary

Amazon SageMaker is AWS's fully managed Machine Learning platform for developing, training, deploying, and monitoring ML models. It simplifies infrastructure management while providing scalable compute, experiment tracking, model versioning, automated pipelines, real-time and batch inference, and production monitoring. SageMaker is a core service for organizations building MLOps solutions on AWS.

Learning Progress

  • Git & GitHub

  • Docker

  • Kubernetes

  • MLflow

  • DVC

  • FastAPI

  • Flask

  • Streamlit

  • Azure Machine Learning

  • AWS SageMaker

You now understand the two largest cloud ML platforms

Azure Machine Learning for Microsoft Azure.

Amazon SageMaker for AWS.

Both platforms provide managed services for training, deployment, monitoring, and MLOps, but they are optimized for their respective cloud ecosystems.

What's Next?

In Chapter 10.11 – Google Vertex AI, you'll learn Google's unified AI platform. You'll explore Vertex AI Workbench, custom training, AutoML, Pipelines, Feature Store, Model Registry, online prediction endpoints, and MLOps integration, and compare Vertex AI with Azure Machine Learning and AWS SageMaker.

Module 10 · Lesson 10.11

Google Vertex AI

Chapter 10.11 – Google Vertex AI

  • Google Vertex AI is Google Cloud Platform's unified Machine Learning platform that enables developers to build, train, deploy, monitor, and manage Machine Learning and Generative AI models using a single cloud service.

It combines Google's expertise in AI (TensorFlow, DeepMind, Gemini, Kubernetes, and BigQuery) into one enterprise-grade MLOps platform.

Learning Objectives

By the end of this chapter, you will be able to

  • Understand Google Vertex AI.
  • Learn Vertex AI architecture.
  • Work with Vertex AI Workbench.
  • Train ML models.
  • Use AutoML.
  • Deploy prediction endpoints.
  • Manage Model Registry.
  • Build ML Pipelines.
  • Monitor deployed models.
  • Understand Feature Store.
  • Integrate Vertex AI with MLOps.

Compare Vertex AI with Azure ML and AWS SageMaker.

Prepare for Vertex AI interview questions.

1. Introduction

Suppose you're building an AI application that predicts crop diseases.

Requirements

  • Store millions of images.
  • Train deep learning models on GPUs.
  • Deploy globally.
  • Serve predictions in real time.
  • Monitor model performance.
  • Automatically retrain models.

Google Cloud provides Vertex AI to manage the entire lifecycle.

2. What is Vertex AI?

Definition

Vertex AI is Google Cloud's unified Machine Learning platform for building, training, deploying, monitoring, and managing AI and ML models at scale.

It supports

  • Machine Learning
  • Deep Learning
  • NLP
  • Computer Vision
  • Time Series Forecasting
  • Reinforcement Learning
  • Generative AI
  • Foundation Models

3. Why Vertex AI?

Without Vertex AI

Collect Data
Build Infrastructure
Configure GPUs
Train Model
Deploy
Monitor

With Vertex AI

Upload Data
Train
Deploy
Monitor
Retrain

Most infrastructure management is handled by Google Cloud.

4. Vertex AI Architecture

Google Vertex AI

┌──────────────────────┼────────────────────────┐

▼ ▼ ▼

Workbench Training Jobs AutoML

Model Registry

Prediction Endpoints

Applications

5. Vertex AI Components

ComponentPurpose
Vertex AI WorkbenchDevelopment environment
DatasetsManage training data
Training JobsModel training
AutoMLAutomatic model building
Model RegistryModel versioning
Prediction EndpointsReal-time inference
Batch PredictionOffline inference
Vertex AI PipelinesWorkflow automation
Model MonitoringProduction monitoring
Feature StoreCentralized feature management

6. Vertex AI Workbench

Workbench is Google's managed notebook environment.

Features

  • JupyterLab
  • Python development
  • GPU support
  • BigQuery integration
  • Git integration
  • TensorFlow & PyTorch support

Developers write code here before submitting training jobs.

7. Datasets

Datasets can include

  • CSV files
  • Images
  • Videos
  • Audio
  • Text

Example

Customer Data
Google Cloud Storage
Vertex AI Dataset

8. Training Jobs

Training Jobs execute model training on managed infrastructure.

Dataset
Training Script
GPU/CPU Cluster
Trained Model

Supported frameworks include

  • TensorFlow
  • PyTorch
  • Scikit-learn
  • XGBoost
  • Custom Docker containers

9. AutoML

AutoML enables users to build ML models without writing extensive code.

Example

Dataset
AutoML
Try Multiple Algorithms
Best Model

AutoML supports

  • Tabular data
  • Images
  • Text
  • Video

10. Custom Training

For complete flexibility

Python Script
Docker Container
Vertex AI Training
Model

You control

  • Training code
  • Framework
  • Libraries
  • Hyperparameters

11. Model Registry

Store trained models.

Customer Churn
Version 1
Version 2
Version 3

Benefits

  • Version history
  • Deployment tracking
  • Rollback capability

12. Prediction Endpoints

Deploy models for real-time inference.

Application
Vertex Endpoint
Prediction

Common use cases

  • Chatbots
  • Fraud detection
  • Medical diagnosis
  • Recommendation engines

13. Batch Prediction

Used when predicting on very large datasets.

Example

10 Million Records
Batch Prediction
Output File

Suitable for

  • Nightly scoring
  • Reporting
  • Bulk predictions

14. Vertex AI Pipelines

Automate ML workflows.

Collect Data
Preprocessing
Training
Evaluation
Register Model
Deploy

Pipelines support reproducible and repeatable ML processes.

15. Feature Store

A Feature Store stores reusable ML features.

Example

Customer Age

Purchase History

Credit Score
Feature Store
Multiple Models

Benefits

  • Reuse
  • Consistency
  • Faster development

16. Model Monitoring

Monitor production models.

Track

  • Prediction latency
  • Data drift
  • Feature drift
  • Prediction quality
  • Resource usage
  • If problems are detected,
  • alerts can trigger retraining workflows.

17. Vertex AI Workflow

Prepare Data
Upload Dataset
Training Job
Model Registry
Endpoint
Monitoring
Retraining

18. Generative AI Support

Vertex AI supports modern Generative AI workflows.

Examples

  • Large Language Models
  • Chatbots
  • Document Summarization
  • Code Generation
  • Image Generation

Google also provides managed access to foundation models through Vertex AI.

19. Integration with Google Cloud Services

Google Cloud ServicePurpose
Cloud StorageData storage
BigQueryAnalytics
Cloud FunctionsEvent-driven automation
Cloud RunServerless deployment
GKE (Google Kubernetes Engine)Kubernetes
Cloud LoggingLogging
Cloud MonitoringMonitoring
Artifact RegistryDocker image storage

20. Vertex AI + MLOps

GitHub
Cloud Build
Vertex AI Training
Model Registry
Endpoint
Monitoring
Retraining

21. Real-World Example

Suppose an agricultural company wants to detect crop diseases.

Workflow

Leaf Images
Cloud Storage
Vertex AI Dataset
Training
Model Registry
Endpoint
Farmer Mobile App

The mobile application sends leaf images to Vertex AI.

The endpoint predicts the disease in real time.

22. Azure ML vs SageMaker vs Vertex AI

FeatureAzure MLSageMakerVertex AI
Cloud ProviderMicrosoft AzureAWSGoogle Cloud
Development EnvironmentCompute InstanceSageMaker StudioVertex AI Workbench
StorageAzure Blob StorageAmazon S3Google Cloud Storage
PipelinesAzure ML PipelinesSageMaker PipelinesVertex AI Pipelines
Model RegistryYesYesYes
AutoMLYesYesYes
Batch InferenceYesYesYes
Real-Time EndpointsYesYesYes
Kubernetes IntegrationAKSEKSGKE

23. Advantages

  • Fully managed ML platform.
  • Strong TensorFlow integration.
  • AutoML support.
  • Excellent support for Generative AI.
  • Feature Store.
  • Scalable infrastructure.
  • Enterprise-grade security.

24. Limitations

  • Costs increase with GPU usage.
  • Google Cloud knowledge is required.
  • Large projects require proper IAM configuration.
  • Managing cloud resources requires planning.

25. Best Practices

  • Store datasets in Cloud Storage.
  • Version every model.
  • Monitor deployed endpoints.
  • Use Pipelines for automation.
  • Reuse features with Feature Store.
  • Separate development, testing, and production environments.

26. Common Mistakes

  • Deploying models without monitoring.
  • Ignoring feature drift.
  • Hardcoding credentials.
  • Not versioning datasets.
  • Training large models on insufficient compute resources.

27. Interview Questions

Beginner

  • What is Vertex AI?
  • What is Vertex AI Workbench?
  • What is AutoML?
  • What is a Prediction Endpoint?
  • What is Feature Store?

Intermediate

  • Difference between Batch Prediction and Online Prediction?
  • What is Model Registry?
  • What are Vertex AI Pipelines?
  • What is Model Monitoring?
  • What is Custom Training?

Advanced

  • Explain Vertex AI architecture.
  • Azure ML vs SageMaker vs Vertex AI?
  • How would you deploy a deep learning model?
  • How would you automate retraining?
  • Design an enterprise MLOps solution using Vertex AI.

28. Mini Project

Crop Disease Detection using Vertex AI

Workflow

Leaf Images
Cloud Storage
Vertex AI Dataset
Training
Model Registry
Prediction Endpoint
Farmer Mobile App
  • Tasks
  • Upload image dataset.
  • Create a Vertex AI Dataset.
  • Train an image classification model.
  • Register the trained model.
  • Deploy it to a Prediction Endpoint.
  • Test predictions.
  • Enable Model Monitoring.
  • Build an automated retraining pipeline.

29. Complete Vertex AI Workflow

Cloud Storage
Dataset
Training
Experiment
Model Registry
Endpoint
Monitoring
Retraining

Chapter Summary

Google Vertex AI is Google Cloud's unified AI and Machine Learning platform. It provides managed tools for data preparation, training, AutoML, model versioning, deployment, monitoring, Feature Store, and MLOps automation. It also supports modern Generative AI applications, making it one of the most comprehensive AI platforms available today.

Learning Progress

  • Git & GitHub

  • Docker

  • Kubernetes

  • MLflow

  • DVC

  • FastAPI

  • Flask

  • Streamlit

  • Azure Machine Learning

  • AWS SageMaker

  • Google Vertex AI

At this stage, you've learned the three major enterprise cloud ML platforms

  • Azure Machine Learning (Microsoft Azure)
  • Amazon SageMaker (AWS)
  • Google Vertex AI (Google Cloud Platform)

Although the interfaces differ, they all provide the same core capabilities

  • Managed model training
  • Experiment tracking
  • Model registry
  • Real-time and batch deployment
  • Monitoring
  • Automated ML pipelines
  • MLOps integration
  • Cloud Platform Comparison
CapabilityAzure MLAWS SageMakerGoogle Vertex AI
Workspace/StudioAzure ML WorkspaceSageMaker StudioVertex AI Workbench
Data StorageAzure Blob StorageAmazon S3Cloud Storage
Experiment TrackingAzure ML + MLflowSageMaker ExperimentsVertex AI Experiments
Model RegistryYesYesYes
AutoMLYesYesYes
PipelinesYesYesYes
Feature StoreLimited native support (ecosystem-based)AvailableNative Vertex AI Feature Store
Kubernetes IntegrationAKSEKSGKE
Generative AI SupportAzure OpenAI integrationAmazon Bedrock integrationVertex AI foundation models

What's Next?

In Chapter 10.12 – CI/CD, you'll learn how to automatically build, test, validate, and deploy machine learning applications whenever code changes are pushed to Git. You'll explore tools such as GitHub Actions, Azure DevOps, Jenkins, and AWS CodePipeline, and build a complete automated MLOps deployment pipeline.

Module 10 · Lesson 10.12

CI/CD

Chapter 10.12 – CI/CD (Continuous Integration & Continuous Deployment)

  • CI/CD is the backbone of modern DevOps and MLOps.

Every time a developer pushes code to GitHub, automated pipelines can build, test, package, and deploy the application without manual intervention.

Companies like Google, Microsoft, Amazon, Netflix, Meta, Uber, and OpenAI rely heavily on CI/CD to deliver software and machine learning models quickly and reliably.

Learning Objectives

By the end of this chapter, you will be able to

  • Understand CI/CD concepts.
  • Learn Continuous Integration (CI).
  • Learn Continuous Deployment (CD).
  • Build CI/CD pipelines.
  • Use GitHub Actions.
  • Understand Azure DevOps and Jenkins.
  • Automate ML model deployment.
  • Integrate CI/CD with Docker, Kubernetes, and MLflow.
  • Learn CI/CD best practices.
  • Prepare for CI/CD interview questions.

1. Introduction

Imagine you're working on a Machine Learning project with five developers.

Every day, developers

  • Fix bugs
  • Improve models
  • Update APIs
  • Add new features

Without automation

Developer
Manual Build
Manual Testing
Manual Deployment
Production

Problems

  • Human errors
  • Slow deployments
  • Missed tests
  • Inconsistent environments
  • CI/CD automates the entire process.

2. What is CI/CD?

CI/CD stands for

Continuous Integration (CI)

Continuous Delivery (CD) or Continuous Deployment (CD)

It is a practice that automates building, testing, and deploying software.

3. Continuous Integration (CI)

Definition

Continuous Integration is the practice of frequently merging code changes into a shared repository where automated builds and tests are executed.

Instead of merging code once every month,

developers merge changes several times a day.

Example

Developer A
Git Push
CI Pipeline
Build
Tests
Success

4. Why Continuous Integration?

Suppose

Developer A modifies

predict()

Developer B modifies

train()

Developer C modifies

database.py

CI automatically

  • Builds the application.
  • Runs tests.
  • Detects integration issues early.

5. Continuous Delivery vs Continuous Deployment

Continuous Delivery

Code
Build
Test
Ready for Deployment
Manual Approval
Production

Deployment requires human approval.

Continuous Deployment

Code
Build
Test
Automatic Deployment
Production

No manual approval is required once all checks pass.

6. CI/CD Workflow

Developer
Git Push
Build
Unit Tests
Docker Image
Deploy
Production

Every code change follows the same automated path.

7. CI/CD Pipeline

A pipeline is a sequence of automated steps.

Typical stages

Source Code
Build
Test
Package
Deploy
Monitor

8. Popular CI/CD Tools

ToolCloud / Platform
GitHub ActionsGitHub
Azure DevOps PipelinesMicrosoft Azure
JenkinsOpen Source
GitLab CI/CDGitLab
AWS CodePipelineAWS
Google Cloud BuildGoogle Cloud

9. GitHub Actions

GitHub Actions is GitHub's built-in CI/CD platform.

Workflow

Git Push
GitHub Actions
Run Tests
Build Docker Image
Deploy

10. GitHub Actions Workflow File

Create

.github/workflows/python.yml

Example

name: Python CI

on

push

branches

- main

jobs

build

runs-on: ubuntu-latest

steps

- uses: actions/checkout@v4

- uses: actions/setup-python@v5

with

  • python-version: "3.11"
  • - run: pip install -r requirements.txt
  • - run: pytest

Whenever code is pushed to the main branch

  • Code is checked out.
  • Python is installed.
  • Dependencies are installed.
  • Tests are executed.

11. Build Stage

Typical tasks

  • Install dependencies.
  • Compile code (if needed).
  • Validate syntax.
  • Build Docker image.

Example

docker build -t ml-api .

12. Testing Stage

Tests ensure code quality.

Common tests

  • Unit Tests
  • Integration Tests
  • API Tests
  • Model Validation

Example

pytest

13. Packaging Stage

Package the application.

Example

Application
Docker Image
Container Registry

The image is pushed to

  • Docker Hub
  • Azure Container Registry
  • Amazon ECR
  • Google Artifact Registry

14. Deployment Stage

Deploy the Docker image.

Example

Docker Image
Kubernetes
Production

15. CI/CD for Machine Learning

Machine Learning pipelines often include additional stages.

Code
Data Validation
Model Training
Model Evaluation
Register Model
Deploy
Monitor

Unlike traditional software, ML pipelines may retrain models before deployment.

16. CI/CD + MLflow

Git Push
Training
MLflow
Model Registry
Deployment

MLflow tracks

  • Parameters
  • Metrics
  • Artifacts
  • Models
  • Only approved models move to deployment.

17. CI/CD + Docker

Git Push
Build Docker Image
Push to Registry
Deploy

This ensures the same container is tested and deployed.

18. CI/CD + Kubernetes

Git Push
Docker Image
Kubernetes
Rolling Update
Production

Kubernetes updates applications with minimal downtime.

19. Azure DevOps

Azure DevOps provides

  • Git repositories
  • Boards
  • Pipelines
  • Test Plans
  • Artifacts

Typical workflow

Azure Repo
Azure Pipeline
Azure ML
AKS
Production

20. Jenkins

Jenkins is an open-source automation server.

Workflow

GitHub
Jenkins
Build
Test
Deploy

Jenkins supports thousands of plugins.

21. AWS CodePipeline

AWS CodePipeline automates

GitHub
Build
Test
SageMaker
Deploy

22. Google Cloud Build

Google Cloud Build integrates with Vertex AI.

GitHub
Cloud Build
Vertex AI
Deployment

23. Complete MLOps Pipeline

Developer
GitHub
CI Pipeline
Run Tests
Train Model
MLflow
Docker
Kubernetes
Production
Monitoring

24. Real-World Example

Suppose a bank updates its fraud detection model.

Pipeline

Developer
Git Push
Tests
Train Model
Register Model
Deploy Endpoint
Monitor Performance

If tests fail,

deployment stops automatically.

25. Advantages

  • Faster deployments.
  • Fewer human errors.
  • Consistent releases.
  • Better collaboration.
  • Automatic testing.
  • Reliable deployments.
  • Easier rollback.

26. Limitations

  • Initial setup takes time.
  • Pipeline maintenance is required.
  • Poorly designed tests reduce effectiveness.

Training large ML models can make pipelines slow if not optimized.

27. Best Practices

  • Commit small changes frequently.
  • Run automated tests.
  • Build Docker images automatically.
  • Version models.
  • Use infrastructure as code.
  • Monitor production deployments.
  • Keep secrets in secure vaults (never in source code).

28. Common Mistakes

  • Deploying without testing.
  • Ignoring failed builds.
  • Hardcoding passwords or API keys.
  • Building huge Docker images unnecessarily.
  • Skipping model validation before deployment.

29. Interview Questions

Beginner

  • What is CI/CD?
  • What is Continuous Integration?
  • What is Continuous Deployment?
  • What is GitHub Actions?
  • Why do we automate deployments?

Intermediate

  • Explain a CI/CD pipeline.
  • GitHub Actions vs Jenkins?
  • What happens after a Git push?
  • How do Docker and Kubernetes fit into CI/CD?
  • How do you automate testing?

Advanced

  • Design a CI/CD pipeline for a Machine Learning project.
  • How would you integrate MLflow into CI/CD?
  • How would you automate model deployment?
  • How would you roll back a failed deployment?
  • How would you build an enterprise MLOps pipeline?

30. Mini Project

  • End-to-End CI/CD Pipeline for a House Price Prediction API
  • Project Structure
  • HousePriceAPI/
  • ├── app.py
  • ├── model.pkl
  • ├── Dockerfile
  • ├── requirements.txt
  • ├── tests/

└── .github/

  • └── workflows/
  • └── python.yml
  • Pipeline Tasks
  • Push code to GitHub.
  • Run unit tests.
  • Build a Docker image.
  • Push the image to a container registry.
  • Deploy to Kubernetes.
  • Run health checks.
  • Notify the team on success or failure.

31. Complete Enterprise CI/CD Architecture

Developer

GitHub Repository

GitHub Actions

Run Tests

Train ML Model

MLflow Registry

Docker Build

Container Registry

Kubernetes

Production

Monitoring

32. CI/CD Workflow Cheat Sheet

Write Code

Git Commit

Git Push

CI Pipeline

Build

Test

Package

Deploy

Monitor

Chapter Summary

CI/CD (Continuous Integration and Continuous Delivery/Deployment) automates the software and machine learning delivery process. It ensures that every code change is automatically built, tested, packaged, and deployed, reducing manual effort and improving software quality. In MLOps, CI/CD extends beyond application code to include model training, validation, experiment tracking, containerization, deployment, and monitoring, making it an essential practice for production AI systems.

Learning Progress

  • Git & GitHub

  • Docker

  • Kubernetes

  • MLflow

  • DVC

  • FastAPI

  • Flask

  • Streamlit

  • Azure Machine Learning

  • AWS SageMaker

  • Google Vertex AI

  • CI/CD

At this stage, you have covered the complete workflow from writing code to deploying AI applications automatically. You now understand:

  • Version control with Git
  • Containerization using Docker
  • Orchestration with Kubernetes
  • Experiment tracking with MLflow
  • Data versioning using DVC
  • API development using FastAPI and Flask
  • Interactive dashboards with Streamlit
  • Cloud ML platforms (Azure ML, SageMaker, Vertex AI)
  • Automated software and ML delivery using CI/CD
  • What's Next?

In Chapter 10.13 – Model Monitoring, you'll learn how to monitor machine learning models after deployment by tracking prediction latency, accuracy, resource utilization, failures, and data quality. You'll also explore how to detect performance degradation and trigger alerts or retraining, which is critical for maintaining reliable AI systems in production.

Module 10 · Lesson 10.13

Model Monitoring

Chapter 10.13 – Model Monitoring

  • Deploying a Machine Learning model is not the end of the project—it is the beginning of production operations.

A model that performs well today may perform poorly tomorrow because data changes, user behavior changes, or system performance degrades.

Model Monitoring continuously observes deployed models to ensure they remain accurate, reliable, and efficient.

Learning Objectives

By the end of this chapter, you will be able to

  • Understand Model Monitoring.
  • Learn why monitoring is important.
  • Monitor prediction quality.
  • Monitor system performance.
  • Detect model degradation.
  • Understand alerts and dashboards.
  • Learn monitoring architecture.
  • Integrate monitoring with MLOps.
  • Prepare for Model Monitoring interview questions.

1. Introduction

Imagine you build a Loan Approval Model.

During testing

  • Accuracy
  • 97%
  • After deployment,
  • everything works well.
  • Six months later,
  • customers complain.

The model now performs

  • Accuracy
  • 81%
  • What happened?

Possible reasons

  • Customer behavior changed.
  • Economic conditions changed.
  • New types of applicants appeared.
  • Input data quality declined.
  • Without monitoring,

you may not notice the problem until users report it.

2. What is Model Monitoring?

Definition

Model Monitoring is the continuous process of observing the health, performance, quality, and behavior of machine learning models after deployment.

Monitoring helps answer questions such as

  • Is the model responding quickly?
  • Are predictions still accurate?
  • Has input data changed?
  • Is the system available?
  • Should the model be retrained?

3. Why Model Monitoring?

Training accuracy

98%

Production accuracy

82%

Without monitoring

  • The issue may remain hidden.

With monitoring

✅ Teams receive alerts and can investigate or retrain the model.

4. Monitoring Architecture

Users
Prediction Endpoint
Machine Learning Model
Logs
Monitoring System
Dashboard
Alerts

5. What Should Be Monitored?

A production ML system should monitor

  • Prediction latency
  • Throughput
  • Error rate
  • Resource usage
  • Data quality
  • Model quality
  • Data drift
  • Concept drift
  • Business metrics

6. Prediction Latency

Latency measures how long the model takes to respond.

Example

Request
100 milliseconds
Prediction

Low latency is important for

  • Chatbots
  • Fraud detection
  • Recommendation systems
  • Search

7. Throughput

Throughput measures how many requests the system handles.

Example

500 Requests

Per Second

High throughput is essential for large-scale applications.

8. Error Rate

Monitor failed requests.

Example

Total Requests

1000
Errors

5

Error Rate

0.5%

A sudden increase may indicate deployment issues.

9. CPU and Memory Usage

Monitor infrastructure resources.

Example

  • CPU
  • 65%
  • Memory
  • 72%

High resource usage can increase response times or cause failures.

10. Prediction Distribution

Track how predictions are distributed over time.

Example

  • Approved Loans
  • 85%
  • Rejected Loans
  • 15%
  • If the distribution changes dramatically,

the model or input data may require investigation.

11. Data Quality Monitoring

Check for problems such as

  • Missing values
  • Invalid values
  • Duplicate records
  • Unexpected formats
  • Out-of-range values

Example

  • Age
  • Expected
  • 18–80
  • Received
  • -25
  • This indicates invalid input data.

12. Model Quality Monitoring

If actual outcomes become available,

compare predictions with reality.

Example

Prediction

Approved
Actual

Rejected

Metrics include

  • Accuracy
  • Precision
  • Recall
  • F1 Score
  • RMSE (Regression)

13. Drift Monitoring

There are two major types of drift.

Data Drift
Concept Drift

These are covered in detail in the next chapter.

14. Business Metrics

Technical metrics alone are not enough.

Business metrics include

  • Revenue
  • Customer satisfaction
  • Conversion rate
  • Fraud losses
  • Loan defaults

Sometimes technical metrics remain stable while business outcomes decline.

15. Logging Predictions

Example log

TimeInputPredictionLatency
10:01Loan DataApproved95 ms
10:02Loan DataRejected110 ms

Logs help diagnose production issues.

16. Dashboards

Monitoring dashboards visualize system health.

Typical dashboard

Accuracy

96%

──────────────

Latency

105 ms

──────────────

Requests

1200/min

──────────────

Error Rate

0.3%

Popular dashboard tools

  • Grafana
  • Azure Monitor
  • Amazon CloudWatch
  • Google Cloud Monitoring

17. Alerts

Alerts notify engineers when thresholds are exceeded.

Example

Latency > 500 ms
Send Email
Send Slack Message
Open Incident

Other alert conditions

  • High error rate
  • CPU usage > 90%
  • Data drift detected
  • Endpoint unavailable

18. Monitoring Workflow

Prediction
Logging
Dashboard
Alert
Investigation
Retraining (if needed)

19. Model Monitoring in MLOps

Train Model
Deploy
Monitor
Detect Problem
Retrain
Redeploy

Monitoring creates a continuous feedback loop.

20. Monitoring Tools

ToolPurpose
Azure MonitorAzure monitoring
Amazon CloudWatchAWS monitoring
Google Cloud MonitoringGoogle Cloud monitoring
PrometheusMetrics collection
GrafanaDashboards
MLflowExperiment tracking (not production monitoring)

21. Real-World Example

Suppose a fraud detection model is deployed.

Monitoring dashboard shows

Latency

80 ms
500 ms

At the same time

CPU

40%
95%

Investigation finds a sudden traffic spike.

Solution

  • Scale additional containers.
  • Optimize the model.
  • Increase infrastructure capacity.

22. Healthcare Example

Disease prediction model

Training Accuracy

98%

Production Accuracy

84%

Monitoring identifies

New disease patterns.

Outdated training data.

The model is retrained with recent data.

23. End-to-End Monitoring Architecture

Users
FastAPI Endpoint
ML Model
Prediction Logs
Prometheus
Grafana
Alerts
MLOps Team

24. Advantages

  • Detects performance degradation.
  • Improves reliability.
  • Reduces downtime.
  • Identifies data quality issues.
  • Supports proactive maintenance.
  • Helps maintain business performance.

25. Limitations

  • Monitoring infrastructure adds operational cost.
  • Some quality metrics require delayed ground-truth labels.
  • Thresholds must be tuned carefully.
  • Large-scale logging requires storage and governance.

26. Best Practices

  • Monitor both technical and business metrics.
  • Create dashboards for different audiences.
  • Configure meaningful alerts.
  • Store prediction logs securely.
  • Review trends regularly.
  • Monitor data quality continuously.
  • Combine monitoring with automated retraining workflows.

27. Common Mistakes

  • Monitoring only CPU usage.
  • Ignoring business metrics.
  • No alerting mechanism.
  • Never reviewing monitoring dashboards.
  • Assuming training accuracy guarantees production performance.

28. Interview Questions

Beginner

  • What is Model Monitoring?
  • Why is monitoring important?
  • What is prediction latency?
  • What is throughput?
  • What is error rate?

Intermediate

  • What metrics should be monitored?
  • What are business metrics?
  • How would you monitor an ML model?
  • What tools are commonly used?
  • Why is monitoring necessary after deployment?

Advanced

  • Design a monitoring architecture for an ML API.
  • How would you detect model degradation?
  • How would you monitor a fraud detection model?
  • How would you create production alerts?
  • Explain the role of monitoring in an MLOps pipeline.

29. Mini Project

Monitoring a House Price Prediction API

Architecture

Users
FastAPI
House Price Model
Prediction Logs
Prometheus
Grafana
Email Alerts
  • Tasks
  • Deploy the prediction API.
  • Record every prediction request.
  • Measure latency and throughput.
  • Create Grafana dashboards.

Configure alerts for high latency and error rates.

Analyze production metrics weekly.

30. Complete Monitoring Workflow

Prediction Request

Model Response

Logging

Metrics Collection

Dashboard

Alert

Investigation

Retraining (if required)

Chapter Summary

Model Monitoring is the continuous observation of machine learning models after deployment. It ensures that models remain accurate, reliable, scalable, and responsive by tracking technical metrics (such as latency, throughput, and resource utilization), data quality, prediction quality, and business outcomes. Effective monitoring enables organizations to detect issues early, respond quickly, and maintain production-grade AI systems.

Learning Progress

  • Git & GitHub

  • Docker

  • Kubernetes

  • MLflow

  • DVC

  • FastAPI

  • Flask

  • Streamlit

  • Azure Machine Learning

  • AWS SageMaker

  • Google Vertex AI

  • CI/CD

  • Model Monitoring

You have now learned how to deploy and operate machine learning systems in production. Monitoring closes the loop between deployment and continuous improvement.

What's Next?

In Chapter 10.14 – Data Drift, you'll learn one of the most important causes of model degradation. You'll explore data drift, concept drift, target drift, methods to detect them statistically, and strategies for retraining models when production data changes over time. This topic is fundamental to maintaining accurate AI systems in real-world environments.

Module 10 · Lesson 10.14

Data Drift

Chapter 10.14 – Data Drift

  • One of the biggest reasons Machine Learning models fail in production is Data Drift.

A model may achieve 98% accuracy during training, but after several months, its performance may fall significantly because the data seen in production no longer resembles the data used during training.

Detecting and handling Data Drift is one of the most important responsibilities in MLOps.

Learning Objectives

By the end of this chapter, you will be able to

  • Understand Data Drift.
  • Differentiate Data Drift, Concept Drift, and Target Drift.
  • Learn the causes of drift.
  • Detect drift using statistical methods.
  • Monitor drift in production.
  • Mitigate drift through retraining and feature engineering.
  • Integrate drift detection into MLOps pipelines.
  • Prepare for Data Drift interview questions.

1. Introduction

Suppose you trained a House Price Prediction Model using data from 2022.

The model achieved

Training Accuracy

97%

Now it's 2026.

House prices have changed due to

  • Inflation
  • Interest rates
  • New government policies
  • Population growth

The model now performs

  • Production Accuracy
  • 82%
  • The model wasn't necessarily built incorrectly.
  • The data changed.

This is called Data Drift.

2. What is Data Drift?

Definition

Data Drift occurs when the statistical distribution of input features changes between the training data and the production data.

In simple words

The model learned from one type of data,

but now receives different data.

3. Example of Data Drift

Training data

AgeIncome
25₹4,00,000
30₹5,00,000
35₹6,00,000

Average income

₹5,00,000

Production data

AgeIncome
25₹10,00,000
30₹12,00,000
35₹15,00,000

Average income

₹12,33,333

The income distribution has changed.

This is Data Drift.

4. Why Does Data Drift Occur?

Common causes include

  • Economic changes
  • Seasonal trends
  • Customer behavior changes
  • Market changes
  • Policy changes
  • Sensor changes
  • New products
  • Geographic expansion

Example

A food delivery app trained on weekday orders may see different patterns during holidays.

5. Types of Drift

Three common types

Production Changes
├── Data Drift

├── Concept Drift

└── Target Drift

6. Data Drift

Only the input features change.

Example

Training

Customer Age

20–40

Production

Customer Age

45–70

The relationship between features and labels may remain the same, but the input distribution changes.

7. Concept Drift

Definition

Concept Drift occurs when the relationship between input features and the target variable changes over time.

Example

Before COVID

Working from office
Low laptop purchases

During COVID

Work from home
High laptop purchases

Customer behavior changed.

The model's learned relationship is no longer valid.

8. Target Drift

Target Drift occurs when the distribution of the target variable changes.

Example

Fraud detection

Training

Fraud Cases

2%

Production

Fraud Cases

8%

The proportion of positive and negative labels has changed.

9. Visualizing Drift

Training distribution

Feature Value

*****

***********

***************

***********

*****

Production distribution

Feature Value

***********

********************

***************

*******

**

The shapes differ, indicating potential drift.

10. Why Drift Matters

Without drift

Training Data
Model
High Accuracy

With drift

New Data
Old Model
Lower Accuracy

Even a well-trained model can degrade when data changes.

11. Drift Detection

The general workflow

Training Data
Compare
Production Data
Statistical Test
Drift Score

12. Statistical Methods

Common methods include

  • Kolmogorov–Smirnov (KS) Test
  • Chi-Square Test
  • Population Stability Index (PSI)
  • Jensen-Shannon Distance
  • Wasserstein Distance

Each compares the training and production distributions in different ways.

13. Population Stability Index (PSI)

PSI is commonly used in banking and finance.

Typical interpretation

PSIInterpretation
< 0.10Little or no drift
0.10 – 0.25Moderate drift
> 0.25Significant drift

Example

PSI = 0.32

Significant Drift

14. Kolmogorov–Smirnov (KS) Test

The KS Test compares two continuous distributions.

Example

Training income distribution
Production income distribution
KS Test
Difference Score

A larger difference suggests stronger evidence that the distributions differ.

15. Monitoring Drift

Typical production workflow

Production Data
Compare
Training Data
Drift Detection
Dashboard
Alert

16. Drift Dashboard

Example

  • Feature Drift
  • Income
  • High

──────────────

Age

Low

──────────────

City

None

──────────────

Loan Amount

Medium

The dashboard helps identify which features have changed the most.

17. Drift Alerts

Example rules

PSI > 0.25
Alert Team

Or

KS Statistic

Above Threshold
Create Incident

Alerts enable proactive action.

18. Handling Data Drift

Common strategies

  • Collect new data.
  • Retrain the model.
  • Add new features.
  • Remove outdated features.
  • Adjust feature engineering.
  • Monitor continuously.

Retraining is often the most effective solution when drift is persistent.

19. Automated Retraining

Drift Detected
Trigger Pipeline
Train New Model
Evaluate
Deploy

This is common in mature MLOps systems.

20. Drift in Different Industries

  • Banking
  • Income changes.
  • Credit scores change.
  • Fraud patterns evolve.
  • Retail
  • Seasonal buying behavior.
  • Holiday sales.
  • New products.
  • Healthcare
  • New diseases.
  • New treatment protocols.
  • Population changes.
  • Agriculture
  • Rainfall.
  • Temperature.
  • Soil conditions.
  • Crop diseases.
  • Manufacturing
  • Sensor calibration changes.
  • Machine wear.
  • New equipment.

21. Real-World Example

Loan approval model

Training

Average Salary

₹6 Lakhs

Production

  • Average Salary
  • ₹10 Lakhs
  • The salary feature has drifted.
  • The monitoring system detects this,
  • and a retraining pipeline is started.

22. Data Drift in MLOps

Train Model
Deploy
Monitor Data
Detect Drift
Retrain
Redeploy

This continuous cycle keeps the model relevant.

23. Data Drift vs Concept Drift

Data DriftConcept Drift
Input feature distribution changesRelationship between features and target changes
Easier to detect using statisticsOften requires observing prediction performance and labeled outcomes
May not immediately reduce accuracyFrequently leads to declining accuracy
Example: Customer ages increaseExample: Customer purchasing behavior changes

24. Advantages of Drift Monitoring

  • Detects changing data patterns.
  • Improves model reliability.
  • Enables proactive retraining.
  • Maintains prediction quality.
  • Supports long-term production stability.

25. Limitations

  • Requires historical reference data.
  • Some drift metrics need careful threshold selection.
  • Not every detected drift requires retraining.

Label availability may be delayed, making concept drift harder to detect.

26. Best Practices

  • Monitor important features separately.
  • Store training data statistics.
  • Automate drift detection.
  • Create dashboards.
  • Set meaningful alert thresholds.
  • Retrain only after proper evaluation.
  • Track drift trends over time.

27. Common Mistakes

  • Ignoring production data.
  • Retraining after every small drift.
  • Monitoring only accuracy.
  • Using outdated reference datasets forever.
  • Ignoring business context.

28. Interview Questions

Beginner

  • What is Data Drift?
  • Why does Data Drift occur?
  • What is Concept Drift?
  • What is Target Drift?
  • Why is drift monitoring important?

Intermediate

  • How do you detect Data Drift?
  • What is Population Stability Index (PSI)?
  • What is the KS Test?
  • How do you monitor drift in production?
  • How would you respond to detected drift?

Advanced

  • Design a drift monitoring architecture.
  • How would you automate retraining?
  • How would you detect drift in a fraud detection model?
  • Explain Data Drift vs Concept Drift with examples.
  • How would you integrate drift detection into an MLOps pipeline?

29. Mini Project

Drift Detection for a Loan Approval Model

Architecture

Production Data
Compare with Training Data
PSI + KS Test
Dashboard
Alert
Retraining Pipeline
Updated Model
  • Tasks
  • Store baseline training statistics.
  • Collect production data daily.
  • Calculate PSI for important features.
  • Run KS Tests for continuous variables.
  • Display drift dashboards.
  • Send alerts when thresholds are exceeded.
  • Retrain and evaluate the model if necessary.

30. Complete Drift Detection Workflow

Training Data

Production Data

Statistical Comparison

Drift Detection

Dashboard

Alert

Retraining

Production

Chapter Summary

Data Drift occurs when the statistical properties of production input data differ from the data used to train the model. If left unmanaged, it can reduce prediction quality over time. Effective MLOps systems continuously compare production data with training data, detect meaningful drift using statistical techniques such as PSI and the KS Test, and trigger investigation or retraining when appropriate. Understanding the distinction between Data Drift, Concept Drift, and Target Drift is essential for maintaining reliable machine learning systems.

Learning Progress

  • Git & GitHub

  • Docker

  • Kubernetes

  • MLflow

  • DVC

  • FastAPI

  • Flask

  • Streamlit

  • Azure Machine Learning

  • AWS SageMaker

  • Google Vertex AI

  • CI/CD

  • Model Monitoring

  • Data Drift

You now understand one of the most important operational challenges in production AI systems: keeping models accurate as real-world data evolves.

What's Next?

In Chapter 10.15 – Feature Store, you'll learn how organizations manage, version, and share machine learning features across multiple teams and models. You'll explore online and offline feature stores, feature engineering workflows, feature reuse, consistency between training and serving, and enterprise Feature Store architectures used by companies such as Uber, Airbnb, Netflix, and Google.

Module 10 · Lesson 10.15

Feature Store

Chapter 10.15 – Feature Store

  • A Feature Store is a centralized repository for storing, managing, versioning, and serving Machine Learning features.

Instead of every Data Scientist creating the same features repeatedly, a Feature Store allows teams to build once, reuse many times, ensuring consistency between training and production.

Learning Objectives

By the end of this chapter, you will be able to

  • Understand what a Feature Store is.
  • Learn why Feature Stores are important.
  • Understand features and feature engineering.
  • Learn online and offline Feature Stores.
  • Understand feature versioning.
  • Prevent training-serving skew.
  • Integrate Feature Stores into MLOps pipelines.
  • Prepare for Feature Store interview questions.

1. Introduction

Suppose your company has three Machine Learning projects

  • Loan Approval
  • Credit Card Fraud Detection
  • Customer Churn Prediction

All three models use

  • Customer Age
  • Income
  • Credit Score
  • Account Balance

Without a Feature Store

Data Scientist A
Creates Age Feature

------------------

Data Scientist B
Creates Age Feature Again

------------------

Data Scientist C
Creates Age Feature Again

The same work is repeated multiple times.

A Feature Store solves this problem.

2. What is a Feature?

A feature is an input variable used by a Machine Learning model.

Example

Predict house prices.

AreaBedroomsAgePrice
150035₹75L

Features

  • Area
  • Bedrooms
  • House Age

Target

Price

3. What is Feature Engineering?

Feature Engineering is the process of creating useful input variables from raw data.

Raw Data

Date of Birth
Age

Raw Data

Transaction History
Average Monthly Spending

Raw Data

Login Time
Number of Logins per Week

Better features often lead to better model performance.

4. What is a Feature Store?

Definition

A Feature Store is a centralized platform that stores, manages, versions, and serves machine learning features for both model training and real-time inference.

It ensures the same feature definitions are used across the organization.

5. Why Do We Need a Feature Store?

Without Feature Store

Project A
Income Feature

------------------

Project B
Income Feature

(Different Calculation)

------------------

Project C
Income Feature

(Another Calculation)

This leads to inconsistent models.

With Feature Store

Central Feature Store
Shared Income Feature
All Models

6. Feature Store Architecture

Raw Data

Feature Engineering

Feature Store

┌─────────┴─────────┐

▼ ▼

Offline Store Online Store

│ │

▼ ▼

Model Training Real-Time Prediction

7. Offline Feature Store

The Offline Feature Store stores historical features.

Used for

  • Model training
  • Batch inference
  • Data analysis
  • Experimentation

Example

Historical Transactions
Offline Feature Store
Training Dataset

8. Online Feature Store

The Online Feature Store serves features with very low latency.

Used for

  • Real-time APIs
  • Fraud detection
  • Recommendations
  • Chatbots

Example

Customer Request
Online Feature Store
Prediction API

9. Offline vs Online Feature Store

Offline StoreOnline Store
Historical dataLatest features
Batch accessReal-time access
TrainingInference
High latency acceptableLow latency required
Large datasetsSmall, frequently accessed data

10. Feature Versioning

Features evolve over time.

Example

Version 1

Income

Version 2

Income

+

Bonus

Version 3

Income

+

Bonus

+

Investments

A Feature Store keeps track of these versions.

11. Training-Serving Skew

One of the biggest ML problems.

Training

Age = Current Year - Birth Year

Production

Age = Entered Manually

Different calculations produce different values.

This difference is called Training-Serving Skew.

12. Preventing Training-Serving Skew

Feature Store Solution

Single Feature Definition
Training
Production
Same Calculation

Both training and inference use the exact same feature logic.

13. Feature Pipeline

Raw Data
Cleaning
Feature Engineering
Feature Store
ML Model

Features are generated once and reused.

14. Feature Metadata

A Feature Store maintains metadata such as

  • Feature name
  • Data type
  • Owner
  • Description
  • Creation date
  • Version
  • Source table
  • Update frequency

Example

FieldValue
FeatureAverage Monthly Spend
TypeFloat
Version2
UpdatedDaily

15. Feature Freshness

Some features update frequently.

Examples

FeatureUpdate Frequency
AgeYearly
Account BalanceReal-time
Stock PriceEvery second
WeatherHourly

Freshness is important for accurate predictions.

16. Feature Lineage

Lineage tracks where a feature comes from.

Example

Transactions
SQL Query
Average Spend
Feature Store
Fraud Model

This improves transparency and debugging.

17. Feature Monitoring

Monitor

  • Missing values
  • Feature drift
  • Feature freshness
  • Data quality
  • Update failures

Example

  • Credit Score
  • Expected
  • 300–900
  • Received
1500
Alert

18. Feature Store Workflow

Raw Data
Feature Engineering
Feature Store
Training
Deployment
Prediction

19. Popular Feature Stores

Feature StorePlatform
FeastOpen Source
Vertex AI Feature StoreGoogle Cloud
Amazon SageMaker Feature StoreAWS
Databricks Feature StoreDatabricks
TectonCommercial

Azure Machine Learning integrates with feature management capabilities, although it does not currently provide a native Feature Store service equivalent to some other platforms.

20. Feature Store in MLOps

Raw Data
Feature Engineering
Feature Store
Training
MLflow
Model Registry
Deployment
Prediction

21. Real-World Example

Fraud Detection

Features

  • Average Transaction Amount
  • Transactions Last Hour
  • Country
  • Device Type
  • Login Frequency
  • Instead of recalculating them for every model,

the Feature Store provides them to

  • Fraud Detection
  • Risk Analysis
  • Credit Approval

22. Banking Example

Loan Approval
Feature Store
Income
Credit Score
Debt Ratio
Employment History

Multiple models reuse these standardized features.

23. E-Commerce Example

Recommendation System
Feature Store
Customer Age
Browsing History
Purchase Frequency
Cart Size

These features can also support churn prediction and marketing models.

24. Advantages

  • Eliminates duplicate feature engineering.
  • Improves consistency.
  • Prevents training-serving skew.
  • Supports feature reuse.
  • Simplifies collaboration.
  • Improves model quality.
  • Enables feature versioning.

25. Limitations

  • Additional infrastructure is required.
  • Governance and ownership are important.
  • Feature design still requires domain expertise.
  • Real-time synchronization can be complex.

26. Best Practices

  • Use consistent feature definitions.
  • Version important features.
  • Monitor feature freshness.
  • Document feature metadata.
  • Reuse existing features before creating new ones.
  • Monitor feature drift.
  • Automate feature pipelines.

27. Common Mistakes

  • Duplicating feature logic across teams.
  • Ignoring feature versioning.
  • Mixing training and production calculations.
  • Not documenting feature definitions.
  • Serving stale features.

28. Interview Questions

Beginner

  • What is a Feature?
  • What is a Feature Store?
  • Why is a Feature Store needed?
  • What is Feature Engineering?
  • What is Training-Serving Skew?

Intermediate

  • Difference between Online and Offline Feature Stores?
  • What is Feature Versioning?
  • What is Feature Lineage?
  • What is Feature Freshness?
  • How do Feature Stores improve collaboration?

Advanced

  • Design an enterprise Feature Store architecture.
  • How would you prevent Training-Serving Skew?
  • How would you monitor feature quality?
  • How would you integrate a Feature Store into an MLOps pipeline?
  • Compare Feast, SageMaker Feature Store, and Vertex AI Feature Store.

29. Mini Project

Feature Store for Customer Churn Prediction

Architecture

Customer Database
Feature Engineering
Feature Store

├─────────────┐

│ │

▼ ▼

Offline Store Online Store

│ │

▼ ▼

Training Real-Time API

  • Features
  • Customer Age
  • Monthly Spending
  • Average Session Time
  • Number of Purchases
  • Customer Lifetime Value
  • Tasks
  • Create reusable features.
  • Store feature metadata.
  • Version features.
  • Train a churn model using the Offline Store.
  • Serve real-time predictions using the Online Store.
  • Monitor feature freshness and drift.

30. Enterprise Feature Store Architecture

Raw Data Sources

ETL / Data Engineering

Feature Engineering

Feature Store

┌───────────────┐

│ │

▼ ▼

Offline Store Online Store

│ │

▼ ▼

Model Training Real-Time Inference

MLflow

Model Registry

Deployment

Chapter Summary

A Feature Store is a centralized system for storing, managing, versioning, and serving machine learning features. It enables organizations to reuse features across projects, maintain consistency between training and inference, reduce duplicated work, and improve collaboration among teams. Modern MLOps platforms use Feature Stores to ensure reliable, scalable, and reproducible machine learning systems.

Learning Progress

  • Git & GitHub

  • Docker

  • Kubernetes

  • MLflow

  • DVC

  • FastAPI

  • Flask

  • Streamlit

  • Azure Machine Learning

  • AWS SageMaker

  • Google Vertex AI

  • CI/CD

  • Model Monitoring

  • Data Drift

  • Feature Store

You now understand how enterprise organizations standardize feature engineering, eliminate duplicate work, and ensure that the same feature definitions are used consistently for both model training and production inference.

What's Next?

In Chapter 10.16 – Deployment Strategies, you'll learn how to safely deploy new machine learning models into production using techniques such as Blue-Green Deployment, Canary Deployment, Rolling Updates, Shadow Deployment, and A/B Testing. These strategies help minimize downtime, reduce deployment risk, and validate new models before exposing them to all users.

Module 10 · Lesson 10.16

Deployment Strategies

Chapter 10.16 – Deployment Strategies

  • Training a Machine Learning model is only half the job. Deploying it safely is equally important.

A new model may have higher accuracy during testing, but if it contains hidden bugs or behaves unexpectedly in production, it can impact thousands or even millions of users.

Deployment Strategies help organizations release new models safely while minimizing downtime and business risk.

Learning Objectives

By the end of this chapter, you will be able to

  • Understand deployment strategies.
  • Learn Blue-Green Deployment.
  • Learn Rolling Deployment.
  • Learn Canary Deployment.
  • Learn Shadow Deployment.
  • Learn A/B Testing.
  • Understand rollback strategies.
  • Deploy ML models safely.
  • Integrate deployment strategies into MLOps.
  • Prepare for deployment interview questions.

1. Introduction

Suppose your bank has deployed a Loan Approval Model (Version 1).

Current performance

  • Accuracy
  • 94%
  • You develop a new model.

New performance

Accuracy

97%

Question

  • Should you immediately replace the old model?
  • No.
  • If the new model has hidden issues,
  • millions of loan decisions could be affected.
  • Instead, use a deployment strategy.

2. What is a Deployment Strategy?

Definition

A Deployment Strategy is a controlled approach for releasing a new version of an application or Machine Learning model into production while minimizing downtime and reducing deployment risk.

Deployment strategies determine

  • Who receives the new model.
  • When they receive it.
  • How failures are handled.
  • How rollbacks occur.

3. Why Deployment Strategies?

Without strategy

Old Model
Replace Immediately
Production Failure

With strategy

Old Model
Deploy Carefully
Monitor
Expand Deployment

Risk is significantly reduced.

4. Deployment Workflow

Train Model
Testing
Deployment Strategy
Monitoring
Production

Monitoring remains essential after deployment.

5. Blue-Green Deployment

Blue-Green Deployment uses two identical production environments.

Blue Environment
Current Production

──────────────

Green Environment
New Version

Initially

Users access

Users
Blue

After validation

Users
Green

The switch is almost instantaneous.

6. Blue-Green Rollback

Suppose Green fails.

Rollback

Users
Blue

Rollback is quick because the previous environment is still running.

7. Advantages of Blue-Green Deployment

  • Near-zero downtime.
  • Fast rollback.
  • Easy testing.
  • Low deployment risk.

8. Limitations

  • Requires duplicate infrastructure.
  • Higher cloud costs.
  • Database migrations require careful planning.

9. Rolling Deployment

Instead of replacing every server,

replace them gradually.

Example

Server 1

Version 2

──────────

Server 2

Version 1

──────────

Server 3

Version 1

Then

Server 2
Version 2

Finally

All Servers
Version 2

10. Rolling Update Workflow

Old Servers
Update One
Monitor
Update Next
Monitor
Complete

This approach is commonly used in Kubernetes.

11. Advantages

  • No downtime.
  • Lower infrastructure cost.
  • Gradual rollout.

12. Limitations

  • Multiple versions run simultaneously.
  • Rollback can take longer than Blue-Green.
  • Compatibility between versions is important.

13. Canary Deployment

Deploy to a small percentage of users first.

Example

100 Users
5 Users
New Model
95 Users
Old Model

If everything works well

20%
50%
100%

14. Canary Workflow

Version 1
5% Users
Monitor
25%
Monitor
100%

15. Advantages

  • Very low deployment risk.
  • Real production testing.
  • Easy to detect issues early.

16. Limitations

  • Requires traffic routing.
  • More operational complexity.
  • Monitoring must be accurate.

17. Shadow Deployment

Shadow Deployment sends production traffic to both models.

User Request
Version 1
Prediction Used

────────────

Version 2
Prediction Logged
  • (Not Used)
  • Users only receive responses from Version 1.
  • Version 2 is evaluated silently.

18. Advantages

  • Safe evaluation.
  • No customer impact.
  • Uses real production traffic.

19. Limitations

  • Double infrastructure cost.
  • Higher resource usage.
  • Additional logging required.

20. A/B Testing

  • Two models actively serve different user groups.
  • Users
  • ├── Group A

Model A

────────────

Users

├── Group B

Model B

Compare

  • Accuracy
  • Revenue
  • Click-through rate
  • Conversion rate
  • User engagement

21. Example: Recommendation System

Model A

Revenue

₹20 Lakhs

Model B

Revenue

₹24 Lakhs

Model B becomes the preferred production model.

22. Deployment Strategy Comparison

StrategyDowntimeRollbackCostRisk
Blue-GreenNear zeroExcellentHighLow
RollingNoneModerateMediumMedium
CanaryNoneGoodMediumVery Low
ShadowNoneExcellentHighVery Low
A/B TestingNoneGoodMediumLow

23. Rollback Strategy

Every deployment should have a rollback plan.

Deploy
Monitor
Issue Detected
Rollback
Previous Version

A fast rollback minimizes business impact.

24. Monitoring After Deployment

After deployment monitor

  • Accuracy
  • Latency
  • Error rate
  • CPU usage
  • Memory usage
  • Data drift
  • Business KPIs
  • Deployment without monitoring is risky.

25. Deployment in Kubernetes

Typical workflow

Docker Image
Kubernetes
Rolling Update
Pods Updated
Production

Kubernetes supports rolling updates natively and can also be configured for Blue-Green or Canary deployments using additional tooling.

26. Deployment in MLOps

Train Model
MLflow
Model Registry
Deployment Strategy
Monitoring
Production

Only validated models should be promoted to production.

27. Real-World Example

Suppose Netflix develops a better recommendation model.

Instead of sending it to all users

1%

Monitor
10%
Monitor
50%
Monitor
100%

This is a classic Canary Deployment.

28. Banking Example

Loan Approval Model
Shadow Deployment
Compare Predictions
No Customer Impact
Deploy

Banks often validate new models thoroughly before making decisions that affect customers.

29. Advantages

  • Reduced deployment risk.
  • Easier rollback.
  • Better customer experience.
  • Continuous improvement.
  • Safer production releases.

30. Limitations

  • More infrastructure.
  • More monitoring.
  • Increased operational complexity.
  • Requires automation.

31. Best Practices

  • Always test before deployment.
  • Use automated CI/CD.
  • Monitor production continuously.
  • Keep previous model versions.
  • Automate rollback when possible.
  • Validate business metrics—not just technical metrics.

32. Common Mistakes

  • Deploying directly to 100% of users.
  • No rollback plan.
  • Ignoring monitoring.
  • Deploying untested models.
  • Deleting previous model versions.

33. Interview Questions

Beginner

  • What is a deployment strategy?
  • What is Blue-Green Deployment?
  • What is Rolling Deployment?
  • What is Canary Deployment?
  • What is Shadow Deployment?

Intermediate

  • Difference between Canary and Blue-Green?
  • What is A/B Testing?
  • Why is monitoring required after deployment?
  • What is rollback?
  • Which deployment strategy is safest?

Advanced

  • Design a deployment strategy for a fraud detection system.
  • Blue-Green vs Rolling Deployment?
  • How would you deploy an ML model with Kubernetes?
  • How would you perform A/B testing for recommendations?
  • Explain deployment strategies in an enterprise MLOps pipeline.

34. Mini Project

Safe Deployment of a House Price Prediction Model

Architecture

New Model
MLflow Registry
Canary Deployment
10% Traffic
Monitoring
100% Production
  • Tasks
  • Register Version 2 of the model.
  • Deploy to 10% of users.
  • Measure latency and accuracy.
  • Compare with Version 1.
  • Increase traffic gradually.

Roll back automatically if error rates exceed thresholds.

35. Enterprise Deployment Architecture

GitHub

CI/CD Pipeline

MLflow Registry

Deployment Strategy

Kubernetes

Production

Monitoring

Rollback (if needed)

36. Deployment Strategy Cheat Sheet

StrategyBest Used When
Blue-GreenCritical systems requiring instant rollback
RollingKubernetes-based applications
CanaryGradually validating a new model with real users
ShadowComparing new models without affecting users
A/B TestingMeasuring business impact of different models

Chapter Summary

Deployment Strategies provide controlled methods for releasing new machine learning models into production while minimizing downtime and risk. Common approaches include Blue-Green, Rolling, Canary, Shadow, and A/B Testing, each suited to different operational needs. Combined with CI/CD, Model Monitoring, MLflow, and Kubernetes, these strategies enable organizations to deploy AI systems safely, monitor their performance, and roll back quickly if issues arise.

Learning Progress

  • Git & GitHub

  • Docker

  • Kubernetes

  • MLflow

  • DVC

  • FastAPI

  • Flask

  • Streamlit

  • Azure Machine Learning

  • AWS SageMaker

  • Google Vertex AI

  • CI/CD

  • Model Monitoring

  • Data Drift

  • Feature Store

  • Deployment Strategies

You now understand how enterprise organizations safely release new machine learning models while minimizing risk and ensuring continuous service availability.

What's Next?

In Chapter 10.17 – REST APIs, you'll learn the foundation of communication between modern applications. You'll understand HTTP methods, request/response structure, JSON, authentication, status codes, API design principles, and how FastAPI and Flask expose machine learning models as RESTful services. This knowledge is essential before deploying production-grade AI applications.

Module 10 · Lesson 10.17

REST APIs

Chapter 10.17 – REST APIs

  • REST APIs are the standard way modern applications communicate over the internet.

Almost every Machine Learning model deployed in production is exposed as a REST API, allowing web applications, mobile apps, enterprise software, and IoT devices to request predictions.

Learning Objectives

By the end of this chapter, you will be able to

  • Understand REST APIs.
  • Learn HTTP fundamentals.
  • Understand API requests and responses.
  • Learn HTTP methods.
  • Understand JSON.
  • Learn HTTP status codes.
  • Design RESTful APIs.
  • Secure APIs.
  • Build ML prediction APIs.
  • Prepare for REST API interview questions.

1. Introduction

Suppose you trained a House Price Prediction Model.

Now multiple applications need to use it

  • Mobile App
  • Website
  • Banking Portal
  • Power BI Dashboard
  • Chatbot
  • How can they communicate with the model?

The answer is

REST API

2. What is an API?

Definition

An API (Application Programming Interface) is a set of rules that allows one software application to communicate with another.

Example

Mobile App
API
Machine Learning Model
Prediction

The API acts as a messenger between applications.

3. What is REST?

REST stands for

Representational State Transfer

It is an architectural style for designing web services using the HTTP protocol.

A REST API allows clients to

  • Send requests.
  • Receive responses.
  • Exchange data (usually JSON).

4. Why REST APIs?

Without REST API

Website
Cannot Directly Access

Python Model

With REST API

Website
REST API
Python Model
Prediction

The model becomes accessible to any application that can make HTTP requests.

5. REST API Architecture

Client
HTTP Request
REST API
Business Logic
Machine Learning Model
HTTP Response

6. Client and Server

Client

Requests information.

Examples

  • Browser
  • Mobile App
  • Power BI
  • React Application
  • Server
  • Processes requests and returns responses.

Examples

  • FastAPI
  • Flask
  • Django

7. HTTP

REST APIs use the HTTP (HyperText Transfer Protocol).

Every request contains

Client
HTTP Request
Server
HTTP Response

8. HTTP Methods

MethodPurposeExample
GETRetrieve dataGet customer details
POSTCreate or process dataPredict house price
PUTReplace an existing resourceUpdate customer profile
PATCHPartially update a resourceUpdate only email address
DELETEDelete dataDelete customer

9. GET Request

Example

GET /customers/10

Response

{

"id":10,

"name":"Hari"

}

GET requests should not modify server data.

10. POST Request

POST is commonly used for ML predictions.

Request

POST /predict

Body

{

"area":1500,

"bedrooms":3

}

Response

{

"predicted_price":7500000

}

11. PUT Request

Replace an entire resource.

Example

PUT /customer/10

{

"name":"Hari",

"city":"Hyderabad"

}

The server updates the complete customer record.

12. PATCH Request

Update only selected fields.

Example

PATCH /customer/10

{

"city":"Bangalore"

}

Only the city changes.

13. DELETE Request

Example

DELETE /customer/10

Response

{

"message":"Deleted Successfully"

}

14. Request Structure

Every HTTP request contains

  • URL
  • Headers
  • Body
  • Method

Example

POST /predict

Content-Type: application/json

Body

{

"age":30

}

15. Response Structure

A server responds with

  • Status Code
  • Headers
  • Body

Example

{

"prediction":"Approved"

}

16. JSON

JSON stands for

JavaScript Object Notation

It is the most common data format used by REST APIs.

Example

{

  • "name":"Hari",
  • "salary":600000,
  • "city":"Hyderabad"

}

JSON is

  • Lightweight
  • Human-readable
  • Language-independent

17. HTTP Status Codes

CodeMeaning
200Success
201Created
204No Content
400Bad Request
401Unauthorized
403Forbidden
404Not Found
409Conflict
422Validation Error
500Internal Server Error

Example

200 OK

means the request succeeded.

18. REST API Example (FastAPI)

from fastapi import FastAPI
app = FastAPI()

@app.get("/")

def home():
return {"message":"Hello"}

Run

uvicorn app:app --reload

Open

http://localhost:8000

19. REST API Example (Flask)

from flask import Flask
app = Flask(__name__)

@app.route("/")

def home():
return "Hello"

Run

python app.py

20. Machine Learning Prediction API

Example

@app.post("/predict")

def predict(data):
    prediction = model.predict(data)
    return {
        "prediction":prediction
    }

Request

{

"income":600000,

"age":35

}

Response

{

"loan":"Approved"

}

21. API Authentication

Not everyone should access your API.

Common authentication methods

  • API Keys
  • JWT Tokens
  • OAuth 2.0
  • Microsoft Entra ID
  • AWS IAM
  • Google Cloud IAM

Example

Client
Token
REST API
Authorized

22. API Versioning

As APIs evolve, changes should not break existing clients.

Example

/api/v1/predict

/api/v2/predict

Versioning allows multiple API versions to coexist.

23. REST API Best Practices

Use nouns rather than verbs in URLs.

Good

  • /customers
  • /orders
  • /products

Avoid

  • /getCustomers
  • /deleteCustomer
  • /createOrder
  • Use HTTP methods to express actions.

24. REST APIs in MLOps

User
REST API
FastAPI
ML Model
Prediction
JSON Response

This is the most common architecture for serving ML models.

25. REST API + Kubernetes

Users
Load Balancer
REST API Pods
Machine Learning Model

Multiple API instances improve scalability and availability.

26. REST API + CI/CD

GitHub
CI/CD Pipeline
Docker
REST API
Production

Code changes are automatically tested and deployed.

27. REST API Security

Always

  • Use HTTPS.
  • Authenticate users.
  • Validate input.
  • Limit request rates.
  • Log requests.
  • Protect secrets.

Avoid exposing sensitive information in responses.

28. REST vs GraphQL

RESTGraphQL
Multiple endpointsSingle endpoint
Simple to implementMore flexible queries
Standard HTTP methodsClient specifies requested fields
Widely used for ML APIsOften used for complex frontend applications

REST remains the most common approach for serving ML inference APIs.

29. Real-World Example

Banking

Loan Approval API

Mobile App
REST API
Loan Model
Decision

Healthcare

Disease Prediction API

Hospital System
REST API
Diagnosis Model
Prediction

Agriculture

Crop Disease API

Farmer Mobile App
REST API
Image Model
Disease Prediction

30. Advantages

  • Platform independent.
  • Easy integration.
  • Standardized communication.
  • Scalable.
  • Supports JSON.
  • Works across cloud providers.

31. Limitations

  • Stateless design means clients must send necessary context with each request.
  • Large responses can increase network usage.
  • REST may require multiple requests for related resources.
  • API versioning must be managed carefully.

32. Common Mistakes

  • Using GET for operations that change data.
  • Returning incorrect HTTP status codes.
  • Not validating input.
  • Exposing internal errors to users.
  • Forgetting authentication.

33. Best Practices

  • Use meaningful endpoint names.
  • Return proper HTTP status codes.
  • Validate request data.
  • Document APIs using OpenAPI/Swagger.
  • Version your APIs.
  • Secure APIs using authentication and HTTPS.
  • Log requests for monitoring and debugging.

34. Interview Questions

Beginner

  • What is an API?
  • What is REST?
  • What is JSON?
  • Difference between GET and POST?
  • What is HTTP?

Intermediate

  • What are HTTP status codes?
  • What is API authentication?
  • What is API versioning?
  • Why is POST commonly used for ML prediction?
  • REST vs GraphQL?

Advanced

  • Design a REST API for a fraud detection model.
  • How would you secure a production REST API?
  • How would you deploy REST APIs using Kubernetes?
  • Explain REST APIs in an MLOps architecture.
  • How would you handle millions of prediction requests?

35. Mini Project

House Price Prediction REST API

Endpoints

GET /health

POST /predict

GET /model-info

GET /metrics

Workflow

User
REST API
FastAPI
House Price Model
Prediction
JSON Response
  • Tasks
  • Build a prediction API.
  • Validate user input.
  • Return JSON responses.
  • Add Swagger documentation.
  • Containerize using Docker.
  • Deploy to Kubernetes.
  • Monitor latency and error rates.

36. Complete REST API Architecture

User

HTTPS Request

Load Balancer

REST API (FastAPI)

┌─────────┴─────────┐

▼ ▼

Authentication Logging

│ │

└─────────┬─────────┘

Machine Learning Model

JSON Response

Client

Chapter Summary

REST APIs are the standard mechanism for exposing machine learning models to external applications. They use HTTP methods, JSON payloads, and well-defined endpoints to enable secure, scalable, and platform-independent communication. Combined with FastAPI, Docker, Kubernetes, and CI/CD, REST APIs form the foundation of modern production AI systems.

Learning Progress

  • Git & GitHub

  • Docker

  • Kubernetes

  • MLflow

  • DVC

  • FastAPI

  • Flask

  • Streamlit

  • Azure Machine Learning

  • AWS SageMaker

  • Google Vertex AI

  • CI/CD

  • Model Monitoring

  • Data Drift

  • Feature Store

  • Deployment Strategies

  • REST APIs

You now understand how applications communicate with machine learning models in production using standardized web APIs.

What's Next?

In Chapter 10.18 – Kubernetes Deployment, you'll learn how to deploy machine learning applications on Kubernetes, including Pods, Deployments, Services, Ingress, ConfigMaps, Secrets, Horizontal Pod Autoscaling (HPA), rolling updates, and production-grade scaling. This chapter brings together Docker, Kubernetes, CI/CD, and REST APIs into a complete enterprise deployment architecture.

Module 10 · Lesson 10.18

Kubernetes Deployment

Chapter 10.18 – Kubernetes Deployment

  • Docker packages your Machine Learning application into a container, while Kubernetes deploys, manages, scales, and monitors those containers in production.

Today, most enterprise AI applications—including recommendation systems, fraud detection services, chatbots, and prediction APIs—run on Kubernetes because it provides high availability, automatic scaling, self-healing, and zero-downtime deployments.

Learning Objectives

By the end of this chapter, you will be able to

  • Understand Kubernetes deployment architecture.
  • Learn Kubernetes Pods, Deployments, and Services.
  • Deploy Docker containers.
  • Expose applications to users.
  • Manage ConfigMaps and Secrets.
  • Scale applications automatically.
  • Perform rolling updates and rollbacks.
  • Deploy Machine Learning models.
  • Prepare for Kubernetes deployment interview questions.

1. Introduction

Suppose you built a House Price Prediction API using FastAPI.

It runs perfectly on your laptop.

FastAPI
Prediction

But now your company expects

  • 100,000 users/day
  • High availability
  • Zero downtime
  • Automatic recovery
  • Automatic scaling

Running a single Docker container is not enough.

This is where Kubernetes comes in.

2. What is Kubernetes Deployment?

Definition

A Kubernetes Deployment is a resource that manages the lifecycle of application Pods by ensuring the desired number of replicas are running, supporting updates, rollbacks, and self-healing.

Instead of manually starting containers,

you tell Kubernetes

"Always keep 3 copies of my application running."

Kubernetes handles the rest.

3. Kubernetes Architecture

Internet

Load Balancer

Kubernetes Service

┌──────────┴──────────┐

▼ ▼

Pod 1 Pod 2

│ │

▼ ▼

FastAPI App FastAPI App

│ │

└──────────┬──────────┘

Machine Learning Model

4. Deployment Workflow

Python Code
Docker Image
Container Registry
Kubernetes Deployment
Pods
Service
Users

5. Kubernetes Objects

ObjectPurpose
PodRuns one or more containers
DeploymentManages Pods
ReplicaSetMaintains the desired number of Pods
ServiceExposes Pods inside or outside the cluster
IngressHTTP/HTTPS routing
ConfigMapConfiguration data
SecretSensitive information
NamespaceResource isolation
Horizontal Pod Autoscaler (HPA)Automatic scaling

6. Docker Image

First create your Docker image.

docker build -t house-price-api:v1 .

Push it to a container registry.

Examples

  • Docker Hub
  • Azure Container Registry (ACR)
  • Amazon Elastic Container Registry (ECR)
  • Google Artifact Registry

7. Deployment YAML

A Deployment is described using YAML.

Example

apiVersion: apps/v1

kind: Deployment

metadata

name: house-api

spec

replicas: 3

selector

matchLabels

app: house-api

template

metadata

labels

app: house-api

spec

containers

- name: api

image: house-api:v1

ports

- containerPort: 8000

Apply

kubectl apply -f deployment.yaml

8. ReplicaSets

ReplicaSets ensure the required number of Pods are always running.

Example

Desired

3 Pods

Current

2 Pods

Kubernetes automatically starts another Pod.

9. Pods

A Pod is the smallest deployable unit in Kubernetes.

Example

Pod
FastAPI
ML Model

Each Pod runs one or more containers.

10. Services

Pods have changing IP addresses.

Services provide a stable endpoint.

Users
Service
Pod 1

Pod 2

Pod 3

Common service types

  • ClusterIP (internal)
  • NodePort
  • LoadBalancer

11. Load Balancing

Suppose

100 Requests

Kubernetes distributes them

Pod 1

34 Requests

──────────

Pod 2

33 Requests

──────────

  • Pod 3
  • 33 Requests
  • No single Pod becomes overloaded.

12. Ingress

Ingress manages external HTTP/HTTPS traffic.

Example

Internet
Ingress
Service
Pods

It supports

  • URL routing
  • TLS/HTTPS termination
  • Host-based routing

13. ConfigMaps

Store configuration separately from application code.

Example

DATABASE_NAME=ml_db
API_VERSION=v1

Benefits

Easier configuration changes.

No need to rebuild Docker images for configuration updates.

14. Secrets

Store sensitive information.

Examples

  • Database passwords
  • API keys
  • JWT secrets
  • Cloud credentials

Never hardcode secrets into source code or Docker images.

15. Horizontal Pod Autoscaler (HPA)

Automatically adjusts the number of Pods based on metrics such as CPU utilization.

Example

Low traffic

2 Pods

High traffic

10 Pods

Traffic decreases

3 Pods

This improves both performance and cost efficiency.

16. Rolling Updates

  • Rolling updates replace Pods gradually.
  • Pod 1
  • Version 2

──────────

Pod 2

Version 1

──────────

Pod 3

Version 1
Pod 2
Version 2
All Pods

Version 2

Users continue accessing the application during the update.

17. Rollback

Suppose Version 2 fails.

Rollback

kubectl rollout undo deployment house-api

Kubernetes restores the previous version.

18. Self-Healing

Suppose a Pod crashes.

Pod
Crash

Kubernetes detects the failure.

Creates a new Pod automatically.

No manual intervention is required.

19. Scaling

Manual scaling

kubectl scale deployment house-api --replicas=5

Pods

1
5

The application can now handle more requests.

20. Kubernetes Deployment Workflow

Developer
GitHub
CI/CD
Docker Build
Container Registry
Kubernetes Deployment
Pods
Service
Users

21. Machine Learning Deployment

ML Model
FastAPI
Docker
Kubernetes
Prediction API

This is one of the most common production architectures.

22. Kubernetes + MLflow

Train Model
MLflow Registry
Docker Image
Kubernetes
Production

The deployment pipeline always uses an approved model version.

23. Kubernetes + Monitoring

Monitor

  • CPU
  • Memory
  • Pod health
  • Restart count
  • Response time
  • Error rate

Typical tools

  • Prometheus
  • Grafana
  • Azure Monitor
  • Amazon CloudWatch
  • Google Cloud Monitoring

24. Real-World Example

Suppose Netflix receives a sudden increase in traffic.

1 Million Users

Kubernetes automatically scales

20 Pods
100 Pods

When traffic decreases

100 Pods
20 Pods

25. Production Architecture

Users
Load Balancer
Ingress
Service
Pods
FastAPI
Machine Learning Model

26. Advantages

  • High availability.
  • Automatic scaling.
  • Self-healing.
  • Rolling updates.
  • Easy rollback.
  • Efficient resource utilization.
  • Cloud-independent architecture.

27. Limitations

  • Steeper learning curve.
  • Cluster management adds operational complexity.
  • Misconfigured resource limits can affect performance.
  • Networking and storage require careful planning.

28. Best Practices

  • Use Deployments instead of standalone Pods.
  • Define CPU and memory requests/limits.
  • Use ConfigMaps and Secrets.
  • Enable readiness and liveness probes.
  • Monitor applications continuously.
  • Keep container images small.
  • Use rolling updates for production.

29. Common Mistakes

  • Running only one Pod.
  • Hardcoding secrets.
  • No resource limits.
  • No health checks.
  • No monitoring.
  • Deploying without rollback capability.

30. Interview Questions

Beginner

  • What is Kubernetes Deployment?
  • What is a Pod?
  • What is a Service?
  • What is Ingress?
  • What is a ReplicaSet?

Intermediate

What is a ConfigMap?

  • What is a Secret?
  • Explain Rolling Updates.
  • What is Horizontal Pod Autoscaling?
  • Why are Services required?

Advanced

  • Design a Kubernetes architecture for a Machine Learning API.
  • How would you deploy FastAPI on Kubernetes?
  • Explain self-healing.
  • How would you scale an ML inference service?
  • Explain a production Kubernetes deployment pipeline.

31. Mini Project

Deploy a House Price Prediction API

Architecture

FastAPI
Docker Image
Container Registry
Kubernetes Deployment
Service
Ingress
Users
  • Tasks
  • Build the Docker image.
  • Push it to a container registry.
  • Create a Deployment with three replicas.
  • Expose the application using a Service.
  • Configure an Ingress.
  • Enable Horizontal Pod Autoscaling.
  • Monitor CPU and latency.
  • Perform a rolling update to Version 2.
  • Roll back if health checks fail.

32. Enterprise Kubernetes Architecture

Developer

GitHub

CI/CD Pipeline

Docker Build

Container Registry

Kubernetes Cluster

Deployment

ReplicaSet

Pods

Service

Ingress

Users

Monitoring

33. Kubernetes Deployment Cheat Sheet

ComponentPurpose
PodRuns containers
DeploymentManages Pods
ReplicaSetMaintains replica count
ServiceStable network endpoint
IngressExternal HTTP/HTTPS routing
ConfigMapConfiguration
SecretSensitive credentials
HPAAutomatic scaling

Chapter Summary

Kubernetes Deployment is the standard approach for running Machine Learning applications in production. It manages Pods, ReplicaSets, and Services, while providing features such as automatic scaling, self-healing, rolling updates, and rollbacks. Combined with Docker, CI/CD, MLflow, and Model Monitoring, Kubernetes enables reliable, scalable, and highly available AI systems suitable for enterprise workloads.

Learning Progress

  • Git & GitHub

  • Docker

  • Kubernetes

  • MLflow

  • DVC

  • FastAPI

  • Flask

  • Streamlit

  • Azure Machine Learning

  • AWS SageMaker

  • Google Vertex AI

  • CI/CD

  • Model Monitoring

  • Data Drift

  • Feature Store

  • Deployment Strategies

  • REST APIs

  • Kubernetes Deployment

You now understand how enterprise organizations deploy and manage machine learning applications at scale using Kubernetes, combining containerization, orchestration, monitoring, and automated deployment strategies.

What's Next?

In Chapter 10.19 – End-to-End Deployment Project, you'll bring together everything you've learned in Module 10 by building a complete production-grade MLOps solution. You'll implement:

  • Git & GitHub for version control
  • Docker for containerization
  • MLflow for experiment tracking
  • DVC for dataset versioning
  • FastAPI for serving predictions
  • Streamlit for the user interface
  • CI/CD for automated deployment
  • Kubernetes for orchestration
  • Model Monitoring and Drift Detection
  • Cloud deployment (Azure ML, SageMaker, or Vertex AI)

This capstone-style project demonstrates the complete lifecycle of deploying and operating a machine learning application in production.

Module 10 · Lesson 10.19

End-to-End Deployment Project

Chapter 10.19 – End-to-End Deployment Project

  • This chapter combines everything you have learned throughout Module 10 into a single production-ready Machine Learning project.

You will build a complete MLOps solution that starts with raw data and ends with a scalable, monitored Machine Learning API running on Kubernetes with automated CI/CD.

Learning Objectives

By the end of this chapter, you will be able to

  • Build an end-to-end ML system.
  • Version code, data, and models.
  • Train and track ML experiments.
  • Containerize an ML application.
  • Deploy the application to Kubernetes.
  • Automate deployment using CI/CD.
  • Monitor the production system.
  • Detect data drift.
  • Scale the application automatically.
  • Understand a real-world enterprise MLOps workflow.
  • Project Overview
  • Project Name
  • House Price Prediction Platform
  • Goal

Build a production-ready Machine Learning application that

  • Predicts house prices.
  • Exposes predictions through a REST API.
  • Provides a web interface.
  • Automatically deploys new versions.
  • Supports monitoring and scaling.
  • Business Problem

A real estate company wants an application where agents can enter

  • Area
  • Number of bedrooms
  • Number of bathrooms
  • House age
  • Location score
  • The application should instantly predict the selling price.
  • Thousands of agents may use the system simultaneously.
  • Technologies Used
LayerTechnology
ProgrammingPython
ML LibraryScikit-learn
Experiment TrackingMLflow
Data VersioningDVC
APIFastAPI
FrontendStreamlit
ContainerizationDocker
OrchestrationKubernetes
Version ControlGit & GitHub
CI/CDGitHub Actions
MonitoringPrometheus + Grafana
CloudAzure ML / AWS SageMaker / Vertex AI

Complete Architecture

Users

Streamlit UI

FastAPI Server

House Price Model

Prediction Result

────────────────────────────────────────

Developer
GitHub Repository
GitHub Actions
Run Tests
Train Model
MLflow
Build Docker Image
Container Registry
Kubernetes
Pods
Monitoring

Project Folder Structure

HousePriceProject/

├── data/

│ ├── raw/

│ ├── processed/

├── models/
├── notebooks/

├── src/

│ ├── train.py

│ ├── predict.py

│ ├── preprocessing.py

├── app/

│ ├── api.py

│ ├── ui.py

├── tests/

  • ├── Dockerfile
  • ├── requirements.txt
  • ├── dvc.yaml
  • ├── deployment.yaml
  • ├── service.yaml

├── .github/

│ └── workflows/

│ └── ci.yml

└── README.md

Step 1 – Collect Data

Example dataset

AreaBedroomsBathroomsAgePrice
1200221045L
150032575L
180033295L

Store data in

  • data/raw/
  • Step 2 – Version Data using DVC
  • dvc init
  • dvc add data/raw

Benefits

  • Track dataset versions.
  • Restore previous datasets.
  • Share datasets with the team.
  • Step 3 – Train Model

Example

model.fit(X_train, y_train)

Save model

joblib.dump(model,"models/model.pkl")

Step 4 – Track Experiments

Log

  • Parameters
  • Metrics
  • Artifacts

Example

  • mlflow.log_metric("RMSE",23.5)
  • mlflow.log_param("Algorithm","Random Forest")
  • Every training run is stored.
  • Step 5 – Register Model
RandomForest
Version 1
Version 2
Production

Only approved models move to production.

Step 6 – Build FastAPI

Prediction endpoint

POST

/predict

Input

{

  • "area":1500,
  • "bedrooms":3,
  • "bathrooms":2,
  • "age":5

}

Output

{

"price":7500000

}

Step 7 – Build Streamlit UI

Interface

Area

\[1500\]

Bedrooms

\[3\]

Bathrooms

\[2\]

Age

\[5\]
\[Predict\]

Result

  • Predicted Price
  • ₹75,00,000
  • Step 8 – Dockerize

Dockerfile

  • FROM python:3.11
  • COPY . .
  • RUN pip install -r requirements.txt
  • CMD ["uvicorn","app.api:app"]

Build

docker build -t house-api:v1 .

Step 9 – Push Image

Push Docker image

  • Docker Hub
  • or
  • Azure Container Registry
  • or
  • Amazon ECR
  • or
  • Google Artifact Registry
  • Step 10 – Kubernetes Deployment

Deployment

3 Pods
FastAPI
Prediction API
kubectl apply -f deployment.yaml

Step 11 – Expose Service

Users
Load Balancer
Service
Pods

Users now access the API through a stable endpoint.

Step 12 – CI/CD Pipeline

Workflow

Git Push
GitHub Actions
Run Tests
Train Model
Build Docker
Deploy Kubernetes

Every commit can automatically trigger the deployment pipeline.

Step 13 – Monitoring

Track

  • CPU
  • Memory
  • Latency
  • Error rate
  • Request count

Dashboard

Latency

95 ms

────────────

CPU

45%

────────────

Errors

0.2%

Step 14 – Detect Data Drift

Compare

Training Data
Production Data
PSI
Alert

If significant drift is detected, schedule retraining.

Step 15 – Automatic Scaling

Traffic

100 Users
2 Pods

Traffic increases

10000 Users
10 Pods
  • Kubernetes automatically scales the application.
  • Step 16 – Rolling Update
  • Deploy Version 2.
  • Pod 1
  • Version 2

────────────

Pod 2

Version 1

────────────

Pod 3

  • Version 1
  • Pods are updated one at a time to avoid downtime.
  • Step 17 – Rollback

If Version 2 fails

kubectl rollout undo

Production returns to Version 1.

Complete Production Workflow

Raw Data
DVC
Training
MLflow
Model Registry
FastAPI
Docker
Container Registry
Kubernetes
REST API
Users
Monitoring
Drift Detection
Retraining

Enterprise Architecture

GitHub

GitHub Actions

Train Model

MLflow

Register Model

Docker Build

Container Registry

Kubernetes Cluster

┌──────────┴──────────┐

▼ ▼

Pod 1 Pod 2

▼ ▼

FastAPI FastAPI

└──────────┬──────────┘

Load Balancer
Users

Security Considerations

Use

  • HTTPS
  • JWT Authentication
  • Kubernetes Secrets
  • Role-Based Access Control (RBAC)
  • Network Policies
  • Container image scanning
  • Regular dependency updates
  • Logging

Store

  • Request logs
  • Prediction logs
  • Error logs
  • Audit logs

Example

  • 10:30
  • Prediction
  • Success
  • Latency
  • 105 ms
  • Testing

Perform

  • Unit Testing
  • Integration Testing
  • API Testing
  • Performance Testing
  • Load Testing
  • Security Testing
  • Only deploy if all tests pass.
  • Scaling Strategy

Horizontal

2 Pods
10 Pods

Vertical

2 GB RAM
8 GB RAM
  • Horizontal scaling is generally preferred for stateless REST APIs.
  • Project Deliverables
  • Source code in GitHub
  • Versioned dataset using DVC
  • Trained ML model
  • MLflow experiment history
  • FastAPI prediction service
  • Streamlit frontend
  • Docker image
  • Kubernetes deployment
  • CI/CD pipeline
  • Monitoring dashboard
  • Documentation

Advantages

  • Fully automated deployment.
  • Reproducible ML workflow.
  • Scalable architecture.
  • High availability.
  • Easy rollback.
  • Production monitoring.
  • Enterprise-ready.
  • Challenges
  • Managing cloud costs.
  • Kubernetes complexity.
  • Monitoring large-scale systems.
  • Securing APIs and secrets.
  • Handling model retraining efficiently.
  • Best Practices
  • Keep code modular.
  • Version everything (code, data, models).
  • Automate testing.
  • Use Infrastructure as Code.
  • Monitor production continuously.
  • Store secrets securely.
  • Document deployment procedures.

Common Mistakes

  • Training directly in production.
  • Deploying without testing.
  • Ignoring monitoring.
  • Not versioning datasets.
  • Hardcoding credentials.
  • Deploying without rollback support.

Interview Questions

Beginner

  • Explain an end-to-end ML deployment workflow.
  • Why do we use Docker?
  • Why is Kubernetes required?
  • What is MLflow?
  • What is DVC?

Intermediate

  • How does CI/CD automate deployments?
  • How would you monitor a deployed ML model?
  • How would you detect data drift?
  • Why use FastAPI instead of directly exposing the model?
  • How does Kubernetes provide high availability?

Advanced

  • Design an enterprise MLOps architecture.
  • How would you deploy multiple model versions?
  • How would you implement Canary Deployment?
  • Explain the complete lifecycle of a production ML system.
  • How would you reduce downtime during deployments?
  • Mini Capstone Assignment

Build a complete House Price Prediction Platform with the following features

Frontend: Streamlit application for user input.

  • Backend: FastAPI REST API for predictions.
  • Model: Train a Random Forest or XGBoost regression model using Scikit-learn.
  • Experiment Tracking: Log runs and metrics using MLflow.
  • Data Versioning: Track datasets using DVC.
  • Containerization: Package the application with Docker.
  • Deployment: Deploy to a Kubernetes cluster with three replicas.
  • Automation: Create a GitHub Actions pipeline that runs tests, builds the Docker image, and deploys automatically.
  • Monitoring: Display metrics with Prometheus and Grafana.
  • Drift Detection: Trigger an alert if feature distributions change significantly.
  • Complete MLOps Lifecycle
  • Business Problem

Collect Data

Data Versioning (DVC)

Feature Engineering

Model Training

Experiment Tracking (MLflow)

Model Registry

FastAPI Service

Docker

Kubernetes

REST API

Users

Monitoring

Data Drift Detection

Retraining

Chapter Summary

An end-to-end ML deployment project combines data engineering, model development, experiment tracking, API development, containerization, orchestration, automation, monitoring, and maintenance into a single production-ready workflow. By integrating tools such as Git, DVC, MLflow, FastAPI, Docker, Kubernetes, CI/CD, and monitoring platforms, organizations can build reliable, scalable, and maintainable AI systems that continuously deliver business value.

Learning Progress

  • Git & GitHub

  • Docker

  • Kubernetes

  • MLflow

  • DVC

  • FastAPI

  • Flask

  • Streamlit

  • Azure Machine Learning

  • AWS SageMaker

  • Google Vertex AI

  • CI/CD

  • Model Monitoring

  • Data Drift

  • Feature Store

  • Deployment Strategies

  • REST APIs

  • Kubernetes Deployment

  • End-to-End Deployment Project

What's Next?

In Chapter 10.20 – MLOps Interview Questions, you'll review the most frequently asked interview questions on MLOps, ranging from beginner to advanced topics. You'll cover Git, Docker, Kubernetes, MLflow, DVC, CI/CD, cloud platforms, deployment strategies, monitoring, data drift, feature stores, and system design scenarios, helping you prepare for roles such as Machine Learning Engineer, MLOps Engineer, Data Engineer, AI Engineer, and Platform Engineer.

Module 10 · Lesson 10.20

MLOps Interview Questions

Chapter 10.20 – MLOps Interview Questions

  • MLOps interviews test more than your knowledge of machine learning algorithms.

Interviewers expect you to understand how models are developed, deployed, monitored, scaled, and maintained in production. You should also be able to explain architectural decisions, trade-offs, and troubleshooting approaches.

Learning Objectives

By the end of this chapter, you will be able to

  • Answer common MLOps interview questions.
  • Explain end-to-end ML pipelines.
  • Compare MLOps tools and platforms.
  • Design production-grade ML systems.
  • Handle scenario-based interview questions.

Prepare for Machine Learning Engineer and MLOps Engineer interviews.

Interview Preparation Tips

Before attending an interview, make sure you can explain

  • The complete ML lifecycle.
  • Docker and Kubernetes basics.
  • REST APIs.
  • CI/CD pipelines.
  • MLflow and DVC.
  • Cloud ML platforms (Azure ML, AWS SageMaker, Vertex AI).
  • Monitoring and Data Drift.
  • Deployment strategies.
  • Model versioning.
  • System architecture.

Section 1 – Beginner Questions

Q1. What is MLOps?

Answer

MLOps (Machine Learning Operations) is the practice of applying DevOps principles to machine learning. It automates the lifecycle of ML models, including data preparation, training, testing, deployment, monitoring, retraining, and governance.

Q2. Why do we need MLOps?

Without MLOps

  • Manual deployments
  • Difficult collaboration
  • No model versioning
  • Poor reproducibility
  • Hard to monitor production models

With MLOps

  • Automated pipelines
  • Version control
  • CI/CD
  • Monitoring
  • Scalability
  • Reliable deployments

Q3. What is the Machine Learning lifecycle?

Business Problem

Collect Data

Preprocess Data

Feature Engineering

Model Training

Evaluation

Deployment

Monitoring

Retraining

Q4. Difference between DevOps and MLOps?

DevOpsMLOps
Manages application codeManages code, data, and models
CI/CDCI/CD + Continuous Training
Software testingModel evaluation + software testing
Focus on applicationsFocus on ML systems

Q5. What is a Machine Learning pipeline?

A Machine Learning pipeline is an automated workflow that performs tasks such as

  • Data ingestion
  • Data preprocessing
  • Feature engineering
  • Model training
  • Evaluation
  • Deployment

Section 2 – Git & Docker

Q6. Why is Git used in MLOps?

Git tracks

  • Source code
  • Configuration files
  • Documentation
  • Infrastructure definitions

Git does not efficiently version large datasets or model artifacts, which is why tools like DVC or model registries are used.

Q7. Why use Docker?

Docker packages

  • Python code
  • Libraries
  • Model files
  • Dependencies
  • into a portable container.

This ensures the application behaves consistently across environments.

Q8. Docker vs Virtual Machine

DockerVirtual Machine
LightweightHeavy
Shares host OS kernelIncludes guest OS
Starts quicklySlower startup
Efficient resource usageHigher resource consumption

Section 3 – Kubernetes

Q9. Why Kubernetes?

Kubernetes provides

  • Automatic scaling
  • Self-healing
  • Rolling updates
  • Load balancing
  • High availability

Q10. What is a Pod?

A Pod is the smallest deployable unit in Kubernetes.

It contains one or more containers.

Q11. What is a Deployment?

A Deployment manages Pods.

It ensures

  • Desired number of replicas
  • Rolling updates
  • Rollbacks
  • Self-healing

Q12. Difference between Pod and Deployment?

PodDeployment
Runs containersManages Pods
Can fail without replacementAutomatically recreates Pods
Individual runtime unitDesired state manager

Section 4 – MLflow

Q13. What is MLflow?

MLflow is an open-source platform for

  • Experiment tracking
  • Model registry
  • Model packaging
  • Model deployment

Q14. What information does MLflow track?

  • Parameters
  • Metrics
  • Artifacts
  • Models
  • Source code reference (when configured)
  • Experiment runs

Section 5 – DVC

Q15. Why use DVC?

DVC versions

  • Large datasets
  • Trained models
  • Data pipelines

without storing large binary files directly in Git.

Q16. Git vs DVC

GitDVC
Source codeData & ML artifacts
Text filesLarge binary files
BranchesDataset/model versions

Section 6 – FastAPI & REST APIs

Q17. Why FastAPI?

FastAPI provides

  • High performance
  • Automatic validation
  • Automatic OpenAPI/Swagger documentation
  • Async support
  • Easy REST API development

Q18. Why use REST APIs for ML?

REST APIs allow

  • Mobile apps
  • Websites
  • Enterprise systems
  • BI tools

to request predictions from ML models over HTTP.

Q19. Difference between GET and POST?

GETPOST
Retrieves dataSends data for processing or creation
No request body (typically)Usually includes a request body
Should not modify dataCan modify or create resources

Prediction APIs commonly use POST because input features are sent in the request body.

Section 7 – CI/CD

Q20. What is CI/CD?

CI/CD automates

  • Build
  • Test
  • Package
  • Deployment
for software and ML applications.

Q21. What is Continuous Integration?

Developers frequently merge code into a shared repository.

Automated builds and tests verify each change.

Q22. What is Continuous Deployment?

After all automated checks pass,

the application is deployed automatically to production.

Section 8 – Monitoring

Q23. Why monitor ML models?

Models can degrade because of

  • Data drift
  • Concept drift
  • Changing business conditions
  • Infrastructure issues
  • Monitoring detects these problems early.

Q24. What metrics are monitored?

  • Latency
  • Throughput
  • Error rate
  • CPU
  • Memory
  • Accuracy (when labels are available)
  • Data quality
  • Drift
  • Business KPIs

Section 9 – Data Drift

Q25. What is Data Drift?

Data Drift occurs when production input data has a different statistical distribution than the training data.

Q26. Difference between Data Drift and Concept Drift?

Data DriftConcept Drift
Input data changesRelationship between inputs and target changes
Easier to detect statisticallyOften requires labeled outcomes

Q27. How do you detect Data Drift?

Common methods

  • Population Stability Index (PSI)
  • Kolmogorov–Smirnov (KS) Test
  • Chi-Square Test
  • Jensen-Shannon Distance

Section 10 – Feature Store

Q28. What is a Feature Store?

A centralized system for

  • Storing
  • Versioning
  • Serving
  • Reusing
  • machine learning features.

Q29. Why use a Feature Store?

It prevents

  • Duplicate feature engineering
  • Inconsistent calculations
  • Training-serving skew

Section 11 – Deployment

Q30. Explain Blue-Green Deployment.

Two production environments exist

  • Blue (current)
  • Green (new)
  • Traffic switches to Green after validation.

Rollback is quick by switching back to Blue.

Q31. Explain Canary Deployment.

A small percentage of users receive the new version first.

Traffic gradually increases if monitoring shows acceptable performance.

Q32. What is Shadow Deployment?

  • Production traffic is sent to both the current and new model.
  • Only the current model's predictions are returned to users.
  • The new model's outputs are logged for evaluation.

Section 12 – Cloud Platforms

Q33. Azure ML vs SageMaker vs Vertex AI

Azure MLSageMakerVertex AI
Microsoft AzureAWSGoogle Cloud
Azure ecosystemAWS ecosystemGoogle Cloud ecosystem
Azure ML WorkspaceSageMaker StudioVertex AI Workbench

All three provide

  • Training
  • Model registry
  • Deployment
  • Monitoring
  • Pipelines

Section 13 – Scenario-Based Questions

Q34. Your production model accuracy drops from 96% to 82%. What would you do?

Suggested approach

Verify the monitoring alerts.

  • Check whether recent deployments introduced changes.
  • Compare production data with training data for data drift.
  • Analyze prediction errors if ground-truth labels are available.
  • Review infrastructure health (latency, resource usage).
  • Retrain the model if necessary.
  • Validate the new model before redeployment.

Q35. How would you deploy a new model with minimal risk?

Use

  • Canary Deployment
  • Blue-Green Deployment
  • Rolling Updates

Monitor

  • Latency
  • Error rate
  • Business metrics
  • Rollback if needed.

Q36. Design an enterprise MLOps architecture.

GitHub
CI/CD
Training Pipeline
MLflow
Model Registry
Docker
Kubernetes
REST API
Monitoring
Drift Detection
Retraining

Q37. How do you scale an ML API?

Possible approaches

  • Multiple application replicas
  • Kubernetes Horizontal Pod Autoscaler
  • Load Balancer
  • Optimized model inference
  • Caching (where appropriate)

Q38. How do you secure an ML API?

Use

  • HTTPS
  • Authentication (JWT, OAuth 2.0, API Keys)
  • Authorization (RBAC)
  • Rate limiting
  • Input validation
  • Secrets management

Section 14 – System Design Questions

Q39. Design a fraud detection system.

Architecture

Transactions
Kafka
Feature Engineering
Feature Store
Fraud Model
REST API
Decision
Monitoring
Retraining

Key considerations

  • Low latency
  • High availability
  • Real-time feature serving
  • Monitoring
  • Drift detection

Q40. Design a recommendation system.

Components

  • User activity collection
  • Feature engineering
  • Feature Store
  • Recommendation model
  • REST API
  • Redis cache (optional)
  • Monitoring
  • Continuous retraining

Section 15 – Practical Coding Questions

Interviewers may ask you to

  • Build a FastAPI prediction API.
  • Dockerize an ML application.
  • Write a GitHub Actions workflow.
  • Create a Kubernetes Deployment YAML.
  • Log experiments using MLflow.
  • Version a dataset using DVC.
  • Detect Data Drift using Python.
  • Build a simple CI/CD pipeline.

Section 16 – Interview Cheat Sheet

TopicKey Points
GitVersion control
DockerContainerization
KubernetesOrchestration
MLflowExperiment tracking & model registry
DVCData versioning
FastAPIHigh-performance REST APIs
CI/CDAutomated build, test, and deployment
MonitoringPerformance and health tracking
Data DriftInput distribution changes
Feature StoreCentralized feature management
Azure MLAzure cloud ML platform
SageMakerAWS cloud ML platform
Vertex AIGoogle Cloud ML platform

Section 17 – Complete MLOps Workflow

Business Problem

Collect Data

Version Data (DVC)

Feature Engineering

Train Model

Track Experiments (MLflow)

Register Model

Build REST API (FastAPI)

Dockerize

CI/CD Pipeline

Deploy to Kubernetes

Monitor

Detect Drift

Retrain

Top 10 Interview Tips

  • Understand the entire ML lifecycle, not just model training.
  • Be able to explain why a tool is used, not just how.
  • Draw architecture diagrams during system design questions.
  • Discuss trade-offs (e.g., Canary vs. Blue-Green deployments).
  • Mention monitoring and rollback plans when discussing deployment.
  • Understand cloud-specific terminology if applying to Azure, AWS, or GCP roles.
  • Practice writing simple Dockerfiles, Kubernetes YAML, and FastAPI endpoints.
  • Know how to troubleshoot production issues such as data drift and high latency.
  • Communicate clearly and structure your answers logically.
  • Relate answers to real-world scenarios when possible.

Chapter Summary

MLOps interviews assess your ability to build and operate production-grade machine learning systems. Beyond algorithms, employers expect knowledge of version control, containerization, orchestration, experiment tracking, CI/CD, cloud platforms, deployment strategies, monitoring, data drift, feature management, and system design. Strong candidates can explain both the technical implementation and the reasoning behind architectural choices.

  • Module 10 Completion
  • Congratulations! 🎉 You have completed Module 10 – MLOps & Cloud.
  • Skills You Have Learned
  • Git & GitHub
  • Docker
  • Kubernetes
  • MLflow
  • DVC
  • FastAPI
  • Flask
  • Streamlit
  • Azure Machine Learning
  • AWS SageMaker
  • Google Vertex AI
  • CI/CD
  • Model Monitoring
  • Data Drift
  • Feature Store
  • Deployment Strategies
  • REST APIs
  • Kubernetes Deployment
  • End-to-End Deployment Project
  • MLOps Interview Preparation

You now have a strong foundation in modern MLOps concepts, from developing machine learning models to deploying, monitoring, scaling, and maintaining them in production. This knowledge prepares you for roles such as Machine Learning Engineer, MLOps Engineer, AI Engineer, Data Engineer, and Platform Engineer.