🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
đŸ’ŧ Servicesâ„šī¸ Aboutâœ‰ī¸ ContactView Pricing Plansfrom $10

Design a Recommendation System

System Design ProblemsMachine Learning InfrastructuređŸŸĸ Free Lesson

Advertisement

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 FilteringUser-Item Interaction MatrixMatrix Factorization (SVD)Nearest Neighbor SearchNo content features neededContent-BasedItem Feature VectorsCosine SimilarityTF-IDF / EmbeddingsHandles cold-startHybrid (Deep Learning)Neural Collaborative FilteringTwo-Tower ModelTransformer + AttentionBest accuracy ✓

Collaborative Filtering

Content-Based Filtering

Two-Tower Deep Learning Model

User TowerUser FeaturesHistory EmbedMLP Layers128-dim EmbeddingItem TowerItem FeaturesContent EmbedMLP Layers128-dim EmbeddingCosine Similarity(dot product for ranking)

High-Level Architecture

User ActionsKafkaRecommendation SvcCandidate GenerationRanking ModelRe-rankingDiversity FilterA/B Test AssignItem Embeddings(ANN Index)User Profiles(Redis)Recommendation System Architecture

Three-Phase Pipeline

PhaseCandidatesLatencyAlgorithm
Candidate Generation1000+10msANN search, collaborative filtering
Ranking10050msDeep learning scoring
Re-ranking1010msBusiness rules, diversity

Handling Cold Start

For new users and items:

Practice Exercises

  1. Algorithm: Implement cosine similarity between two item feature vectors. What is the time complexity for finding the top-K most similar items?

  2. Scale: If you have 100M items with 128-dimensional embeddings, estimate the memory and query time for an FAISS index.

  3. 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?

  4. 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.

Need Expert System Design Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement