Skip to main content
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: 10M active items, 200M DAU, 100K feed QPS, 500K click/watch events/sec.
  • Latency SLO: End-to-end feed generation p99 ≤ 60 ms.
  • Freshness: In-session clicks from 2–5 seconds ago must visibly shift the very next feed refresh.

2. Back-of-envelope sizing

  • Why a single model cannot score 10M items: Scoring 10M items with a cross-feature DNN at 100K QPS is 10^12 inferences/sec — impossible within 60 ms.
  • Multi-stage funnel:
    1. Candidate Generation (Two-Tower ANN): 10M → 500 items (~8 ms).
    2. Pre-Rank Filtering (Bloom + Policy): 500 → 180 items (~3 ms).
    3. Feature Hydration (Redis Online Store): 180 item + user vectors (~6 ms).
    4. Heavy DNN Ranker + MMR Re-Ranker: 180 → 20 items (~18 ms, total ~35 ms).

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

  1. Dual-sink Feature Store (Flink → Redis + Iceberg): Kafka click streams feed Flink sliding-window aggregations (5m, 1h, 24h CTR/dwell counters) written simultaneously to Redis (online serving) and Iceberg/Parquet (offline history).
  2. 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.
  3. 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

TensionTrade-off & Mitigation
Feature store timeoutBounded 8 ms Redis MGET timeout; fallback to cached user/item defaults or popularity ranker rather than failing the feed.
Cold-start itemsContent-based image/text two-tower embeddings + explore/exploit Thompson sampling boost for newly published items.
Feedback loopsReserve 5% randomized exploration slots and log propensity scores for unbiased IPS offline evaluation.

Related Lab Entries