Skip to content
  • Deployment, Monitoring & MLOps · Machine Learning

Deployment, Monitoring & MLOps

LearnViaNotes @learnvianotes· 4 min read

A model creates value only in production — and production data changes. Deploy safely, monitor inputs, outputs and outcomes, and automate retraining. MLOps is the engineering discipline that makes this repeatable.

Serving patterns

PatternHowExample
BatchScore everything on a schedule, store resultsNightly churn scores for the CRM
Online (real-time)A service answers each request (REST/gRPC) in millisecondsFraud check at payment time
StreamingScore events from a queue (Kafka) as they arriveAnomaly alerts on sensor streams
Edge / on-deviceModel runs on the phone or deviceKeyboard suggestions, offline vision

Rolling out safely

StrategyHowCatches
ShadowNew model scores live traffic, but its outputs are only loggedCrashes, latency, training–serving skew — no user risk
CanaryRoute a small % of traffic to the new model, grow it graduallyProblems at small blast radius
A/B testRandomised split, compare business metricsWhether it actually helps (see A/B Testing)
Blue–green + rollbackKeep the previous version ready to switch back instantlyAnything missed above

Why models decay: drift

TypeWhat changesExample
Covariate (data) shiftP(X) changes, P(y | X) staysA marketing campaign brings younger users
Label (prior) shiftP(y) changesFraud rate doubles during a holiday season
Concept driftP(y | X) changes — the same inputs now mean something elseSpending patterns after a price shock; fraudsters change tactics
Upstream data changesA pipeline bug, unit change or new categoryA field starts arriving in cents instead of dollars

Measuring input drift

PSI = Σ_bins (actual% − expected%) · ln(actual% / expected%) < 0.1 stable · 0.1–0.25 moderate · > 0.25 major shift

Python
import numpy as np
from scipy.stats import ks_2samp

rng = np.random.default_rng(0)
train = rng.normal(50, 10, 10000)                 # feature at training time
same = rng.normal(50, 10, 5000)                   # production, unchanged
shifted = rng.normal(56, 12, 5000)                # production, drifted

def psi(expected, actual, bins=10):
    edges = np.quantile(expected, np.linspace(0, 1, bins + 1))
    edges[0], edges[-1] = -np.inf, np.inf
    e = np.histogram(expected, edges)[0] / len(expected)
    a = np.histogram(actual, edges)[0] / len(actual)
    e, a = np.clip(e, 1e-6, None), np.clip(a, 1e-6, None)
    return float(np.sum((a - e) * np.log(a / e)))

print(round(psi(train, same), 3), round(psi(train, shifted), 3))                          # 0.002 0.293
print(round(ks_2samp(train, same).statistic, 3), round(ks_2samp(train, shifted).statistic, 3))   # 0.008 0.22 ← KS distance

What to monitor

LayerSignals
Service healthLatency, throughput, error rate, memory
Data qualitySchema, missing-value rates, out-of-range values, unseen categories
Input driftPSI / KS per important feature
Prediction driftDistribution of scores and predicted classes; share of positives
Model performanceAccuracy/precision/recall or error once labels arrive — often delayed by days or weeks
Business KPIsConversion, fraud losses, complaints

Retraining

  • Scheduled — retrain weekly/monthly on a sliding window; simple and predictable.

  • Triggered — retrain when drift or performance alerts fire.

  • Continuous / online — incremental updates (partial_fit) for fast-moving data.

  • Always validate the new model against the current one on recent data before promoting it; retraining on bad (buggy, poisoned) data makes things worse.

MLOps practices

PracticeWhyTools (examples)
Version code, data and modelsReproduce any model and debug regressionsGit, DVC, lakeFS
Experiment trackingCompare runs, parameters, metrics, artefactsMLflow, Weights & Biases
Model registryStaging → production promotion, lineage, rollbackMLflow Model Registry, SageMaker, Vertex AI
Feature storeSame feature definitions offline (training) and online (serving)Feast, Tecton
CI/CD/CTAutomated tests, builds, deployments — and continuous trainingGitHub Actions, Kubeflow, Airflow
Data validationCatch schema and distribution problems before training/servingGreat Expectations, TFDV, pandera
DocumentationIntended use, data, metrics by slice, limitationsModel cards, datasheets for datasets

How do you detect and handle model drift in production?

What is the difference between covariate shift and concept drift?

Shadow vs canary deployment?

Free for students and teachers

Write notes like this one

Cards for every idea, quizzes and flashcards, read aloud — on the web and your phone.

Something wrong with this note? Open it to report