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.

Intermediate 5 min readLesson 14 of 14

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 softwareML systems
Behaviour defined by codeBehaviour defined by code + data + trained weights
Tests catch most regressionsModels can be "correct" code yet make worse predictions
Stable once deployedDecay as the world changes (drift)
Version the codeVersion 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

Datacollect, validate, labelFeaturespipelines, storeTrain + evaluatetracked experimentsRegistryversioned modelsServebatch / onlineMonitordrift, qualityRetrain trigger

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:

Python
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

PatternHowUse when
BatchScore all rows on a schedule; write predictions to a tableDaily churn scores, recommendations precomputed overnight
Online (real-time)A service answers each request in millisecondsFraud checks at payment time, search ranking
StreamingScore events as they flow through Kafka/FlinkReal-time anomaly detection (Stream processing)
On-device / edgeModel runs on phones or browsersPrivacy, 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:

DriftMeaningExample
Data (covariate) driftInput distribution changesA new app version changes how a feature is recorded; a new customer segment
Concept driftThe relationship between inputs and the target changesFraudsters adapt; spending patterns shift in a pandemic
Label driftTarget distribution changesSeasonal 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:

ConcernPractice
Prompts are codeVersion prompts; review changes; test against evaluation sets before release
Non-deterministic outputEval suites with exact checks, LLM-as-judge rubrics and human review
Model upgradesRe-run evals before switching models; pin versions
Cost and latencyTrack tokens per request, caching, routing easy requests to smaller models
ObservabilityTrace every call: prompt, retrieved documents, tool calls, output, latency, cost
SafetyInput/output filters, prompt-injection defences, PII redaction, rate limits
FeedbackCollect user ratings and failure cases to grow the eval set
Key takeaways
  • 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.