Design an End-to-End Video Recommendation Platform
Machine LearningModel answerLast updated
Architect an end-to-end video recommendation system covering objective setting, matrix factorization baselines, multi-stage retrieval/ranking, feature engineering, and evaluation strategies.
Architect an end-to-end personalized video recommendation platform for a high-volume streaming network (e.g., millions of active subscribers and tens of thousands of catalog items).
Your architecture should address the full machine learning product life cycle:
- Product Objectives & Metrics: Define target business objectives, optimization targets, and guardrail metrics. Address scale, throughput, and latency constraints.
- Data Pipeline & Schema: Outline core data streams, online feature serving, offline training stores, and logging mechanisms for explicit/implicit interactions.
- Modeling & Candidate Retrieval: Detail an initial collaborative filtering baseline (such as Implicit Matrix Factorization / Non-Negative Matrix Factorization) alongside a multi-stage funnel (Retrieval -> Heavy Ranker -> Re-ranking). Explain how the baseline scales and how it transitions to deep/two-tower architectures.
- Feature Engineering & Dataset Construction: Explain feature generation, point-in-time logging, negative sampling strategies, and methods to counter position or popularity biases.
- Evaluation, Cold-Start, & Rollout: Define offline metrics (e.g., NDCG, MAP, Recall@K), online A/B testing approaches, strategies for new users/items (cold start), continuous feature freshness, and live system monitoring.
Hints
Hint 1
Structure your system as a multi-stage funnel: fast candidate generation (retrieval) followed by scoring (ranking) and policy filtering (re-ranking).
Hint 2
Clearly distinguish explicit feedback (ratings, thumbs up) from implicit signals (play durations, clicks, impression skips), noting how implicit signals form the bulk of training labels.
Hint 3
Address position bias explicitly in the ranker—either by introducing impression position as a baseline feature during training or via inverse propensity scoring.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
1. Requirements, Scale & Objectives
Clarifying Objectives
- Primary Objective: Maximize long-term subscriber engagement, measured by total qualified watch time (e.g., viewing sessions lasting $\ge 2$ minutes or covering $\ge 20%$ of video duration) and 30-day retention.
- Secondary Metrics: Click-through rate (CTR) on homepage components, conversion rate from click to long view.
- Guardrail Metrics: Catalog coverage, intra-list genre diversity, novelty (ratio of tail content served), response latency ($p99 < 150\text{ ms}$), and candidate churn rate.
Operational Scale Assumptions
- Users: 60 million Monthly Active Users (MAU), 12 million Daily Active Users (DAU).
- Catalog: 100,000 video titles; ~200 new titles added per week.
- Traffic volume: 12 million DAU generating ~40 million homepage feed requests daily $\approx 460$ average QPS, peaking at $2,500$ QPS.
- Telemetry Stream: ~1.5 billion raw impression and play events per day.
2. High-Level Architecture & API Design
The recommendation pipeline follows a standard multi-stage funnel:
[ Catalog (100k) ]
│
▼ < 30ms
┌─────────────────────────┐
│ Candidate Generation │ --> Retain top ~1,000 items
│ (ANN / MF / Co-watch) │
└───────────┬─────────────┘
│
▼ < 80ms
┌─────────────────────────┐
│ Scoring & Heavy Ranking │ --> Score & filter to ~200 items
│ (GBDT / Two-Tower / DNN)│
└───────────┬─────────────┘
│
▼ < 20ms
┌─────────────────────────┐
│ Re-ranking & Diversity │ --> Final ~20-50 ranked items
│ (MMR / Business Rules) │
└─────────────────────────┘
API Specification
// POST /api/v1/recommendations
// Request Header
{
"user_id": "usr_9983120",
"device": "smart_tv",
"locale": "en_US",
"surface": "home_feed",
"limit": 20
}
// Response
{
"request_id": "req_881a293b",
"items": [
{
"item_id": "vid_40192",
"score": 0.942,
"explanation_code": "COLLECTIVE_FILTERING_SIMILAR"
}
]
}
Every delivered payload logs the request_id to correlate displayed positions with downstream user interactions (impression, click, playback duration).
3. Core Baseline & Multi-Stage Modeling Strategy
Stage 1: Candidate Generation (Retrieval)
To trim 100,000 titles to ~1,000 candidates within a 30 ms budget, we run diverse parallel retrievers:
- Implicit Matrix Factorization (ALS):
Given implicit interaction matrix $R$ where $r_{ui}$ represents watch confidence:
$$\min_{U, V} \sum_{u, i} c_{ui} \left( p_{ui} - u_u^T v_i \right)^2 + \lambda \left( |u_u|_2^2 + |v_i|_2^2 \right)$$
Where:
- $p_{ui} = 1$ if $r_{ui} > 0$, else $0$.
- $c_{ui} = 1 + \alpha \cdot \log(1 + \text{watch_time})$. Non-observed entries are treated as weak negative signals. The learned item vector space is indexed via Hierarchical Navigable Small World (HNSW) graphs in an Approximate Nearest Neighbor (ANN) engine (e.g., Milvus, FAISS) for low-latency similarity queries.
- Item-Item Co-Watch Graph: Precomputed co-occurrence matrix from recent short-term aggregate session data.
- Popularity/Trending & Real-time Context: Top titles stratified by geographic locale and temporal velocity.
Stage 2: Heavy Ranker
Takes the top ~1,000 candidates and ranks them using a rich feature space.
- Phase 1: Gradient Boosted Decision Trees (LightGBM/XGBoost) predicting $P(\text{Click})$ and expected log watch time.
- Phase 2 (Target Evolution): Multi-Task Deep Neural Networks (e.g., Shared-Bottom or MMoE architectures) predicting dual heads: $P(\text{Click})$ and $P(\text{Qualified Play} \mid \text{Click})$. Combined final score: $$\text{Score} = P(\text{Click}) \times P(\text{Qualified Play} \mid \text{Click})^\gamma \times \mathbb{E}[\text{Watch Time}]$$
Stage 3: Re-ranking & Business Rules
- Deduplication: Remove items watched in the past 30 days.
- Diversity Constraint: Apply Maximal Marginal Relevance (MMR) or deterministic genre caps (max 3 titles of the same genre per feed row).
- Exploration Allocation: Reserve 5% of candidate slots for epsilon-greedy or Thompson-sampled exploration of long-tail/new catalog items.
4. Feature Engineering & Training Pipeline
Feature Matrix
| Category | Feature Description | Update Latency |
|---|---|---|
| User Demographics | User age tier, subscription tier, country, preferred language | Batch (Daily) |
| User Activity | 7-day/30-day mean watch time, favorite genres (decayed histogram) | Real-time / Streaming (Flink) |
| Item Features | Genre tags, release age, historical completion rate, embedding vectors | Batch / Near-Real-Time |
| Contextual | Time of day, day of week, network bandwidth tier, device type | Real-time (Request time) |
| Cross-Interaction | Dot product of User & Item vectors, days since user last viewed genre | Real-time |
Training Set Construction & Anti-Bias Strategies
- Negative Sampling: Standard non-clicked impressions introduce selection bias. We combine:
- Hard Negatives: Items displayed to the user in the feed that were ignored.
- In-Batch / Random Negatives: Randomly selected items from the active catalog to stabilize the candidate retrieval distribution.
- Position Bias Mitigation: Position heavily impacts CTR. Incorporate presentation position as a feature during training (e.g., $\text{position_idx}$). At serving time, evaluate all candidate pairs under a uniform control setting (e.g., setting $\text{position_idx} = 0$).
TRAINING TIME SERVING TIME
┌────────────────────────────────┐ ┌────────────────────────────────┐
│ User/Item Features │ │ User/Item Features │
│ Position Feature = Actual Pos │ │ Position Feature = Constant (0)│
└───────────────┬────────────────┘ └───────────────┬────────────────┘
│ │
▼ ▼
┌────────────────────┐ ┌────────────────────┐
│ Learn True Content │ │ Unbiased Content │
│ Signal w/ Pos Bias │ │ Model Predictions │
└────────────────────┘ └────────────────────┘
5. Offline & Online Evaluation Framework
Offline Evaluation Metrics
Offline benchmarks are calculated against held-out time-sliced interaction datasets (e.g., train on Days 1–28, evaluate on Days 29–30):
- Retrieval: $\text{Recall}@K$ ($K=500$) to check if true consumed titles pass candidate retrieval.
- Ranking Quality:
- $\text{NDCG}@10$ (Normalized Discounted Cumulative Gain) using watch-time-weighted relevance levels.
- Mean Average Precision ($\text{MAP}@10$).
- Diversity & Coverage: Intra-List Distance (ILD) based on genre vector distances and overall Catalog Coverage percentage.
Online A/B Testing Protocol
- Traffic Split: Divert 90% of traffic to current production (Control), 5% to Baseline (ALS MF), and 5% to Multi-Task Deep Learning Ranker (Treatment).
- Primary Online Metrics: Total qualified watch hours per active user, 7-day user return rate.
- Guardrails Monitoring: Service response time latency ($p95, p99$), total API error rate, and catalog consumption skewness (Gini index).
6. Cold Start & Freshness Infrastructure
- New Items (Cold Title): Fall back to content-based representations using metadata embeddings (BERT/RoBERTa representations of synopses, actor/director vectors). Route new uploads directly to a contextual multi-armed bandit pool to gather initial interaction signals efficiently.
- New Users (Cold User): Prompt during onboarding for explicitly preferred genres/languages. Compute immediate vector projections in the implicit ALS space via closed-form update iterations over real-time session clicks without re-running full-catalog matrix updates.
- Real-time Feature Freshness: Utilize Apache Flink listening to user event streams (clicks, short plays) to update rolling short-term user preference vectors in a Redis key-value store within seconds.