Sub topic 1
What MLOps is and why models need operations
Prerequisites
This chapter assumes you can read basic Python, have trained and evaluated a supervised model (for example with scikit-learn), and use Git and the command line. You should also know roughly how a web service is deployed: code is built, packaged, and run behind an endpoint. No MLOps tooling is required yet.
What MLOps is
MLOps (machine learning operations) is the set of practices for building, deploying, and running machine learning systems reliably over time. It combines three fields:
- Machine learning, which produces a model from data.
- Software engineering, which supplies version control, testing, and review.
- Operations, which supplies deployment, monitoring, and incident response.
The core idea is that a model in production is a running system, not a file. Someone has to keep it correct, available, and explainable after the data scientist has moved on to the next project.
Why models need operations
In ordinary software, behavior is defined by code. If the code does not change and the infrastructure is healthy, the program behaves the same way tomorrow as today.
A machine learning system has three inputs that define its behavior: code, data, and the resulting model artifact. Any of them can change behavior, and the data can change without anyone touching the repository.
That produces failure modes that a standard DevOps pipeline does not catch:
- Silent degradation. The service returns HTTP 200 and well-formed predictions, but the predictions are getting worse because the world changed.
- Irreproducible results. Nobody can say which data, code, and parameters produced the model currently serving traffic.
- Training-serving mismatch. Features are computed one way in the training notebook and another way in the production service.
- Manual handoffs. A notebook is passed to an engineer who rewrites it, and the rewrite behaves differently.
The next example shows silent degradation in about twenty lines. The model is never modified, but the relationship between input and label shifts after training.
import numpy as np
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score
rng = np.random.default_rng(0)
def make_data(n, threshold):
"""One feature; the label is 1 when the feature (plus noise) exceeds the threshold."""
x = rng.normal(size=(n, 1))
y = (x[:, 0] + rng.normal(scale=0.3, size=n) > threshold).astype(int)
return x, y
X_train, y_train = make_data(5000, threshold=0.0)
model = LogisticRegression().fit(X_train, y_train)
X_old, y_old = make_data(5000, threshold=0.0) # the world as it was at training time
X_new, y_new = make_data(5000, threshold=1.0) # the world after the rule changed
print("accuracy, same world: ", round(accuracy_score(y_old, model.predict(X_old)), 3))
print("accuracy, changed world:", round(accuracy_score(y_new, model.predict(X_new)), 3))The second accuracy is clearly lower, yet no exception is raised and no test fails. Catching this requires monitoring that compares predictions with real outcomes, which is why operations is part of the discipline. Later chapters cover that monitoring in detail.
How MLOps differs from DevOps and from model development
| Aspect | DevOps | Model development alone | MLOps |
|---|---|---|---|
| Main artifact | Application build | Notebook and trained model | Code, data, and model, versioned together |
| What can change behavior | Code and configuration | The experiment you ran | Code, data, features, and the world itself |
| Testing | Unit and integration tests | Held-out evaluation once | Code tests plus data checks and model quality gates |
| After release | Watch errors and latency | Usually nothing | Watch errors, latency, input data, and prediction quality |
| Typical failure | Crash or regression | Result cannot be repeated | Quiet loss of accuracy |
MLOps does not replace DevOps. It reuses continuous integration, infrastructure as code, and observability, and adds the parts that data-dependent systems need. It also goes beyond model development, which ends when an evaluation number looks good.
The working model: a loop, not a line
A common mistake is to picture ML work as a straight path that ends at deployment. In practice it is a loop. Production behavior produces new data and new evidence, and that evidence feeds the next round of training.
MLOps practices exist to make each arrow in this loop repeatable, observable, and, where sensible, automated. The following chapters take the stages one at a time, starting with the lifecycle overview.
What MLOps practice looks like
Most teams adopt MLOps gradually. These are the typical building blocks and the problem each one solves:
- Version control for everything that matters. Code lives in Git. Data and models also need identifiers, so you can answer "which data trained this model?".
- Experiment tracking. Parameters, metrics, and artifacts of each run are recorded instead of living in someone's memory or filenames like
final_v3_really_final.pkl. - Automated pipelines. Training runs as a scripted sequence of steps, not a series of manual notebook cells.
- Release gates. A new model is promoted only if it passes explicit checks, such as a minimum accuracy and no regression against production.
- Controlled deployment. Models are rolled out in ways that limit damage, and can be rolled back.
- Monitoring and retraining. Inputs and outcomes are watched, and degradation triggers a defined response.
Each item is a reaction to one of the failure modes listed earlier. If you are unsure whether a practice is worth adopting, ask which failure it prevents for your system.
Common errors and misconceptions
- "MLOps means buying a platform." Tools help, but the practices matter first. A team with Git, a script, and a spreadsheet of runs can be more disciplined than one with an unused platform.
- "Deployment is the finish line." A deployed model without monitoring is unmonitored software whose accuracy you cannot see.
- "Versioning code is enough." The same code on different data gives a different model. Without a record of data and environment, you cannot reproduce or audit a result.
- "Offline accuracy predicts production accuracy." It does only if production data resembles the evaluation data. That assumption must be checked continuously.
- "Automate everything immediately." Automating a poorly understood process makes its mistakes faster. Make a step repeatable by hand, then automate it.
- "MLOps is only for large companies." Scale changes the tooling, not the need. One model that drives a business decision can fail silently in the same ways as a hundred.
Summary
MLOps treats a machine learning model as a long-running system whose behavior depends on code, data, and a changing environment. It borrows DevOps habits and adds data validation, experiment tracking, release gates on model quality, and monitoring of prediction quality. The rest of this tutorial walks through the lifecycle stage by stage, so that you can map any project's work onto it and judge how mature its practices are.
Exercise
A fraud model is deployed, its service has had 100% uptime for six months, and no code in the repository has changed. Fraud analysts now report that it misses more fraud than before. Name two reasons this can happen without any code change, and say which MLOps practice would have surfaced the problem earlier.
Show answer
Possible reasons: (1) data drift, where the inputs the model sees now differ from the training data, for example because customer behavior or transaction patterns changed; (2) concept drift, where the relationship between inputs and fraud changed, for example because fraudsters adapted their tactics. A training-serving feature mismatch introduced by an upstream data change is another valid answer. Production monitoring would have surfaced it earlier: tracking input distributions for drift, and comparing predictions with confirmed fraud outcomes once labels arrive. Uptime alone cannot show this, because the service was running correctly while its predictions got worse.
Exercise
In the table above, why is "Versioning code is enough" listed as a misconception? Give a concrete example of two models built from identical code that behave differently.
Show answer
A trained model is a product of code, data, and configuration such as random seeds and library versions. If the same training script runs on a dataset snapshot from January and one from June, it produces different models, so the Git commit alone does not identify the model. Recording the data version, parameters, seed, and environment together is what makes a result reproducible and auditable.