Design "People You May Know" system

Difficulty: MEDIUMCategory: HLDFrequency: 1Asked On 2018-07-26

Problem Statement

One of the core features of LinkedIn is “People You May Know (PYMK)” — it recommends potential new connections to users. The system must handle hundreds of millions of users and billions of connections, while continuously updating recommendations in near real-time as the graph evolves.


You are asked to design a scalable and efficient PYMK recommendation system.


✅ Functional Requirements


1.Generate Recommendations
•Suggest new connections based on:
•Mutual connections (friend-of-friend).
•Shared attributes (company, school, industry).
•Graph proximity (shortest path, community detection).
2.Ranking
•Rank suggestions by relevance (e.g., # of mutuals, strength of connections).
3.Personalization
•Consider profile info, activity, and location.
4.Freshness
•Update recommendations when a user adds/removes connections.
5.User Experience
•Show top-K recommendations with pagination.


❌ Non-Functional Requirements


•Scalability: Handle hundreds of millions of users and billions of edges.
•Low Latency: Return recommendations in <200 ms for UI.
•Freshness: Updated in near real-time (within a few minutes).
•High Availability: Must serve results even if parts of pipeline fail.
•Extensibility: Support ML-driven recommendation upgrades.


🧱 System Components


1.Graph Store
•Stores user connections (edges in social graph).
•Options: Graph DB (Neo4j), distributed KV store (HBase, Cassandra), adjacency lists.
2.Feature Store
•Stores profile attributes (company, school, interests).
•Used for attribute-based recommendations.
3.Recommendation Engine
•Candidate Generation
•Mutual connections (2-hop neighbors).
•Attribute-based matching.
•Activity signals.
•Ranking Layer
•Heuristics (mutual count, recency).
•ML models (logistic regression, GBDT, deep learning).
4.Batch Layer (Offline)
•Periodic computation of large-scale recommendations.
•Tools: Spark, Hadoop, Presto.
5.Streaming Layer (Near Real-Time)
•Updates recommendations when new connections/events occur.
•Tools: Kafka, Flink, Samza.
6.Serving Layer (API)
•REST/gRPC API to fetch top-K recommendations.
•Cache hot results in Redis for fast retrieval.


🔄 Example Flow


1.User logs in → Calls PYMK API.
2.System fetches cached recommendations. If not available → triggers candidate generation.
3.Candidate users are ranked using ML + heuristics.
4.API returns top-K suggestions (e.g., 10 profiles).


⚖️ Trade-offs & Design Considerations


•Candidate Generation
•Mutual c cheap & effective but limited.
•Graph traversal at scale is expensive → need precomputation + caching.
•Freshness vs Cost
•Batch jobs for scalability.
•Streaming updates for freshness.
•Storage
•Graph DBs are hard to scale; often use distributed KV stores with adjacency lists.
•Ranking
•Start with heuristics → evolve to ML-driven ranking.
•Cold Start
•New users: rely on profile attributes + location.


🧪 Open Discussion Points


•How to scale 2-hop neighbor search for billions of users?
•How to balance offline batch computation vs real-time updates?
•How to handle spam/fake accounts in recommendations?
•Should recommendations be diversified (not only mutual connections)?


👉 This HLD tests graph theory, distributed systems, caching, streaming, ML integration, and trade-off analysis — very common for LinkedIn/Facebook design rounds.

Solution

Comments