MLOps
Taking models to production and keeping them working — the ML lifecycle, data and feature pipelines, feature stores, experiment tracking and model registries, training pipelines, batch vs online serving, monitoring for data and concept drift, retraining, A/B testing, and LLMOps.
Training a model in a notebook is the easy part. Industry surveys repeatedly find that most ML projects never reach production, and many that do quietly degrade. MLOps applies DevOps practices — automation, versioning, testing, monitoring (CI/CD) — to the whole machine learning lifecycle.
Why ML systems are different
| Traditional software | ML systems |
|---|---|
| Behaviour defined by code | Behaviour defined by code + data + trained weights |
| Tests catch most regressions | Models can be "correct" code yet make worse predictions |
| Stable once deployed | Decay as the world changes (drift) |
| Version the code | Version code, data, features, models and configs |
The famous "Hidden Technical Debt in Machine Learning Systems" paper observed that model code is a tiny box surrounded by much larger systems: data collection, verification, feature extraction, serving infrastructure, monitoring and configuration.
The lifecycle
Data and features
- Data validation: check schemas, ranges, null rates and distributions on every new batch before training (Great Expectations, TFDV, Pandera). Bad data silently produces bad models.
- Data versioning: reproduce exactly which data trained which model (DVC, lakeFS, Delta Lake/Iceberg time travel).
- Labelling: quality matters more than quantity; measure agreement between annotators.
Training–serving skew and feature stores
A classic production bug: features computed one way in a training pipeline (Python over a warehouse) and another way in the live service (Java over a request) — the model sees different inputs in production. A feature store (Feast, Tecton, Databricks, Vertex AI) defines each feature once and serves it:
- Offline: historical values for training, with point-in-time correctness (the value as of each training example's timestamp — avoiding leakage, see Model evaluation).
- Online: low-latency latest values for real-time inference.
Experiments and the model registry
Track every training run — code version, data version, hyperparameters, metrics, artefacts — so results are comparable and reproducible:
import mlflow
with mlflow.start_run():
mlflow.log_params({"model": "lightgbm", "num_leaves": 63, "learning_rate": 0.03})
model = train(X_train, y_train)
mlflow.log_metrics({"val_auc": auc(model, X_val, y_val), "val_f1": f1(model, X_val, y_val)})
mlflow.sklearn.log_model(model, "model", registered_model_name="churn-classifier")A model registry (MLflow, Weights & Biases, SageMaker, Vertex AI) stores versioned models with lineage and stages (staging → production → archived), so deployment and rollback refer to an exact version.
Training pipelines
Automate the steps — ingest → validate → featurise → train → evaluate → register — as a pipeline (Airflow, Dagster, Kubeflow, Vertex/SageMaker Pipelines, Metaflow). Add quality gates: only promote a model that beats the current production model on held-out data and passes checks for performance on important slices, fairness, latency and size.
Serving
| Pattern | How | Use when |
|---|---|---|
| Batch | Score all rows on a schedule; write predictions to a table | Daily churn scores, recommendations precomputed overnight |
| Online (real-time) | A service answers each request in milliseconds | Fraud checks at payment time, search ranking |
| Streaming | Score events as they flow through Kafka/Flink | Real-time anomaly detection (Stream processing) |
| On-device / edge | Model runs on phones or browsers | Privacy, offline use, latency (Core ML, TFLite, ONNX Runtime, WebGPU) |
Online serving concerns: latency budgets, autoscaling, GPU utilisation, batching requests, model formats (ONNX, TorchScript), serving frameworks (Triton, TorchServe, BentoML, KServe, vLLM for LLMs), and graceful fallbacks when the model is slow or down (a rule-based default).
Safe rollout
- Shadow mode: run the new model alongside production, log its predictions, compare — no user impact.
- Canary then gradual rollout (CI/CD).
- A/B tests measure the business metric (conversion, revenue, retention), not just offline accuracy — better offline metrics don't always mean better outcomes.
Monitoring and drift
Models degrade because the world changes:
| Drift | Meaning | Example |
|---|---|---|
| Data (covariate) drift | Input distribution changes | A new app version changes how a feature is recorded; a new customer segment |
| Concept drift | The relationship between inputs and the target changes | Fraudsters adapt; spending patterns shift in a pandemic |
| Label drift | Target distribution changes | Seasonal demand |
What to monitor:
- Operational: latency, throughput, errors, resource usage (Monitoring and SRE).
- Data quality: missing values, out-of-range inputs, schema changes.
- Distribution shift: compare live feature and prediction distributions with training (Population Stability Index, KL divergence, Kolmogorov–Smirnov tests).
- Model quality: actual accuracy once ground-truth labels arrive — often delayed (did the loan default? took months), so use proxies meanwhile.
- Slices and fairness: performance per segment.
Retraining can be scheduled (weekly), triggered by drift or performance alerts, or continuous — always through the same validated pipeline with quality gates.
Responsible ML in production
- Explainability: SHAP values or feature importances for individual decisions where regulation or trust requires it (credit, healthcare).
- Fairness audits across demographic groups.
- Privacy: minimise personal data, control access, consider differential privacy or federated learning.
- Documentation: model cards and datasheets describing intended use, data, evaluation and limitations.
- Feedback loops: a recommender shapes the clicks it later trains on — watch for self-reinforcing bias.
LLMOps
Applications built on LLMs (LLMs, RAG) need their own operational practices:
| Concern | Practice |
|---|---|
| Prompts are code | Version prompts; review changes; test against evaluation sets before release |
| Non-deterministic output | Eval suites with exact checks, LLM-as-judge rubrics and human review |
| Model upgrades | Re-run evals before switching models; pin versions |
| Cost and latency | Track tokens per request, caching, routing easy requests to smaller models |
| Observability | Trace every call: prompt, retrieved documents, tool calls, output, latency, cost |
| Safety | Input/output filters, prompt-injection defences, PII redaction, rate limits |
| Feedback | Collect user ratings and failure cases to grow the eval set |
- MLOps manages code, data and models together; ML systems decay as the world changes.
- Validate and version data; use feature stores to avoid training–serving skew and leakage.
- Track experiments and register versioned models with lineage.
- Automate training pipelines with quality gates; serve in batch, online, streaming or on-device.
- Roll out via shadow, canary and A/B tests on business metrics.
- Monitor operations, data quality, drift and delayed ground truth; retrain through the same pipeline.
- LLMOps adds prompt versioning, eval suites, tracing, cost control and safety filters.