Guide to AI and Data Courses · Lecture Notes
Chapter 35: Machine Learning Systems and MLOps
A bank's credit model may score beautifully in a notebook; the real test begins in the months when it answers thousands of applications a day, the applicant population slowly changes, and nobody is watching the screen. MLOps is the course about that second period: running a model as a service, knowing how fast it is and how many requests it can keep up with, tracking drift in the data with numbers, and releasing a new version without putting users at risk. These notes introduce the course and work through its three core ideas with small examples you can compute by hand.
Learning outcomes
- The production question
- Explain, with examples, the gap between a model's notebook performance and its performance in production; recognize training-serving skew.
- Serving
- Compute the mean, median and percentiles of latency measurements; estimate the number of replicas with Little's law.
- Monitoring
- Compute the drift between two distributions with the population stability index (PSI) and interpret the result.
- Deployment
- Show how to read a canary rollout and an A/B test; compute z for a difference of two proportions and the sample size needed.
- Place of the course
- State what separates MLOps from machine learning, big data, data science and embedded AI.
35.1What question does the course ask?
How is a model taken from the lab into production and kept running there?
MLOps applies software engineering and DevOps practice to ML so that models reach production and run reliably there. The course covers versioning data, code and models together, automating the pipeline, deploying, and monitoring the model in production.
In a machine learning course the data is fixed: a dataset is given, a model is trained, the number on the test set is reported, and the job is done. In production nothing is fixed. Data flows and changes, the model must answer new requests every second, and a mistake reaches a real user. The question of the MLOps course is: how does the system that runs the model, not the model itself, become reliable?
As the 2015 paper by Sculley and colleagues stresses, in a real machine learning system the model code is a small box; around it sit data collection, validation, configuration, serving and monitoring infrastructure. This is why the course talks less about the model than about the pipeline: a chain in which every step is recorded, can be rerun and can be rolled back.
35.1.1Training-serving skew
One of the most insidious production bugs is a feature computed differently in training and in serving. For example, the code that prepares the training data may compute "average spend over the last 30 days" with one script, while the live system computes the same feature with different code and a 28-day window. The model looks good in testing, then receives a slightly different input live and quietly predicts badly; no error message appears. Feature stores and a single shared feature code exist to prevent this skew.
The rest of the course comes down to three questions: how do we run and size a model as a service (serving), how do we notice that it degrades live (monitoring), and how do we decide with confidence that a new version is really better (deployment)? The core sections take these three questions in turn.
35.1.2At a glance
| Criterion | Machine Learning Systems and MLOps |
|---|---|
| Approach | software engineering meets ML |
| Input | trained model, data pipeline |
| Output | a running, monitored service |
| Success measure | latency, uptime, data drift |
| Math load | low |
| Data needs | streaming production data |
35.2A short history
| Year | Milestone |
|---|---|
| 2009 | The first DevOpsDays is held in Ghent; DevOps, uniting development and operations, spreads. |
| 2014 | Docker 1.0 is released and Kubernetes announced: containers become the common unit of deployment. |
| 2015 | Sculley et al. expose hidden technical debt in ML systems: model code is a small part of the system. |
| 2017 | Google presents TFX and Uber presents Michelangelo; in-house ML platforms come into view. |
| 2018 | Databricks open-sources MLflow: experiment tracking and a model registry. |
| 2021 | Andrew Ng calls for data-centric AI: focus on data quality more than on the model. |
35.3Core concepts
The rest of the course is built on the concepts below. The following sections work through the most important ones with examples.
| Concept | Meaning |
|---|---|
| Pipeline | Automated steps from data preparation to deployment. |
| Versioning | Tracking and rolling back data, code and model together. |
| Experiment tracking | Logging the parameters, metrics and outputs of every run. |
| Model registry | Approved model versions kept in one place. |
| Feature store | The same features used in training and in production. |
| CI/CD/CT | Continuous integration, delivery and continuous training. |
| Model serving | Running as an online API or as a batch prediction job. |
| Data drift | Production data moving away from training data; must be monitored. |
35.4Serving a model: latency, scale and capacity
Once a model sits behind an API, accuracy is not the only measure of success; latency (the time to answer one request) and throughput (requests answered per second) are part of it too. Looking at latency through the mean is misleading, because a heavy tail hides inside the average. That is why monitoring dashboards use the median and percentiles (p95, p99).
p95: the time within which 95% of requests are answered. By the nearest-rank method, the p percentile of n sorted measurements is the measurement at rank ⌈p · n⌉.
The latencies of 20 requests to a model service are measured in milliseconds (the values are illustrative): 12, 13, 13, 14, 14, 15, 15, 15, 16, 16, 17, 17, 18, 18, 19, 20, 22, 25, 60, 180.
- Mean. The total is 539, so the mean is 539 / 20 = 26.95 ms.
- Median. In the sorted list the 10th value is 16 and the 11th is 17; the median is (16 + 17) / 2 = 16.5 ms.
- p95. ⌈0.95 · 20⌉ = 19, so the 19th value: 60 ms.
- p99. ⌈0.99 · 20⌉ = 20, so the 20th value: 180 ms.
- Target. For the target "every request within 20 ms", 16 requests (80%) meet it and 4 miss it.
The mean (about 27 ms) and the median (16.5 ms) look healthy, yet one user in twenty waits 60 ms and one waits 180 ms. Targets and contracts are therefore written in terms of p95 or p99.
The second question is how many replicas to run. The number of requests being processed at the same time in a system is given by Little's law: L = λ · W, where λ is the number of requests per second, W is the average time a request spends in the system, and L is the average number of requests in the system at the same moment.
The service receives λ = 200 requests per second and a request takes W = 50 ms = 0.05 s on average. One replica can handle at most 4 requests at the same time (the values are illustrative).
- Concurrent requests. L = 200 · 0.05 = 10.
- Minimum replicas. 10 / 4 = 2.5, so at least 3 replicas.
- Utilization. With 3 replicas the capacity is 12 and utilization 10 / 12 ≈ 83%; with 4 replicas the capacity is 16 and utilization 10 / 16 = 62.5%.
- Decision. To leave room for sudden load spikes and for one replica crashing, we choose 4 replicas.
Very high utilization makes latency climb quickly: requests start to queue. That is why capacity is sized for peak load and for the loss of one replica, not for the average load.
35.4.1Online and batch serving
Not every model needs an instant answer. In online serving (an API) latency is critical: a fraud decision must come in milliseconds. In batch serving (a demand forecast that runs overnight) predictions are computed ahead of time and stored; there the total processing time and the cost matter instead of latency. Ways to speed up inference include batching requests, shrinking the model and caching results; each trades off accuracy, latency and cost.
Looking only at mean latency. In the example above the mean is about 27 ms while the slowest request took 180 ms. The heavy tail is the slowness the user actually feels; targets are set on p95 or p99.
35.5Monitoring decay in production: data drift
A model is tuned to the distribution it was trained on. If the distribution of inputs changes in production (the customer base ages, a new campaign starts, a sensor loses its calibration), the model degrades without raising an error. Two kinds of drift are distinguished: data drift, where the input distribution changes, and concept drift, where the relation between input and output changes (an application with the same features now carries a different risk). Because true labels often arrive late (whether a loan was repaid is known months later), monitoring first looks at the input distribution.
The values of a feature are divided into k bins. Let ei be the share falling in bin i in training and ai the share in production. Then PSI = Σ (ai − ei) · ln(ai / ei). Every term is zero or positive; if the distributions are identical, PSI is zero.
In the training data the values of a feature are divided into four equally populated bins: each bin holds 25%. A month later the production data gives the shares 10%, 20%, 30%, 40% (the values are illustrative).
- Bin 1. (0.10 − 0.25) · ln(0.10 / 0.25) = (−0.15)(−0.916) ≈ 0.137.
- Bin 2. (0.20 − 0.25) · ln(0.20 / 0.25) = (−0.05)(−0.223) ≈ 0.011.
- Bin 3. (0.30 − 0.25) · ln(0.30 / 0.25) = (0.05)(0.182) ≈ 0.009.
- Bin 4. (0.40 − 0.25) · ln(0.40 / 0.25) = (0.15)(0.470) ≈ 0.071.
- Total. PSI ≈ 0.137 + 0.011 + 0.009 + 0.071 ≈ 0.228.
A common rule of thumb in credit-risk practice: a PSI below 0.1 is stable, 0.1 to 0.25 is moderate drift, and above 0.25 is major drift. These thresholds are a convention, not a proven law; each team tunes them to its own data. Here 0.228 is in the "moderate" zone and is enough to raise an alert. The largest contribution comes from bin 1: low values are less than half as common in production as expected.
PSI is a single number; the per-bin contributions show where the drift is. In practice it is computed daily or weekly for every feature and for the model output, and features that cross the threshold raise an alert. What follows an alert is an investigation of the cause: a data pipeline may have broken, a real change may have occurred, or retraining may be needed.
35.5.1When to retrain?
Retraining can be triggered by the calendar (every month), by an event (the PSI threshold is crossed) or by performance (accuracy falls as labels arrive). Whichever is chosen, the new model is not released without going through the same validation process as the old one; that is the subject of the next section.
Planning to monitor drift only through accuracy. Labels arrive days or months later, so accuracy reports late; drift in the input distribution can be measured at once. On the other hand, drift does not always mean lost performance: a feature may drift while the model's decision is unaffected. Monitoring uses both together.
35.6Deploying with confidence: canary and A/B testing
A new model version may behave differently on live data even when it beats the old one in offline tests. That is why a new version is not opened to everyone at once. In a canary deployment the new version first receives a small share of the traffic (say 1%), the error rate and latency are watched, and if nothing is wrong the share is raised step by step. In a shadow deployment the new model receives real requests but its answers never reach users; its outputs are only compared with the old model's. In an A/B test users are randomly split into two groups and a business metric (such as the conversion rate) is compared.
The old model (A) and the new model (B) are shown to 10,000 randomly assigned users each. Group A has 500 conversions (5.0%), group B has 560 conversions (5.6%) (the values are illustrative). Is the difference real or chance?
- Difference. 0.056 − 0.050 = 0.006; relative increase 12%.
- Pooled rate. Pretend there is no difference and merge the groups: p = 1060 / 20000 = 0.053.
- Standard error. SE = √(p(1 − p) · (2 / 10000)) = √(0.053 · 0.947 · 0.0002) ≈ 0.00317.
- Test statistic. z = 0.006 / 0.00317 ≈ 1.89.
- Decision. At the two-sided 5% level the threshold is 1.96; since 1.89 < 1.96, the difference is not statistically significant.
A 12% relative increase looks impressive, but in this sample it can also be explained by chance. To decide, either more data is needed or we accept that the difference may be small.
How many users would we have needed? If the true rates are 5.0% and 5.6%, at the 5% significance level and 80% power the sample needed in each group is about n ≈ (1.96 + 0.84)2 · (0.05·0.95 + 0.056·0.944) / 0.0062 ≈ 21,900 users; our 10,000 are not enough to see this small a difference reliably. The required sample grows with the inverse square of the difference as the difference shrinks.
35.6.1Enough evidence in a canary
In a canary the question is "is the new version broken?", and it often has to be answered with little traffic. A practical estimate is the rule of three: if no errors are observed in n requests, the 95% upper bound on the error rate is about 3 / n. If 1% of 200 requests per second goes to the canary, 10 minutes bring 200 · 0.01 · 600 = 1200 requests; with no errors the upper bound is 3 / 1200 = 0.0025, that is 0.25%. If the old version's error rate is much lower, say 0.01%, this evidence is not enough to show the new version is equally good; we wait longer or give it more traffic before raising the share.
Checking the A/B test every day and stopping as soon as the difference looks significant. The significance threshold is valid when we look once, at a sample size fixed in advance; looking repeatedly and stopping at the first significant moment greatly inflates false positives. The required sample is computed beforehand and the test is evaluated when it reaches that size.
35.7How is the course taught?
35.7.1A typical workflow
A bank's credit model is retrained every month on new applications. The best registered version is packaged in a container, first exposed to a small share of traffic, and rolled out to everyone if nothing breaks. When the applicant distribution drifts, the monitoring dashboard alerts the team and the cycle restarts.
35.7.2Topics over the semester
- ML systems in production: requirements, technical debt
- Data pipelines, data validation and versioning
- Feature engineering and feature stores
- Experiment tracking and reproducible training
- Model evaluation: slice analysis and model tests
- Packaging: containers and the model registry
- Model serving: online APIs and batch prediction
- Faster inference: latency, scale and cost
- Deployment strategies: canary, shadow, A/B tests
- Monitoring: data drift, concept drift, alerts
- Continuous training and CI/CD pipelines
- Responsible ML: auditing, documentation, model cards
This is a typical semester; the order and coverage vary between universities.
35.7.3Skills you will gain
- versioning with Git and DVC
- experiment tracking with MLflow
- packaging models with Docker
- serving a model as a REST API
- building pipelines with Airflow
- monitoring dashboards in Prometheus
35.7.4Try it yourself
The Try It: The Model Silently Degrades in Production slide in the presentation lets you solve a typical problem of this course yourself: A bank's fraud model flags unusually large transactions, while prices rise a little every week. Advance the weeks, watch drift (PSI) and accuracy, and retrain the model when the alarm goes off.
35.8Are you ready for this course?
35.8.1Prerequisites
| Course | Why it is needed |
|---|---|
| Machine Learning | deploying, monitoring and retraining models |
| Operating Systems | processes, memory and resource management: the concepts containers rely on |
| Object Oriented Programming with Java | the habit of writing modular, testable code |
| Software Engineering | version control (Git), testing and continuous integration |
35.8.2Ask yourself
For every "no", the right-hand column shows where to start. If you can say "yes" to most of them, you are ready.
| Question | If not, start with |
|---|---|
| Can you train a classifier and evaluate it with cross-validation? | Machine Learning |
| Can you create and merge branches in Git and resolve a merge conflict? | A short Git tutorial and a software engineering course |
| Can you manage processes, environment variables and permissions from the shell? | An operating systems course and an intro to the Linux shell |
| Can you write a modular Python project that has unit tests? | Object-oriented programming, then a short pytest tutorial |
35.9Neighboring courses
35.9.1Where it overlaps
| Relation | Course | Shared ground |
|---|---|---|
| application | This course applies the methods of Machine Learning | deploying, monitoring and retraining models |
| shares methods | Shares methods with Data Science | experiment tracking, data versioning |
| shares methods | Shares methods with Big Data Systems | data pipelines |
| shares methods | Shares methods with Embedded AI | deploying and updating models on devices |
35.9.2Where it differs
- Machine Learning: ML teaches how to build a good model; this course teaches how to keep it running reliably in production for months.
- Big Data Systems: Big data systems store and process data at scale; this course manages the lifecycle of models trained on that data.
- Data Science: Data science runs an analysis that answers a question; this course builds a service that runs, is monitored and is renewed.
- Embedded AI: Embedded AI fits the model onto a small device; this course deploys, versions and monitors it on servers.
35.10In practice
35.10.1Applications
| Area | What is done |
|---|---|
| Recommendation services | Models answering millions of requests a day. |
| Fraud detection | Decisions in milliseconds, frequent retraining. |
| Demand forecasting | Batch prediction jobs that run every night. |
| Search ranking | Models tested continuously with A/B tests. |
| Credit risk | Auditable, versioned and monitored models. |
| LLM services | Serving large models at scale and at high cost. |
35.10.2Risks and ethics
| Risk | Explanation |
|---|---|
| Silent decay | Without drift monitoring a model degrades with no errors; many demand forecasts lost their accuracy overnight when COVID-19 hit. |
| Training-serving skew | If a feature is computed differently in training and production, a model that tested well predicts wrongly live. |
| Feedback loops | A model retrained on the outcomes of its own decisions, such as a recommender or credit model, amplifies its own bias. |
| Untraceable versions | A model whose training data and code are unknown cannot be explained in a complaint or audit, nor rolled back. |
These issues are discussed in depth in Explainable AI and AI Ethics.
35.10.3Tools and datasets
Tools: MLflow, DVC, Docker, Kubernetes, Kubeflow, Apache Airflow, Prometheus.
Classic example scenarios: Credit model retrained monthly, Nightly demand forecast, Real-time fraud serving, Recommender with A/B testing, Simulating data drift, Rolling back a bad release.
The course teaches a process, not an algorithm: a small model is turned into an end-to-end pipeline, from training to monitoring.
35.11Common misconceptions
Once the model is trained, the job is done.
Data changes in production; an unmonitored model silently degrades over time.
MLOps is just installing tools.
Tools support the process; the real work is versioning, testing, ownership and rollback.
High test accuracy means good production performance.
Production data may differ from training data; latency and cost are part of success too.
Most of an ML system is the model.
Model code is a small part next to data, configuration, serving and monitoring infrastructure.
35.12Summary
- MLOps deals not with the model but with the system that runs it: pipeline, versioning, deployment and monitoring; the model code is a small part of the system.
- In serving, success is accuracy together with latency and cost; latency is read through the median and percentiles (p95, p99), not the mean, and capacity is estimated with Little's law (L = λ · W).
- Input distributions drift in production; a measure such as PSI compares the training and production distributions and raises an alert before labels arrive.
- A new version is opened gradually through a canary, a shadow deployment or an A/B test; whether a difference is significant is judged with a statistic such as z and a sample size computed in advance.
- Training-serving skew, silent decay and untraceable versions are the failures MLOps tries to prevent.
35.13Test Yourself
In a fraud model the feature "transaction count over the last 7 days" is computed in UTC in training and in local time in the live system. What problem is this and how is it prevented?
Answer
It is training-serving skew: the same feature is computed differently in two places, so the model tests well, performs badly live and raises no error. The fix is to produce the feature from one shared piece of code (a feature store) for training and serving, and to compare live feature values with training values.
The latencies of 10 requests (ms): 10, 11, 12, 12, 13, 14, 15, 16, 18, 100. Find the mean, the median and p90.
Answer
The total is 221, the mean 22.1 ms. The median is the average of the 5th and 6th values: (13 + 14) / 2 = 13.5 ms. p90: ⌈0.9 · 10⌉ = 9, so the 9th value, 18 ms. A single heavy request has inflated the mean.
A service receives 120 requests per second, a request takes 80 ms on average, and one replica handles 3 requests at once. How many replicas are needed at least? What is the utilization with 5 replicas?
Answer
L = 120 · 0.08 = 9.6; 9.6 / 3 = 3.2, so at least 4 replicas. With 5 replicas the capacity is 15 and utilization is 9.6 / 15 = 64%.
In training a feature falls in three equally populated bins with shares 1/3, 1/3, 1/3; in production the shares are 0.2, 0.3, 0.5. Compute the PSI.
Answer
Per-bin contributions: (0.2 − 0.3333) · ln(0.2/0.3333) ≈ 0.0681; (0.3 − 0.3333) · ln(0.3/0.3333) ≈ 0.0035; (0.5 − 0.3333) · ln(0.5/0.3333) ≈ 0.0676. The total is PSI ≈ 0.139: moderate drift.
In an A/B test, group A has 50 conversions out of 1000 users and group B has 56 out of 1000. Is the difference significant?
Answer
The difference is 0.006; the pooled rate is 106/2000 = 0.053; SE = √(0.053 · 0.947 · 2/1000) ≈ 0.0100; z ≈ 0.60. This is far below 1.96: not significant. The same rates with 10,000 users each give z ≈ 1.89, which is still below the threshold. The sample size must be chosen for the size of the difference we want to detect.
A team retrains its model every night and puts it into the product every morning, without recording which version was trained on which data. What happens when a customer questions a decision from a month ago? Which MLOps elements solve this?
Answer
Because the model and data versions are unknown, the decision cannot be reproduced, explained or, if needed, rolled back. The fix is to version data, code and model together (Git, DVC), to record every training run with its parameters and metrics (experiment tracking such as MLflow), and to keep approved versions in a model registry.
35.14After this course
MLOps is the backbone of the systems part of the guide: big data systems handle the training data, GPU programming the training speed, and embedded AI deployment at the edge. After this course, cloud platforms, distributed training or serving large language models are natural next steps.
Related careers: MLOps engineer, Machine learning engineer, Data engineer, Platform engineer, Site reliability engineer (SRE).
35.15Further reading
- C. Huyen, Designing Machine Learning Systems (2022): covers production systems end to end, from data to deployment and from monitoring to drift; it spans most topics of these notes.
- D. Sculley et al., "Hidden Technical Debt in Machine Learning Systems" (NeurIPS 2015): the short, foundational paper on why machine learning systems are expensive to maintain.
- A. Burkov, Machine Learning Engineering (2020): a practical account of a project from requirements through production and maintenance.
35.16References
- Huyen, Designing Machine Learning Systems, O'Reilly, 2022.
- Burkov, Machine Learning Engineering, True Positive Inc., 2020.
- Lakshmanan, Robinson and Munn, Machine Learning Design Patterns, O'Reilly, 2020.
- Sculley et al., "Hidden Technical Debt in Machine Learning Systems", NeurIPS, 2015.
Related pages: Slides · Slides (PDF) · Course page