๐ข The situation
The churn model (modules 5โ10) still lives as "a notebook Igor runs on Mondays". Lena:
"Embarrassing to admit, but that's the truth of half the industry. Time to grow up: the model must become a service โ with an API, versioning, monitoring and a plan for 'everything is broken'. Wrap it in FastAPI + Docker, set up drift monitoring. This is the last skill separating you from a middle: a model that can't be operated reliably doesn't exist."
๐ฏ Your task
- Wrap the model in a REST API (FastAPI) and a container (Docker).
- Understand model versioning and reproducibility.
- Set up monitoring: service metrics, data drift, quality.
๐ Theory
Maturity levels of ML systems
- A notebook + manual runs ("us, today").
- Model as a service: API, container, CI/CD, versions.
- An automated pipeline: retraining on schedule/trigger, validation gates.
- Full MLOps: feature store, model registry, automatic rollback, model A/B.
Most teams only need levels 1โ2. Don't build level 3 for the badge.
The model as an artifact
- Serialization: joblib/pickle (โ ๏ธ library versions must match!), ONNX โ a portable format.
- Versioning: the model + code + data + metrics are pinned together (MLflow Model Registry, W&B). The question "which model is in production and what was it trained on?" must be answerable in 10 seconds.
- Reproducibility: pinned random_state, package versions (a lock file), code in git.
The three layers of ML service monitoring
- Service (like any backend): p50/p99 latency, RPS, 5xx errors.
- Data drift: the input feature distribution has drifted from training (a new customer segment, a broken field in a source). Metrics: PSI, KS test per feature. Prediction drift โ a shift in the score distribution โ is the cheapest early signal.
- Quality (concept drift): true labels arrive late (we learn about churn 30 days later) โ compute delayed quality, compare with the offline estimate.
The rule: a model without monitoring is an incident that hasn't happened yet. Data always changes.
Model rollout strategies
- Shadow mode: the new model predicts in parallel; answers are logged but not used. A free check on real traffic.
- Canary: 5% of traffic to the new model; metrics fine โ roll out.
- Rollback: the previous version always on standby; switching by config, not by deployment.