Designing a Leak-Free Weekly Churn Model Pipeline
Machine LearningModel answerLast updated
Design a weekly batch churn-prediction system for millions of subscribers, covering leakage-free features, rare positives, time-aware validation, metrics, and drift monitoring.
Scenario: Predicting Who Won't Renew Next Week
A video streaming service has tens of millions of subscribers. Each week it wants to identify the subscribers who will not renew during the following seven days, so the retention team can contact them. You can draw on three sources: app and playback activity logs, billing and payment history, and content engagement data.
Roughly 2-5% of subscribers up for renewal churn in a typical week.
What to design
Describe a production-grade, scalable pipeline that answers each of the following:
- Preventing time-based leakage. How do you guarantee that features used for a given prediction date contain only information that was truly available at that moment?
- Rare positives. What do you do about the heavy imbalance during training, and during evaluation?
- Validation that mirrors production. Since the model is retrained and applied every week, what splitting scheme gives you an honest estimate of live performance?
- Running it in production. How do you detect both changes in the input data and changes in the relationship between inputs and churn once the model is live?
Deliverables
- A text description of the end-to-end architecture (data ingestion through scoring and monitoring).
- A justified choice of evaluation metrics. Compare ROC-AUC, PR-AUC, precision/recall at a contact budget, and a cost-weighted measure.
- The workflow that produces weekly feature snapshots for all users efficiently.
State any assumptions you make (scale, label definition, how scores will be used).
Hints
Hint 1
Start by pinning down the label precisely: what is the snapshot time, which users are eligible, and when does the outcome become known (including payment retries)? Every leakage and validation decision follows from that.
Hint 2
Think about the gap between the prediction date and the date labels mature. A validation fold that ignores that delay will look better than production. Also ask why random row-level K-fold is wrong when each user appears in many weeks.
Hint 3
For metrics, ask what the score is used for: a fixed contact budget and a discount cost. That points to ranking quality at the top of the list, calibration, and an expected-value threshold, not a single global number. For monitoring, separate checks that need no labels from checks that must wait for labels.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Framing
The key question is whether offline results predict production behavior, and whether the pipeline can run weekly at scale. I would anchor everything on a precise label and a point-in-time snapshot.
1. Assumptions
- Label: At snapshot time
t(say Sunday 00:00 UTC),y = 1if a user with an active subscription whose renewal falls in(t, t+7d]fails to renew. Allow a grace period for payment retries before finalizing the label. Users not up for renewal are excluded or handled by a separate model. - Scale: about 50M subscribers, 2-5% churn, about 10B events per week.
- Use: Scores feed a limited retention budget (for example, the top 500k users get an offer). So ranking at the top and calibrated probabilities both matter.
- Serving: Mostly weekly batch scoring, plus an optional online path for real-time triggers such as visiting the cancel page.
2. Architecture
Events (playback, app, billing, support) -> stream -> data lake (partitioned by date)
-> daily incremental aggregation (Spark) -> per-user daily aggregates
-> weekly snapshot job at t (point-in-time) -> features_t (offline feature store)
-> label job at t+7d+grace -> labels_t
-> training set builder (only matured weeks)
-> rolling backtest + training (gradient-boosted trees) -> registry + calibration
-> batch scoring at t -> CRM / campaigns
-> online feature store + model server (optional real-time path)
-> monitoring: feature drift, score drift, delayed-label metrics, calibration
3. Weekly snapshots at scale
- Daily increments. Each day compute per-user aggregates (watch minutes, sessions, distinct titles, failed payments, support contacts) for that day only, partitioned by date. Never rescan raw history.
- Weekly roll-up. At
t, combine daily partitions into windows (7/14/28 days), trends (last 7 over previous 7), recency (days since last session), tenure, plan, price changes, days to renewal. A 28-day feature reads 28 small partitions. - Immutable storage. Write
features_tkeyed by(user_id, snapshot_date); never overwrite. This makes training sets reproducible and backfills safe. - Late labels. A separate job writes labels once the renewal window and retry grace have closed.
4. Temporal integrity
- Every feature uses events with
event_time <= t. For slowly changing attributes (plan, auto-renew flag) use an as-of join (valid_from <= t < valid_to), never the current row. - Filter late-arriving events by ingestion time, or model the lag, so the snapshot reflects what was knowable at
t. - Exclude retries, refunds, and cancellations dated after
t. Beware monthly aggregates that straddlet. - Use the same feature code for training and serving to avoid train/serve skew.
- Label maturity gap: at deployment date
T, the newest labeled snapshot is at least about 7 days old. Training must respect that gap. - Never use random K-fold over rows: the same user appears in many weeks, so the model effectively sees the future.
5. Class imbalance
- Gradient-boosted trees cope well with about 3% positives. Start with no resampling.
- To cut cost on hundreds of millions of rows, downsample negatives (keep 10-20%) or use class weights.
- Skip SMOTE for behavioral tabular data: little benefit, more complexity.
- Evaluate only on untouched, naturally distributed weeks. Resampling is a training-time trick.
- Resampling distorts probabilities, so recalibrate (isotonic or Platt on a recent held-out week) or correct the prior analytically.
6. Validation
Use a rolling-origin backtest that simulates weekly retraining:
| Fold | Train | Gap | Validate |
|---|---|---|---|
| 1 | weeks 1-26 | 1 week | week 28 |
| 2 | weeks 2-27 (sliding) or 1-27 (expanding) | 1 week | week 29 |
- Run 8-12 folds; report mean and variance, and look for a downward trend.
- Compare sliding vs expanding windows to see how much old data helps under drift.
- Select models on recent folds; keep a final untouched holdout of the newest weeks.
- Also test across seasonal periods (holidays, big releases).
7. Metrics
- ROC-AUC: insensitive to prevalence, which makes it overly optimistic here. With 97% negatives, many false positives barely move the false-positive rate. Report as secondary.
- PR-AUC (average precision): the primary ranking metric because it focuses on positives. Its random baseline equals prevalence, so compare weeks using lift over prevalence.
- Precision/recall at budget k: the most business-aligned view ("of the 500k we can contact, how many are churners?").
- Expected value:
value = TP*(save_rate*CLV - offer_cost) - FP*offer_cost, with missed churners costing CLV. Choose the threshold or k that maximizes it. This beats F1 because it encodes real cost asymmetry. - Calibration: Brier score, reliability curve, ECE. Needed if scores drive budgeting.
Long term, note that churn propensity is not treatment effect; use a randomized holdout or uplift modeling to measure whether the offers actually help.
8. Monitoring
Without labels (immediate):
- Feature drift: compare each scoring snapshot to the training reference with PSI or KS tests (for example, PSI above roughly 0.2 triggers review). Also track null rates, ranges, and schema.
- Score drift: monitor the score distribution and the share of users above threshold.
- Pipeline health: row counts, freshness, join coverage.
With delayed labels (about 1-2 weeks later):
- Track PR-AUC lift, precision at k, and calibration per week against the backtest baseline.
- Segment by plan, tenure, region, and acquisition channel to catch localized concept drift.
- Concept drift shows as stable inputs but falling performance or miscalibration, for example after a pricing change or a competitor launch.
Responses: alert, then recalibrate, retrain on a fresher window, or roll back via the registry. Weekly retraining with champion/challenger comparison and a shadow period keeps changes safe.
Common mistakes
- Random splits or features computed with "current" table values.
- Ignoring the label-maturity gap in validation.
- Evaluating on resampled data, or using uncalibrated scores for budget decisions.
- Reporting only ROC-AUC.
- Monitoring only inputs and never checking delayed-label performance.