Recommender for a Fast-Changing Catalog with Few Interactions
Machine LearningModel answerLast updated
Design a two-stage recommender for a content app where users and items are constantly new, covering models, exploration, off-policy evaluation, A/B testing and a strict latency budget.
You are launching the home feed for a content app. Interaction data is thin, many users are new, and a large batch of new items arrives every day. Most of an item's engagement happens shortly after it is published.
Design a recommendation system that keeps working for both brand-new users and brand-new items. Your answer should cover:
- Architecture. A two-stage pipeline (candidate generation followed by ranking). State your assumptions about scale, such as users, catalog size, requests per second and page size.
- Retrieval model. Choose a concrete approach (for example matrix factorization or a two-tower network). Give the loss, the negative sampling scheme, and explain how it produces useful representations for items and users with no history.
- Ranking model. Choose a model for the launch period and one for when data is plentiful. Give the loss, and list the main user, item, user-item and context features.
- Exploration. Explain how you give new items exposure without hurting the experience (for example Thompson sampling, or epsilon-greedy with limits on propensities).
- Evaluation. Define offline metrics and online KPIs. Write down the off-policy estimator you would compute (IPS, SNIPS or doubly robust) and explain why it is needed.
- Experimentation. Describe an A/B test that handles selection bias, and the guardrails that protect long-term outcomes.
- Serving. Show how you would meet a p50 below 50 ms and a p99 below 200 ms end to end, including feature store access, caching and approximate nearest neighbor search.
Hints
Hint 1
Make the item and user representations work without IDs: feed content embeddings and context into the towers, and randomly drop the ID embedding during training so a new entity still gets a sensible vector.
Hint 2
Log everything needed for off-policy evaluation at serving time (propensity, position, whether the slot was exploratory, policy version). Without logged propensities you cannot use IPS or doubly robust estimators later.
Hint 3
Treat latency as a budget: split the 200 ms p99 across candidate retrieval, feature fetch, ranking and re-ranking, run retrieval sources in parallel, and cut the candidate set aggressively before the expensive model.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
1. Assumptions
- 10M daily users; about 30% have fewer than 5 lifetime interactions.
- About 1M active items plus roughly 50k new ones per day, with much of the engagement in the first 48 hours.
- Peak about 20k feed requests per second, 20 items per page.
- Signals: impressions, clicks, dwell, likes, shares, hides. Explicit ratings are rare.
- Objective: long-term engagement (D7/D28 retention, sessions per user), not raw CTR.
2. Architecture
- Candidate generation (about 1,000 candidates, sources run in parallel): a two-tower ANN index, a fresh-item index (items under ~72 h), item-to-item session co-engagement, popularity by geo/topic/device, and onboarding-topic retrieval for new users.
- Ranking of the top ~500 merged candidates.
- Re-ranking: diversity caps by creator and topic, reserved exploration slots, and propensity computation and logging.
Every impression is logged with request_id, user_id, item_id, position, score, propensity, explore_flag, policy_version. This is the foundation for unbiased evaluation.
3. Retrieval: two-tower model
User tower: hashed user-ID embedding, pooled content embeddings of the last ~50 engaged items, onboarding topics, and context (geo, device, hour, referrer). Item tower: pretrained text and image embeddings, category and creator embeddings, a freshness bucket, and an item-ID embedding.
Cold-start trick: ID dropout (p around 0.5). The towers learn to produce good vectors from content and context alone, so a new item is retrievable on day zero and a new user is served via session and context features.
Loss: sampled softmax with logQ correction, where s(u,i) = ⟨f(u), g(i)⟩/τ and each logit is adjusted by minus log q(j), with q the sampling probability of item j, estimated by a streaming counter.
Negatives: in-batch negatives (popularity-biased, which logQ fixes), about 20% uniform negatives from the whole corpus (otherwise tail and new items are never seen as negatives and get inflated scores), and a small weight on hard negatives (impressed but skipped), which are noisy. Positives are clicks with dwell above ~10 s to filter clickbait.
4. Ranking
- At launch: LightGBM with logistic loss on engaged-click. It is robust on small data and handles dense and count features well.
- At scale: a multi-task DNN (for example MMoE) with click, long-dwell and hide heads, each trained with binary cross-entropy. Final score: p_click · (w1 + w2 · p_dwell) − w3 · p_hide.
Features
- User: tenure, interaction count (an explicit cold-start flag), topic affinity, recency.
- Item: age, content embedding, creator quality prior, smoothed CTR = (clicks + k·prior)/(impressions + k).
- User x item: tower similarity, topic match, creator follow, seen-before.
- Context: hour, device, geo, and position (used in training, fixed to a constant at serving to remove position bias).
5. Exploration
Reserve about 2 of 20 slots for fresh items (age under 72 h, impressions under ~1,000), chosen by Thompson sampling. The Beta posterior is seeded with the ranker's prediction p̂ with pseudo-count k (about 20):
θ_i ~ Beta(k·p̂_i + c_i, k·(1 − p̂_i) + n_i − c_i)
Safeguards: a per-item hourly exposure cap, a propensity floor (about 0.01) so importance weights stay bounded, and logged propensities. Thompson sampling has no closed form propensity, so estimate it by Monte Carlo (about 100 draws, asynchronously) and store it.
6. Evaluation
Offline: Recall@500 for retrieval; NDCG@10, AUC, logloss and calibration (ECE) for ranking on a time-based split. Always slice by item age and user tenure, and track catalog coverage and new-item exposure share.
Off-policy estimate of a new policy π from logs of policy μ, with weight w_i = π(a_i|x_i)/μ(a_i|x_i), clipped at M (say 10):
- IPS: V̂ = (1/n) Σ w_i r_i
- SNIPS: V̂ = Σ w_i r_i / Σ w_i (lower variance, slightly biased)
- Doubly robust (what I would report): V̂ = (1/n) Σ [ q̂(x_i, π) + w_i (r_i − q̂(x_i, a_i)) ], where q̂(x, π) = Σ_a π(a|x) q̂(x, a). It is consistent if either the propensities or the reward model is right, and has lower variance than IPS.
Use these to gate which models reach an online test and to analyse slot-level effects.
7. Online experiment
- Randomize by hashed user ID, so assignment itself is unbiased.
- Use CUPED with pre-period engagement to cut variance, and run a power analysis on the primary KPI (for example detecting a 0.5% lift in sessions per user with about 2% of DAU per arm over two weeks).
- Primary KPI: sessions per user per week or D7 retention. Secondary: engaged clicks, dwell, time for a new item to reach its first 10 engagements, new-user D1 retention.
- Guardrails: hide/report rate, creator and topic diversity, creator concentration, latency, and long-term holdouts (a small persistent control group tracked for 4+ weeks) to catch short-term gains that hurt retention.
- Interference: exploration in the treatment arm shifts item statistics shared across arms, so watch for contamination and consider cluster or creator-level randomization for item-side effects.
8. Latency plan
Budget for p99 of about 200 ms: gateway and user features about 15 ms, parallel retrieval about 30 ms, candidate feature fetch about 25 ms, ranking about 40 ms, re-rank and logging about 15 ms, leaving headroom.
- ANN: HNSW or IVF-PQ sharded and replicated in memory, with a separate small index for fresh items that supports fast inserts.
- Feature store: a low-latency key-value store with batched multi-gets (one round trip for all 500 candidates), item features colocated with the ranker, and a streaming pipeline for counters.
- Caching: cache user vectors for a short TTL, popularity lists per segment, and item features in process memory. Precompute item embeddings at publish time.
- Model cost: ranking only ~500 candidates, quantized or distilled models, and batched inference.
- Tail control: per-stage timeouts with fallbacks (cached popular feed if retrieval is slow), hedged requests, and asynchronous propensity logging.
Common mistakes
- Relying on ID embeddings only, so new items are invisible.
- Not logging propensities, which makes off-policy evaluation impossible.
- Sampling negatives only in-batch, which penalizes popular items and mis-scores the tail.
- Using CTR as the sole objective, which promotes clickbait.
- Using position as a feature at serving time without neutralizing it.
- Reporting only aggregate metrics and hiding cold-start regressions.