System Design
Recommender systems
A dense, interview-grade reference on modern recommender systems spanning collaborative filtering, matrix factorization, two-tower retrieval, deep ranking,
Questions & Answers
Tap a question to reveal its answer. Written for self-study and interview preparation.
In collaborative filtering, what fundamental problem does the 'cold start' refer to, and name its two main variants.
Cold start is the inability to make reliable recommendations when there is insufficient interaction data. The two variants are user cold start (a new user with no history) and item cold start (a new item with no interactions). Content/metadata features or hybrid models are typically used to bridge the gap until enough behavioral signal accumulates (a related 'system cold start' applies to a brand-new platform).
Why is matrix factorization (e.g., SVD-style latent factor models) preferred over memory-based neighborhood methods for large, sparse rating matrices?
Matrix factorization learns low-dimensional latent factors that generalize across the sparse matrix, capturing latent structure rather than relying on directly observed co-ratings. It scales better in storage and inference (O(k) per user-item dot product) and handles sparsity by only fitting observed entries, whereas neighborhood methods degrade when overlapping ratings between users/items are scarce.
In implicit-feedback recommendation, why can't you treat unobserved interactions simply as negative labels, and how does the Weighted ALS (Hu, Koren, Volinsky) approach address this?
Unobserved interactions are ambiguous: they may mean dislike or simply lack of exposure. WALS introduces a binary preference indicator p_ui plus a confidence weight (c_ui = 1 + alpha*r_ui) so observed interactions get high confidence while all unobserved pairs are treated as weak negatives with low (but nonzero) confidence, letting the model learn from the full matrix without overcommitting to missing entries.
What is the key conceptual difference between BPR (Bayesian Personalized Ranking) loss and pointwise regression loss for recommendation?
BPR is a pairwise ranking loss that optimizes the relative ordering between an observed (positive) item and a sampled unobserved item per user, maximizing the probability that positives are ranked above negatives (sigmoid of the score difference). Pointwise losses regress each user-item score toward an absolute target independently, which is poorly aligned with the ranking objective that actually drives top-N recommendation quality.
In a two-tower retrieval model, why are the user and item towers kept separate with a dot-product (or cosine) interaction at the top?
Separating the towers lets item embeddings be precomputed and indexed offline, so serving only requires a single user-tower forward pass plus an approximate nearest-neighbor (ANN) search over millions of items. The late dot-product interaction is the key constraint that enables this sublinear retrieval; richer early cross-features would force scoring every item online.
Explain the difference between the retrieval (candidate generation) and ranking stages in an industrial multi-stage recommender.
Retrieval narrows millions of items to a few hundred/thousand candidates cheaply using simple interactions (e.g., two-tower ANN), optimizing for recall. Ranking then applies a heavy, feature-rich model (cross-features, sequence models, GBDT/DNN) to precisely order the small candidate set, optimizing for precision/calibrated probabilities. Splitting the work balances latency against accuracy.
What is the 'feedback loop' / popularity bias problem in deployed recommenders, and name one mitigation.
Recommenders trained on logged data learn from items the system itself exposed, amplifying popular items and starving the long tail, which biases future training data in a self-reinforcing loop. Mitigations include inverse propensity scoring (IPS) to debias the logged data, exploration (epsilon-greedy/bandits), or popularity-debiasing regularization.
In learning-to-rank for recommendation, what does NDCG@k measure and why is it preferred over precision@k?
NDCG@k (Normalized Discounted Cumulative Gain) measures ranking quality by applying a logarithmic position discount and normalizing against the ideal ordering (IDCG), rewarding placing highly relevant items near the top. Unlike precision@k it is graded (supports multi-level relevance) and position-sensitive, so demoting a relevant item from rank 1 to rank 5 is penalized, which precision@k ignores.
Why is offline AUC or NDCG often a poor predictor of online A/B test lift in recommenders?
Offline metrics are computed on logged data that reflects the old policy's exposure, suffering selection/feedback bias and missing-not-at-random labels, and they ignore presentation, novelty, and feedback-loop effects. They also optimize a proxy (clicks on shown items) rather than true counterfactual user behavior, so improvements may not transfer to live traffic.
What problem does negative sampling solve when training large-scale retrieval models with softmax over the full item catalog?
Computing a full softmax over millions of items is computationally infeasible per training step. Negative sampling (e.g., sampled softmax, in-batch negatives) approximates the partition function using a small set of sampled negatives, with a log-Q correction to remove sampling bias for popular items. This makes training tractable while approximating the true full-softmax gradient.
In sampled softmax / in-batch negatives, why is a logQ correction applied, and what is being corrected?
In-batch negatives are sampled proportionally to item popularity, so popular items appear as negatives more often, biasing their scores downward. The logQ correction subtracts log of the sampling probability Q(item) from each logit, debiasing the estimator so it approximates the full softmax and prevents systematically penalizing popular items.
logit_corrected = score - log(sampling_prob[item]) # logQ correctionWhat is the purpose of the FM (Factorization Machine) model, and what does it add over linear models?
Factorization Machines model all pairwise feature interactions using factorized parameters (each feature gets a latent vector, an interaction is the dot product of two vectors), so they learn interaction weights even for sparse, never-co-occurring feature pairs. This generalizes far better than a linear model with explicit cross terms, which cannot estimate weights for unseen combinations in sparse data.
In the Wide & Deep architecture, what role does each component play?
The wide (linear, cross-product feature) component provides memorization of frequent, specific feature co-occurrences, while the deep (embedding + MLP) component provides generalization to unseen feature combinations via dense representations. Jointly training both balances exploiting known strong signals with generalizing to sparse/novel interactions.
What is the core idea behind sequential recommendation models like SASRec, and why use self-attention?
Sequential recommenders predict the next item from a user's ordered interaction history. SASRec uses self-attention to adaptively weight which past items are relevant for the next prediction, capturing both long- and short-range dependencies without RNN recurrence, while remaining parallelizable and handling variable-length histories via causal masking.
How does BERT4Rec differ from SASRec in its training objective?
SASRec uses a left-to-right (causal) next-item prediction objective, predicting item t+1 from items 1..t. BERT4Rec uses a bidirectional Cloze (masked-item) objective, randomly masking items in the sequence and predicting them from both left and right context, which captures bidirectional dependencies but requires a different inference scheme (appending a mask token at the end to predict the next item).
What is the exploration-exploitation tradeoff in recommendation, and how do contextual bandits address it?
Exploitation serves items predicted best now; exploration tries uncertain items to gather data and avoid getting stuck in a local optimum / feedback loop. Contextual bandits (e.g., LinUCB, Thompson sampling) use context features to estimate reward with uncertainty and balance the two by favoring high-uncertainty arms (UCB) or sampling from the posterior (Thompson), maximizing long-run cumulative reward.
Why is diversity an important objective alongside accuracy, and what is one method to inject it at ranking time?
Pure relevance maximization can produce redundant, near-duplicate lists that hurt user satisfaction and discovery. Diversity widens coverage and reduces redundancy. A common method is Maximal Marginal Relevance (MMR) or Determinantal Point Processes (DPP), which trade off an item's relevance against its similarity to already-selected items during list construction.
What is inverse propensity scoring (IPS) in counterfactual recommendation evaluation, and what is its main weakness?
IPS reweights logged rewards by the inverse of the logging policy's propensity of taking each action, yielding an unbiased off-policy estimate of a new policy's value. Its main weakness is high variance when propensities are small (rare actions), which can be addressed by clipping/capping weights or using doubly-robust estimators that combine IPS with a reward model.
In graph-based recommendation (e.g., LightGCN), what simplification did LightGCN make over standard GCNs and why?
LightGCN removes feature transformation matrices and nonlinear activations from the GCN layers, keeping only neighborhood aggregation (weighted sum) on the user-item bipartite graph. The authors found those components add no benefit and even hurt for collaborative filtering, since the only inputs are ID embeddings; the simplified propagation smooths embeddings over the graph and improves accuracy and efficiency.
What is the 'filter bubble' concern in recommenders, and how does it relate to serendipity?
A filter bubble is when personalization narrows a user's exposure to increasingly homogeneous content, reinforcing existing preferences and limiting discovery. Serendipity metrics measure recommendations that are both relevant and unexpected (surprising relative to the user's profile); optimizing for serendipity/novelty counteracts filter bubbles while preserving usefulness.
When using embeddings for categorical IDs in a deep recommender, why is the hashing trick sometimes used, and what is its risk?
The hashing trick maps high-cardinality IDs into a fixed-size embedding table via a hash function, bounding memory and handling unseen IDs at serving without retraining the vocabulary. Its risk is hash collisions, where distinct IDs share an embedding row, conflating their representations; larger tables or multiple hash functions (e.g., QR/compositional embeddings) reduce collision impact.
What is position bias in click-through data, and how can a ranking model be debiased for it?
Position bias is the tendency of users to click higher-ranked items regardless of true relevance, so observed clicks conflate relevance with position. It can be modeled with an examination model (P(click) = P(relevance) x P(examination)) and corrected via IPS using estimated position propensities, or by adding a position feature at training (zeroed/fixed at serving) so the model attributes positional effects separately.
Why do many production recommenders calibrate predicted probabilities (e.g., for CTR), and what is one calibration method?
Downstream decisions like ad auctions, expected-value ranking, and blending multiple objectives require predicted probabilities to match true empirical rates, not just rank order; negative sampling and class imbalance also distort raw scores. Calibration methods include Platt scaling, isotonic regression, or correcting for the sampling rate when negatives were downsampled.
What is multi-task learning in ranking models (e.g., MMoE), and why use it for recommendation?
Recommenders often optimize several objectives (click, watch time, like, conversion) that share signal but can conflict. Multi-task learning shares lower layers while specializing per-task heads; MMoE (Multi-gate Mixture-of-Experts) uses shared experts with per-task gating so each task softly selects relevant experts, reducing negative transfer between loosely related objectives.
How does L2 regularization in matrix factorization help, and what is its effect on latent factors?
L2 regularization penalizes the squared norms of user and item latent vectors, preventing the model from overfitting the sparse observed ratings by shrinking factors toward zero. This reduces variance, improves generalization to unseen entries, and is essential since unregularized factorization can perfectly fit observed ratings while predicting nonsense for missing ones.
What is the role of user and item bias terms in a matrix factorization rating model r_ui = mu + b_u + b_i + p_u . q_i?
The bias terms capture systematic effects independent of interaction: mu is the global average, b_u captures a user's tendency to rate high/low, and b_i captures an item's general popularity/quality. Separating these from the latent dot product lets p_u . q_i focus on genuine user-item interaction, improving accuracy and interpretability.
In approximate nearest neighbor (ANN) search for retrieval, what tradeoff does an HNSW index manage?
HNSW (Hierarchical Navigable Small World) trades recall (fraction of true nearest neighbors found) against latency and memory by tuning graph parameters like M (connections per node) and efSearch (search breadth). Higher ef/M raise recall and index quality but increase query time and memory, so tuning targets the recall-latency operating point the application needs.
What is a common cause of training-serving skew in recommenders, and how is it mitigated?
Skew arises when features computed at training (often batch, with full future-aware joins or different code paths) differ from features computed at serving (online, point-in-time). Mitigations include a shared feature transformation library, logging features at serving time to use as training data, and a feature store that guarantees point-in-time-correct joins.
How can large language models (LLMs) be leveraged in modern recommender systems as of 2026?
LLMs are used for semantic item/content understanding and generating rich text or embeddings for cold-start items, for conversational and explainable recommendation, as zero/few-shot rankers or re-rankers over candidates, and for generating semantic IDs in generative retrieval. They complement (rather than replace) collaborative signal, which still drives most accuracy at scale.
What is generative retrieval (e.g., TIGER with semantic IDs) and how does it differ from dual-encoder retrieval?
Generative retrieval represents each item as a sequence of discrete 'semantic ID' tokens (from a quantized content embedding, e.g., RQ-VAE) and trains a sequence-to-sequence model to autoregressively generate the target item's ID tokens given user history. Unlike dual-encoder ANN retrieval, it has no separate index or dot-product matching; the model's parameters memorize the corpus and decode items directly, improving cold-start generalization via shared semantic tokens.
Why might cosine similarity be preferred over raw dot product when comparing learned embeddings, and what is a subtle risk of using cosine?
Cosine normalizes for embedding magnitude, focusing on direction/semantic similarity and preventing high-norm (often popular/frequent) items from dominating. The subtle risk is that on embeddings not trained with normalization, cosine can be uninterpretable; recent work (Steck et al.) shows cosine similarity of learned embeddings can yield arbitrary results depending on regularization, so the similarity metric should match the training objective.
What is the purpose of temperature scaling in the softmax of a retrieval/contrastive recommendation model?
The temperature tau divides the logits before softmax, controlling the sharpness of the distribution: low tau sharpens, emphasizing the hardest negatives and producing more discriminative embeddings, while high tau softens, treating negatives more uniformly. Tuning tau materially affects retrieval quality and the geometry (uniformity/alignment) of the learned embedding space.
logits = (user_emb @ item_emb.T) / temperatureIn a re-ranking stage, why is a listwise (whole-slate) model sometimes used instead of scoring items independently?
Independent (pointwise) scoring ignores interactions between items shown together, such as substitutes/complements, diversity, and contextual fatigue. Listwise/slate re-rankers (e.g., with attention over the candidate set) score items conditioned on the rest of the slate, capturing these mutual influences to optimize the value of the whole list rather than each item in isolation.
What is concept/distribution drift in recommender systems, and why does it necessitate frequent retraining or online learning?
User preferences, item catalogs, trends, and context shift over time, so a model trained on stale data degrades as the data distribution it sees at serving diverges from training. This necessitates frequent (often daily/streaming) retraining, online/incremental updates of embeddings, and freshness features, plus monitoring for performance decay to trigger retraining.
Related topics in System Design
Put it into practice with AI Learning
This topic — and hundreds more — comes from our free, offline AI Learning app. Practice Q&A, quizzes and cheat sheets anywhere, no account needed.
- Free
- No account
- Works offline