System Designhard•DECEMBER 2026•20 MIN
Design a Real-Time Recommendation Pipeline
Two-stage candidate generation and ranking, online/offline feature store skew prevention, and freshness caches at Netflix scale.
candidate generationfeature storestreaming ingestionmulti-tier cacheml-systemsrecsysstreaming
1. Clarifying questions & SLO contract
- Scale:
10Mactive items,200MDAU,100Kfeed QPS,500Kclick/watch events/sec. - Latency SLO: End-to-end feed generation
p99 ≤ 60 ms. - Freshness: In-session clicks from
2–5 secondsago must visibly shift the very next feed refresh.
2. Back-of-envelope sizing
- Why a single model cannot score 10M items: Scoring
10Mitems with a cross-feature DNN at100K QPSis10^12inferences/sec — impossible within60 ms. - Multi-stage funnel:
- Candidate Generation (Two-Tower ANN):
10M → 500items (~8 ms). - Pre-Rank Filtering (Bloom + Policy):
500 → 180items (~3 ms). - Feature Hydration (Redis Online Store):
180item + user vectors (~6 ms). - Heavy DNN Ranker + MMR Re-Ranker:
180 → 20items (~18 ms, total~35 ms).
- Candidate Generation (Two-Tower ANN):
3. Interactive multi-stage RecSys funnel simulator
Toggle between Batch Features (24h stale) and Streaming Store (2s fresh) to trace latency, candidate pruning, and in-session relevance:
LOADING RECSYS FUNNEL SIM...
4. Deep dive: preventing training-serving skew
- Dual-sink Feature Store (Flink → Redis + Iceberg): Kafka click streams feed Flink sliding-window aggregations (
5m,1h,24hCTR/dwell counters) written simultaneously to Redis (online serving) and Iceberg/Parquet (offline history). - Log-and-Wait training datasets: Instead of recomputing features offline from raw logs during training, log the exact feature vector seen at serving time alongside
request_id, then join with delayed click/watch labels. This eliminates online/offline feature skew bit-for-bit. - MMR / Determinantal diversity re-ranking: Pure pointwise CTR ranking floods the top 20 with near-duplicate topics. Maximal Marginal Relevance penalizes items too similar to already-selected slots.
5. Failure modes & trade-offs
| Tension | Trade-off & Mitigation |
|---|---|
| Feature store timeout | Bounded 8 ms Redis MGET timeout; fallback to cached user/item defaults or popularity ranker rather than failing the feed. |
| Cold-start items | Content-based image/text two-tower embeddings + explore/exploit Thompson sampling boost for newly published items. |
| Feedback loops | Reserve 5% randomized exploration slots and log propensity scores for unbiased IPS offline evaluation. |