System Design Problems
Design a Recommendation System
A recommendation system predicts user preferences and suggests relevant items. Netflix saves $1B/year through its recommendation engine, which drives 80% of content watched. The system combines collaborative filtering, content-based filtering, and deep learning.
- Collaborative Filtering â "Users like you also liked..."
- Content-Based Filtering â "Items similar to ones you've liked..."
- Hybrid Approach â Combine signals for better accuracy
The challenge is balancing relevance (what users want) with diversity (what users don't know they want) at massive scale with sub-second latency.
Requirements
Functional Requirements
- "Because you watched X" recommendations (item-to-item)
- "Users like you also liked" (user-to-user)
- Trending and popular items
- Personalized homepage feed
- Real-time updates based on user actions
- A/B testing framework for algorithms
Non-Functional Requirements
- Latency: Recommendations in < 200ms
- Scale: 200M users, 100M items
- Freshness: User actions reflected within minutes
- Accuracy: Click-through rate > 5%
- Diversity: Avoid filter bubbles; introduce serendipity
Back-of-the-Envelope Estimation
Recommendation Algorithms
Collaborative Filtering
Content-Based Filtering
Two-Tower Deep Learning Model
High-Level Architecture
Three-Phase Pipeline
| Phase | Candidates | Latency | Algorithm |
|---|---|---|---|
| Candidate Generation | 1000+ | 10ms | ANN search, collaborative filtering |
| Ranking | 100 | 50ms | Deep learning scoring |
| Re-ranking | 10 | 10ms | Business rules, diversity |
Handling Cold Start
For new users and items:
Practice Exercises
-
Algorithm: Implement cosine similarity between two item feature vectors. What is the time complexity for finding the top-K most similar items?
-
Scale: If you have 100M items with 128-dimensional embeddings, estimate the memory and query time for an FAISS index.
-
Diversity: Design a re-ranking algorithm that ensures the top 10 recommendations don't all belong to the same genre. How do you balance relevance vs. diversity?
-
Evaluation: Design an A/B testing framework for recommendation algorithms. What metrics would you track and how long should experiments run?
What to Learn Next
-> Design Search Engine Inverted indices and relevance ranking.
-> Design News Feed Personalized content ranking and fan-out.
-> Design Realtime Analytics Real-time user interaction tracking.
-> Design Search Autocomplete Trie-based typeahead with popularity ranking.
-> Databases Storing user profiles and item features.
-> Caching Strategies Caching pre-computed recommendations.