Build a Personalized Swipe-Feed Ranking Pipeline for Clips
Machine LearningModel answerLast updated
Design an end-to-end ML recommender for a vertical clip feed with multi-stage retrieval and ranking, real-time learning, diversity and safety controls, and cold-start handling.
Problem
You are asked to design the recommendation backend for a mobile app where users swipe through an endless vertical feed of short clips. The feed should feel tailored to each person and keep adapting while they scroll.
What the product needs
- Tailored feed: Each user gets a continuous stream of clips chosen from their past behavior (likes, skips, watch time and similar signals).
- Fast responses: The service must absorb a very high request rate while keeping the delay before the first frame low. The server-side budget for retrieval plus ranking is roughly 100 ms.
- Fresh content: A newly uploaded clip should be able to reach viewers soon after ingestion.
Operating constraints
- Scale: More than 100M daily active users and more than 1M new uploads per day.
- Variety: The feed must not trap users in a narrow bubble, so it should deliberately mix in different kinds of content.
- Safety: Policy checks (copyright, prohibited content, takedowns) must be enforced reliably.
What your answer should cover
- Architecture: A high-level picture of the path from a feed request to the response.
- Candidate retrieval: How you shrink a huge corpus to a manageable candidate set (for example collaborative filtering and embedding-based retrieval).
- Ranking: How a multi-stage model cascade works, from cheap early filtering to a heavy final model and re-ranking.
- Feedback loop: How live interactions (plays, watch time, likes) flow back to improve features and retrieval.
- Cold start: How you serve brand-new users and brand-new clips that have no history.
State your assumptions, do rough capacity math, and discuss the key trade-offs.
Hints
Hint 1
Begin with back-of-envelope numbers: requests per second at peak, corpus size, embedding memory footprint, and a per-stage latency budget that sums to under 100 ms.
Hint 2
Think in a funnel: several parallel retrieval channels return thousands of candidates, a cheap pre-ranker trims to a few hundred, a multi-task heavy ranker scores them, and a re-ranker applies diversity, safety, and business rules.
Hint 3
Separate request-time work (reads precomputed features only) from nearline stream processing (seconds) and offline training (hours to daily), and explain how each feeds back into the system.
Hint 4
For cold start, use content-derived embeddings plus a small guaranteed exposure budget for new clips, and context priors plus fast in-session adaptation for new users.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
1. Clarify goals and size the system
Objective. Optimize long-term satisfaction (retention, healthy watch time), not raw clicks, subject to safety and diversity constraints. Confirm this first, since it determines the training labels.
Rough numbers.
- 100M DAU, about 10 feed fetches per day, about 8 clips each, gives roughly 1B requests per day. That is about 12K QPS on average and about 50K QPS at peak.
- Assume about 200M clips in the active recommendable pool. With 128-dim fp16 embeddings (256 B each) that is about 50 GB, which fits in a sharded in-memory ANN index.
Latency budget (p99 under 100 ms): feature fetch 10 ms, retrieval 20 ms, pre-rank 15 ms, heavy rank 40 ms, re-rank and filters 10 ms.
2. Interfaces and data
GET /feed?user_id&session_id&count&cursorreturns clips with arec_token.POST /events(batched) reports impression, play, watch_ms, like, share, skip, follow.- The
rec_tokenrecords which model version and features produced the recommendation. It is essential for correct training logs and A/B attribution.
Stores: a clip store (metadata, safety status, content embeddings), a KV store for user profiles (long-term embedding, last ~200 interactions), real-time counters (windowed CTR, completion rate), and an event log (Kafka into a data lake).
3. Serving architecture
- Feature fetch: user profile, session state, context.
- Multi-channel retrieval (thousands of candidates): two-tower ANN, item-to-item CF on recent positives, followed creators, trending/geo/language, plus fresh and exploration pools. Run channels in parallel with per-channel timeouts and quotas.
- Merge, dedupe, seen-filter: a per-user Bloom filter of recent impressions.
- Pre-rank: a light model cuts thousands to about 500.
- Heavy rank: multi-task network reduces 500 to about 50.
- Re-rank: diversity, safety, business rules, then return the top slice.
4. Deep dives
Retrieval. The user tower consumes profile, recent sequence, and context; the item tower consumes ID, creator, and content embeddings. Train with in-batch sampled softmax on strong positives (completion or like), with a logQ correction to counter popularity bias. Item vectors are precomputed in a sharded HNSW index; the user vector is computed per request. HNSW supports incremental inserts, so fresh clips appear quickly.
Ranking.
- The pre-ranker is a dot-product or small MLP over cached features, distilled from the heavy model so both stages agree.
- The heavy ranker is a multi-task model (MMoE or PLE) with heads for finish probability, expected watch time, like, share, follow, fast skip, and report. It uses cross features (user x creator, user x tag) and attention over the behavior sequence.
- Final score is a weighted blend such as
w1*E[watch] + w2*P(like) + w3*P(share) + w4*P(follow) - w5*P(fast_skip) - w6*P(report), with weights tuned in A/B tests against long-term metrics. - Normalize watch time by clip duration (completion ratio or duration-quantile), otherwise the model just prefers long clips.
Diversity and safety.
- Use MMR or DPP over embeddings plus hard rules (no back-to-back clips from one creator, a cap per topic in a window of 10). Reserve about 5 to 10 percent of slots for exploration.
- Safety runs twice. At ingestion, classifiers and audio/visual fingerprinting gate entry to the index, with human review for borderline cases and a limited-exposure pool for unreviewed clips. At serving, a final hard filter checks current status so takedowns propagate within seconds.
5. Feedback loop
- Request path: reads precomputed features only.
- Nearline (seconds): a stream job (Flink) updates session and sequence features and clip counters, joins impressions with delayed labels like watch time over a few minutes, and feeds samples to online training that refreshes sparse embeddings and recent parameters every few minutes.
- Offline (hours to daily): full retrains of retrieval and ranking models, rebuilding the ANN index, refreshing long-term user embeddings.
This split keeps tail latency flat while capturing mid-session interest shifts within seconds.
6. Cold start
New clips. Compute content embeddings (frames, audio, speech transcript, OCR, hashtags) at upload so the item tower can place the clip with zero interactions. Then run a traffic-ramp: guarantee a small exposure (a few hundred impressions) to interest-matched users, and promote to larger pools only if completion and like rates clear thresholds. Thompson sampling or UCB manages uncertainty.
New users. Start from priors (locale, device, language, time of day, acquisition source), an optional interest picker, and a popular-but-diverse seed set. Short clips give dense signal, so 5 to 10 swipes of session features should quickly dominate.
7. Trade-offs
- Recall vs. latency: more channels and candidates improve quality but strain the retrieval budget; use parallelism and timeouts.
- Freshness vs. stability: faster online updates react sooner but risk noisy or drifting models; add guardrails and canary evaluation.
- Engagement vs. wellbeing: pure watch-time optimization can amplify clickbait or narrow feeds; include negative signals and diversity terms.
- Exploration cost: exploration hurts short-term metrics but protects creator ecosystem health and long-term discovery.
8. Common mistakes
- Training on impressions or clicks only, ignoring completion and negative feedback.
- Not normalizing watch time by duration.
- Logging without a model-version token, which breaks offline/online consistency and A/B analysis.
- Doing heavy feature computation on the request path.
- Applying safety only at upload and not at serving time.
- Ignoring position and selection bias in training data.
Evaluation. Offline: recall@K for retrieval, AUC and calibration for ranking. Online: A/B tests on retention, session length, and creator-side metrics, with guardrails on reports and fast-skip rate.