Cheat sheet · System Design
Recommender systems cheat sheet
The key ideas on one page — plus common pitfalls and interview tips. Skim it before an interview, or print it for revision.
Cheat sheet
A dense, interview-grade reference on modern recommender systems spanning collaborative filtering, matrix factorization, two-tower retrieval, deep ranking, sequential/transformer and graph models, and the LLM/generative-retrieval era - with the metrics, serving architecture, and evaluation traps that interviews probe.
Problem Framing & Paradigms
- Three families: Collaborative Filtering (CF) uses user-item interaction patterns; Content-Based uses item/user features; Hybrid combines both to fight cold start.
- Feedback types: explicit (ratings, hard to get) vs implicit (clicks, watches, dwell - abundant but noisy; absence != negative).
- Tasks: rating prediction (RMSE) is largely legacy; real systems do top-N ranking and next-item prediction.
- Industrial pipeline is multi-stage: candidate generation/retrieval (millions->hundreds, recall-optimized) -> ranking (hundreds->tens, precision-optimized) -> re-ranking (diversity, business rules, freshness).
- Why staged: an expensive deep ranker can't score the entire catalog within the latency budget, so cheap retrieval narrows the set first.
- Cold start is the central recurring challenge: new users (no history), new items (no interactions), new system (no data) - solved with content features, popularity priors, and bandits/exploration.
Collaborative Filtering & Matrix Factorization
- Memory-based CF: user-user or item-item similarity (cosine, Pearson). Item-item (Amazon) is more stable and precomputable than user-user.
- Model-based: factorize the sparse interaction matrix R (m x n) into user factors P (m x k) and item factors Q (n x k), so r_hat_ui = p_u . q_i.
- Add biases: r_hat_ui = mu + b_u + b_i + p_u . q_i - biases capture 'this user rates high' / 'this item is popular' and often beat raw factors.
- For implicit feedback use ALS with confidence weighting (Hu/Koren iALS) or BPR, which optimizes a pairwise ranking loss (observed item ranked above a sampled negative).
- Regularize factors (L2) to avoid overfitting sparse rows; tune k (latent dim), typically 32-256.
- Limitations: a linear dot product can't model higher-order feature interactions or context, and pure-ID factorization has no representation for unseen users/items (cold start).
Deep Retrieval: Two-Tower & ANN
- Two-tower (dual encoder): a user/query tower and an item tower each produce an embedding; relevance = dot product or cosine. Towers are independent, so item embeddings are precomputed offline.
- Train with sampled softmax / in-batch negatives (other items in the batch act as negatives); apply logQ correction to debias for item popularity in the sampling distribution.
- A learnable temperature on the softmax logits sharpens/softens the distribution and is an important tuning knob.
- Serve item embeddings in an ANN index (FAISS, ScaNN, HNSW); the query tower runs at request time and ANN returns top-K in sub-millisecond.
- Towers ingest rich features (IDs, content, context, demographics) so the model generalizes to new items via features even without interaction history.
- Key constraint: no early interaction between user and item features (the price of precomputable item embeddings) - cross-features are deferred to the ranker.
- Hard negative mining (semantically close non-clicks) improves retrieval quality far more than random negatives alone.
Ranking Models & Feature Interactions
- Ranking scores the small retrieved candidate set with a heavy model and full cross-features (user x item, context, feature crosses).
- Classic deep CTR: Wide&Deep (memorization + generalization), DeepFM and DCN/DCN-v2 (explicit feature crossing), DLRM (Meta's embedding + interaction + MLP architecture).
- Factorization Machines model all pairwise feature interactions in O(k*n) via the FM trick - a strong baseline for sparse categorical data.
- Multi-task learning (MMoE, PLE) jointly predicts click, like, share, watch-time, with shared + task-specific experts to balance objectives.
- Learning-to-rank losses: pointwise (logistic), pairwise (RankNet/BPR), listwise (LambdaMART, softmax) - listwise/pairwise align better with ranking metrics like NDCG.
- Calibration matters when scores feed business logic (e.g., ad bidding, expected-value blends p(click)*p(convert)*value); use Platt/isotonic if the loss distorts probabilities.
Sequential, Session & Graph Models
- User behavior is a sequence; next-item prediction with self-attention: SASRec (causal/left-to-right) and BERT4Rec (masked, bidirectional, cloze objective).
- GRU4Rec pioneered RNN-based session recommendation for anonymous/short sessions where no long user profile exists.
- Graph models (LightGCN, PinSage) propagate embeddings over the user-item bipartite graph; LightGCN strips nonlinearities/weight matrices and just averages neighbor embeddings across layers - simple and strong.
- Sequential models capture short-term intent and order effects that bag-of-history MF misses (e.g., bought phone -> now wants a case).
- Real-time features (last N actions in this session) often give the biggest online lift; stream them into the serving features.
- Target-attention models (DIN/DIEN) weight relevant past behaviors per candidate item rather than collapsing history into one static vector.
Evaluation, Bandits & the LLM Era
- Offline ranking metrics: Precision@K, Recall@K, MAP, NDCG@K (position-discounted, the workhorse), MRR, plus coverage/diversity/novelty/serendipity beyond accuracy.
- Online truth is A/B testing on engagement/retention/revenue; interleaving gives faster, lower-variance ranker comparisons than full A/B.
- Exploration vs exploitation via contextual bandits (epsilon-greedy, Thompson sampling, LinUCB) - essential for cold items and breaking feedback loops.
- Counterfactual/off-policy evaluation (IPS, doubly-robust) estimates a new policy from logged data and corrects for position/presentation bias.
- LLM era (2024-2026): LLMs as feature extractors / semantic embeddings, zero-shot and conversational recommenders, and Generative Retrieval (e.g., TIGER) that decodes semantic item IDs autoregressively instead of ANN lookup.
- RAG-style and agentic recommenders use retrieval + LLM reasoning for explainable, instruction-following recs; multimodal pretrained embeddings give strong cold-start content signals.