Recommend Connections Through Mutual Friends and Evaluate the Ranking
FireworksMachine Learning Engineer · OnsiteLast updated
Design a connection recommendation system based on mutual connections, define bounded graph affinity scores, and evaluate the ranking pipeline using metrics like NDCG with independent labels.
Scenario
A social platform wants to build a "People You May Know" (PYMK) recommendation feature. The system suggests potential connections to a user based on their social network topology—specifically leveraging mutual friends—and ranks candidates to maximize valid, accepted connections.
Requirements
- Functional Requirements:
- For a given user
u, identify candidate users who share at least one mutual friend withu, strictly excludinguthemselves and existing 1-hop connections. - Formulate bounded candidate scoring heuristics (mapping similarity into a known interval such as
[0, 1]) to score topological proximity before or alongside ML ranking. - Rank candidates using candidate features (graph topology, mutual connection counts, interaction history, user profile attributes).
- Support an offline evaluation framework using ranking metrics (such as NDCG or MAP) and justify the choice of relevance labels.
- For a given user
- Non-Functional Requirements & Scale:
- 100 million active users; 10 billion total undirected friendship edges.
- Average user has ~200 friends, but degree distribution is heavy-tailed (super-connectors have 10,000+ friends).
- Serving latency: p99 under 100 ms for top-20 recommendations.
What to Cover
- Candidate Generation (Retrieval): Architecture for 2-hop neighbor traversal at scale. Explain how to handle high-degree nodes ("celebrity/hub problem") to avoid combinatorial explosion.
- Bounded Affinity Scoring: Define mathematical scoring functions (e.g., Jaccard similarity, normalized Adamic-Adar, or Cosine similarity of adjacency vectors) that map to a bounded range like
[0, 1]. Discuss why raw mutual friend count is insufficient. - ML Ranking Pipeline: Describe features, training data generation (handling negative samples and impression bias), and the ranking objective (e.g., point-wise calibrated probability vs. list-wise learning to rank).
- Evaluation Strategy: Detail how to evaluate the ranking system offline using NDCG. Explain the theoretical assumptions of NDCG (e.g., item independence, position discounts) versus real-world social network dynamics, and define the online A/B test metrics.
Hints
Hint 1
To prevent combinatorial explosion during 2-hop traversal, consider capping neighbor lists or down-weighting intermediate nodes with extremely high degrees.
Hint 2
Raw mutual friend count scales with node degree, so consider metrics like Jaccard similarity or modified Adamic-Adar to normalize and bound the score between 0 and 1.
Hint 3
Standard NDCG assumes the relevance of each recommended item is independent, whereas in social networks, accepting one invitation can immediately alter the relevance of remaining candidates.
Follow-up questions
- How would you address the cold-start problem for new users who have zero or very few friends in the graph?
- How does position bias in PYMK UI carousels affect offline ground-truth labels, and how would you correct for it during model training?
- If candidate generation needs to run in near real-time as users accept new requests, how would you architect the graph index updates?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.