| Scale | Users | Search Queries/Second | Recommendation Requests/Second | Data Size (Items, User Profiles) | System Changes |
|---|---|---|---|---|---|
| Small | 100 | 10 | 5 | 1K items, 100 profiles | Single server, simple DB, no caching |
| Medium | 10K | 1K | 500 | 100K items, 10K profiles | Load balancer, DB replicas, caching layer |
| Large | 1M | 100K | 50K | 10M items, 1M profiles | Distributed search cluster, sharded DB, ML model serving |
| Very Large | 100M | 10M | 5M | 1B+ items, 100M profiles | Multi-region deployment, CDN, advanced sharding, real-time streaming |
Search and recommendation in HLD - Scalability & System Analysis
Start learning this pattern below
Jump into concepts and practice - no test required
At small scale, the database is the first bottleneck because it handles all search queries and recommendation data lookups. As traffic grows, the single DB cannot handle the query load and latency increases.
- Database scaling: Add read replicas to distribute query load and use connection pooling.
- Caching: Use in-memory caches (e.g., Redis) for frequent queries and recommendation results.
- Search scaling: Deploy distributed search engines (e.g., Elasticsearch) to handle large data and queries.
- Sharding: Partition user profiles and item data across multiple databases to reduce single DB load.
- Horizontal scaling: Add more application servers behind load balancers to handle increased traffic.
- CDN: Use content delivery networks to cache static recommendation content closer to users.
- ML model serving: Use dedicated servers or services for recommendation model inference to offload app servers.
At 1M users with 100K search queries/sec and 50K recommendation requests/sec:
- Database: Needs to handle ~150K QPS (queries per second). A single PostgreSQL instance handles ~10K QPS, so at least 15 replicas or sharded DBs are needed.
- Cache: Redis can handle ~100K ops/sec per instance, so multiple Redis nodes are required for caching.
- Network bandwidth: Assuming 1KB per query/response, total bandwidth ~150MB/s, requiring multiple 1Gbps network links or 10Gbps links.
- Storage: 10M items and 1M user profiles may require terabytes of storage, preferably on distributed storage systems.
Start by clarifying scale and traffic patterns. Identify the main components: search engine, recommendation engine, database, cache, and network. Discuss bottlenecks at each scale and propose targeted solutions like caching, sharding, and horizontal scaling. Use real numbers to justify your choices and show understanding of trade-offs.
Your database handles 1000 QPS. Traffic grows 10x to 10,000 QPS. What do you do first and why?
Answer: Add read replicas and implement caching to reduce load on the primary database. This distributes query load and improves response times before considering more complex solutions like sharding.
Practice
Solution
Step 1: Understand the role of search systems
Search systems are designed to help users find information efficiently from large amounts of data.Step 2: Match the purpose with options
Only To help users quickly find relevant content from a large dataset describes helping users find relevant content quickly, which is the core function of search.Final Answer:
To help users quickly find relevant content from a large dataset -> Option AQuick Check:
Search system purpose = find relevant content [OK]
- Confusing search with unrelated features like password storage
- Thinking search manages user settings
- Assuming search is for random content display
Solution
Step 1: Identify personalization needs
Recommendation systems personalize suggestions based on user data and behavior.Step 2: Match components to personalization
User behavior tracking collects data needed to tailor recommendations, unlike static pages or infrastructure tasks.Final Answer:
User behavior tracking -> Option BQuick Check:
Personalization needs user data = User behavior tracking [OK]
- Confusing infrastructure tasks with personalization
- Thinking static pages can personalize content
- Ignoring the role of user data
Solution
Step 1: Understand inverted index concept
An inverted index maps each word to the list of documents containing it, enabling quick lookups.Step 2: Identify the advantage for search speed
This mapping allows the system to find relevant documents quickly without scanning all documents.Final Answer:
Faster search queries by mapping words to document lists -> Option DQuick Check:
Inverted index = fast word-to-doc lookup [OK]
- Confusing indexing with storage format
- Thinking encryption is the main index benefit
- Assuming index deletes documents automatically
Solution
Step 1: Analyze cause of irrelevant recommendations
Recommendations depend on accurate user data; missing or wrong data leads to poor suggestions.Step 2: Evaluate other options
Server count, protocol choice, or backup frequency do not directly affect recommendation relevance.Final Answer:
Incorrect or missing user behavior data -> Option CQuick Check:
Bad recommendations = bad user data [OK]
- Blaming infrastructure instead of data quality
- Confusing network protocols with recommendation logic
- Ignoring data collection importance
Solution
Step 1: Understand scalability and personalization needs
Millions of users require efficient processing; personalization improves user experience.Step 2: Evaluate approaches
Hybrid models combine strengths of different methods. Offline batch processing reduces load, while online updates keep recommendations fresh.Step 3: Reject less scalable or less personalized options
Popular-only recommendations lack personalization. Real-time deep learning per request is costly. Single DB server is a bottleneck.Final Answer:
Use a hybrid model combining collaborative filtering and content-based filtering with offline batch processing and online updates -> Option AQuick Check:
Hybrid + batch + online = scalable personalized system [OK]
- Ignoring scalability by doing all processing online
- Sacrificing personalization for simplicity
- Using single server for massive data
