← Create New Paste

System Design Interview: "People You May Know" Friend Recommendations

6 views
Designing a friend suggestion feature like LinkedIn's or Facebook's "People You May Know" combines graph processing, ranking and serving at scale. Here is a 45-minute structure. 1. Requirements Functional: show each user a ranked list of suggested connections, refresh it regularly, and let users dismiss suggestions. Non-functional: hundreds of millions of users with an average of a few hundred connections each, suggestions loaded within about 100 ms, and freshness within a day (a new connection should affect suggestions reasonably soon). 2. Candidate generation The strongest signal is friends of friends. For a user A, collect the connections of A's connections, excluding A and people A already knows, and count mutual connections. The problem: a user with 500 friends, each with 500 friends, produces up to 250,000 candidates. Mitigations: - Sample or cap the number of second-degree neighbors per friend. - Skip "super-connector" accounts with huge friend counts, which add little signal. - Add other candidate sources: same company or school, imported contacts, shared groups and people who viewed the profile. 3. Batch vs. online computation Computing second-degree neighbors for everyone on every request is too expensive. A common design: - A daily batch job (Spark on the graph stored as edge lists) computes the top few hundred candidates per user with features like mutual count. - A near-real-time stream updates candidates for users who just added connections, so new friends quickly change suggestions. - Results are stored in a key-value store keyed by user ID. 4. Ranking A model scores each candidate using features such as mutual connections, shared employers or schools, geographic proximity, profile completeness and past interactions. The label is whether past suggestions led to a sent and accepted invitation. Optimize for accepted connections, not just clicks, to avoid spammy behavior. 5. Serving The API reads the precomputed candidate list, filters out dismissed users, blocked users and people who already connected since the batch ran, applies final ranking and returns the top N. Caching per user keeps latency low. 6. Privacy and safety Respect blocks and privacy settings, avoid suggesting people based on sensitive signals, and be careful with contact import data. Interviewers increasingly expect you to mention this. 7. Metrics Track invitation send rate, acceptance rate, dismissals and long-term engagement. A/B test ranking changes. 8. Trade-offs to summarize Batch for cost, streaming for freshness, sampling to tame the second-degree explosion, and acceptance-based training labels. During live system design rounds, Linkjob AI (https://linkjob.ai) offers real-time help in technical interviews, helping you remember points like super-connector handling when the discussion moves quickly.
Created Nov 17, 2026 21:32 Expires Nov 17, 2027 21:32