RECOMMENDATION SYSTEMS · INTERVIEW QUESTION
Explain two-tower models for recommendation. How are they used in production?
🔴 advanced · Hybrid Systems
Hint: Think about separate user and item encoders with dot-product similarity.
Answer
Two-tower architecture: separate neural networks encode users and items into dense embeddings. User tower: processes user features (demographics, history, context). Item tower: processes item features (metadata, content). Relevance score: dot product or cosine similarity of the two embeddings.
Interview reasoning
Training: contrastive learning on positive (clicked/purchased) and negative (random/hard negatives) pairs.
Production use:
- Item embeddings pre-computed and indexed in ANN (FAISS, ScaNN)
- User embedding computed at request time
- ANN retrieves top-k candidates in ~ms.
Benefits: serving per candidate, scales to billions of items.
Limitations: limited interaction modeling (no cross-features). Solution: use two-tower for retrieval, then a cross-network ranker (e.g., DCN, DeepFM) for final ranking.
A two-tower model encodes user/context and item information separately and trains their similarity to retrieve useful items. Item vectors can be precomputed into an ANN index; user vectors reflect recent context. A richer cross-feature ranker can then evaluate the bounded retrieved pool.
Worked example. For ten million items, precompute their vectors; compute one query vector and retrieve hundreds before expensive ranking.
Validation
Measure exact and ANN recall, new-item quality, index freshness and retrieval latency; verify both towers' feature versions.
Common pitfalls
Separately encoded towers cannot represent every pairwise interaction. Mixed encoder/index versions can fail even when each component works independently.
Related questions
- Explain matrix factorization for collaborative filtering. How does it handle the cold start problem?
- How do you evaluate a recommendation system in production? What are the key offline and online metrics?
- What is a recommendation system and how does it work?
- Explain the difference between user-based and item-based collaborative filtering.
- What is the cold start problem in recommendation systems? How do you solve it?