Bird
Raised Fist0
HLDsystem_design~12 mins

Search and recommendation in HLD - Architecture Diagram

Choose your learning style9 modes available
System Overview - Search and recommendation

This system allows users to search for items and receive personalized recommendations. It must handle large volumes of queries quickly and provide relevant results based on user preferences and item popularity.

Architecture Diagram
User
  |
  v
Load Balancer
  |
  v
API Gateway
  |
  +--------------------+
  |                    |
  v                    v
Search Service      Recommendation Service
  |                    |
  v                    v
Search Index         User Profile DB
  |                    |
  v                    v
Cache (Search)      Cache (Recommendations)
  |                    |
  +---------+----------+
            |
            v
         Main Database
Components
User
client
Sends search queries and receives recommendations
Load Balancer
load_balancer
Distributes incoming user requests evenly to API Gateway instances
API Gateway
api_gateway
Routes requests to appropriate backend services
Search Service
service
Processes search queries using the search index
Recommendation Service
service
Generates personalized recommendations based on user profiles
Search Index
search_index
Stores indexed data for fast search retrieval
User Profile DB
database
Stores user preferences and behavior data
Cache (Search)
cache
Caches frequent search results to reduce latency
Cache (Recommendations)
cache
Caches popular recommendations for quick access
Main Database
database
Stores all item data and metadata
Request Flow - 20 Hops
UserLoad Balancer
Load BalancerAPI Gateway
API GatewaySearch Service
Search ServiceCache (Search)
Cache (Search)Search Service
Search ServiceSearch Index
Search IndexSearch Service
Search ServiceCache (Search)
API GatewayRecommendation Service
Recommendation ServiceCache (Recommendations)
Cache (Recommendations)Recommendation Service
Recommendation ServiceUser Profile DB
User Profile DBRecommendation Service
Recommendation ServiceMain Database
Main DatabaseRecommendation Service
Recommendation ServiceCache (Recommendations)
Search ServiceAPI Gateway
Recommendation ServiceAPI Gateway
API GatewayLoad Balancer
Load BalancerUser
Failure Scenario
Component Fails:Main Database
Impact:New item data cannot be fetched, recommendation service cannot update item metadata, recommendations may be stale. Search index updates may also be delayed.
Mitigation:Use database replication for failover. Cache layers serve stale data to maintain availability. Alert system triggers for quick recovery.
Architecture Quiz - 3 Questions
Test your understanding
Which component handles distributing incoming user requests to backend services?
ACache (Search)
BSearch Index
CLoad Balancer
DUser Profile DB
Design Principle
This architecture uses caching to reduce latency and load on databases, separates search and recommendation services for scalability, and employs load balancing and API gateway for efficient request routing and fault tolerance.