← Back to Index

13. Monitoring & Drift Detection

Infrastructure Monitoring

MetricAlert ThresholdAction
p99 latency > 500ms5 minutesAuto-scale, investigate bottleneck
Error rate > 1%2 minutesRollback model, page on-call
Throughput drop > 50%1 minuteCheck upstream, health of replicas
GPU utilization > 95%10 minutesAdd GPU instances, check batching

Model Performance Monitoring

When ground truth is available (with delay), compute model accuracy:

# Model accuracy monitoring (delayed labels)
Prediction at t=0: fraud_score=0.92
Ground truth at t=24h: confirmed_fraud=True

Weekly report:
  Precision@threshold=0.5: 0.83  (was 0.85 last week) ⚠
  Recall@threshold=0.5:    0.76  (was 0.78 last week)  ⚠
  Alert if drop > 0.02

Drift Detection

Drift is the most common cause of silent ML system degradation.

Types of Drift

TypeWhat ChangesDetection Method
Data (feature) driftInput features distribution shiftsKS test, PSI, chi-squared
Concept driftRelationship between features and target changesAccuracy monitoring, residual analysis
Label driftGround truth distribution shiftsLabel distribution tracking
Upstream driftSource data changes (schema, quality)Data validation, schema checks
# Drift detection with PSI (Population Stability Index)
psi = sum((p_i - q_i) * log(p_i / q_i))
# p_i = proportion in serving data, q_i = proportion in training data
# PSI < 0.1: no drift
# PSI 0.1—0.25: moderate drift (investigate)
# PSI > 0.25: severe drift (retrain immediately)

Prometheus + Grafana Dashboard

Recommended panels:

  1. Latency heatmap (p50/p95/p99 over time)
  2. Throughput (requests/sec by model version)
  3. Error rate (% by error type)
  4. Cache hit ratio (feature + prediction)
  5. Fallback usage rate (% of requests using fallback model)
  6. Feature drift scores per feature (top-10 most drifted)
  7. Model accuracy (when ground truth available)
  8. GPU/CPU/memory utilization per replica

Alerting Strategy

Exercise: Design the monitoring system for an ML-based credit scoring API. Define: a) 6 Grafana dashboard panels with chart type and metric source, b) 4 alert rules with thresholds and severity levels, c) drift detection configuration (which features to monitor, test frequency, retraining trigger), d) how you handle delayed ground truth (loans default after 90 days).