Skip to content
GenAI Learn/Classic ML Design Questions
Browsing as a guest. Sign in to save your progress and earn XP as you complete chapters.

Capstone: People You May Know

6 min read

You'll learn to

  • -Design a graph-based recommender from candidate generation to serving
  • -Generate candidates with friends of friends and score them with mutual-friend features
  • -Explain why mutual friends need weighting, and how Adamic-Adar does it
  • -Anticipate feedback loops, privacy risks, and scale limits

"People You May Know" is a recommender where the items are also users, and the strongest signal is the shape of the network itself. It is a classic capstone for ML design because it brings together graph data, candidate generation, ranking, scale, privacy, and feedback loops in one system.

An Analogy: Introductions at a Party

At a party you are most likely to be introduced to someone who knows several of your friends, who works in your field, or who went to your school. Those are the same signals a system can use: shared friends, shared groups, shared places. The more of them, the better the introduction.

Requirements

  • -Goal: help people form real connections that lead to lasting engagement, not just a count of requests.
  • -Scale: billions of users and tens of billions of edges, with suggestions needed instantly on the home page.
  • -Latency: a few tens of milliseconds, so heavy graph work happens offline.
  • -Constraints: privacy, safety, and the reality that spammers and strangers will try to exploit the feature.
Social graph
Offline candidate jobs
Feature store
Ranker training
Precomputed suggestion lists
Online service
Feedback logging

PYMK: graph jobs run offline to build candidates, a ranker scores them, and the online service reads precomputed lists. Logged feedback feeds the next round of training data.

Candidate Generation

  • -Friends of friends: people two steps away in the graph. This is the strongest and most common source.
  • -Shared context: same school, employer, group, event, or city.
  • -Imported contacts: people in your address book who are on the platform.
  • -Graph embeddings: vectors learned from the graph (for example with a graph neural network) so that nearby people are close, then nearest-neighbor search.
  • -Reciprocity: people who already viewed or invited you.

At billions of users, two-step expansion is expensive, since popular accounts have thousands of friends. The work is done offline, in batch or on a graph engine, with caps on very high-degree nodes, and the results are written to a key-value store for fast serving.

Scoring: Not All Mutual Friends Are Equal

The number of mutual friends is a strong feature, but a mutual friend who knows 5,000 people says little, while a mutual friend with 40 friends is a real link. The Adamic-Adar score captures this: each mutual friend contributes one divided by the logarithm of their number of friends, so popular connectors count for less. The code builds a tiny friendship graph and suggests people for a user called ana. Press Run and see who comes first.

Press Run: the person who shares two friends with ana comes first

Eli comes first, with a score of 1.44, because Eli shares two friends with ana, Ben and Cara. Hana and Ivo score 0.91 each through one friend, Dev. Fay and Gus come last at 0.72 through Ben and Cara respectively, each of whom has four friends. This is only one feature. A real ranker combines it with many others: how many groups you share, how often you interact with the mutual friends, profile similarity, how recently the candidate was active, and whether they have already viewed you.

Ranking and Labels

  • -Positive label: a sent request that was accepted. A request sent and ignored is a weaker negative, and an unseen suggestion is not a negative at all.
  • -Features: graph signals (mutual friends, Adamic-Adar, shared groups), interaction history, profile similarity, candidate quality (account age, report rate), and context (time, device).
  • -Model: a gradient boosted tree or a neural network that predicts acceptance, perhaps with a second head for later engagement, since a connection that goes quiet is not much of a win.
  • -Re-rank: remove people the user has dismissed, and spread suggestions across different parts of their network.

Risks and Failure Modes

  • -Rich get richer: people with many connections are suggested more, which gives them more connections. Cap and diversify so quieter users are surfaced too.
  • -Privacy: suggestions can reveal hidden relationships, such as a therapist's patients appearing as suggestions for each other. Respect visibility settings and avoid exposing sensitive links.
  • -Abuse: fake accounts and spammers will target the feature. Add quality signals and rate limits, and watch for sudden bursts.
  • -Feedback loops: only suggested people can be accepted, so the model learns from its own suggestions. Keep some exploration.
  • -Staleness: friend lists change. Refresh lists often for active users and fall back to a general list for others.

Evaluation

  • -Offline: precision at k for accepted requests, split by time, by user segment, and by number of existing connections.
  • -Online: A/B test on accepted connections and the downstream engagement of those connections, with guardrails on reports, blocks, and ignored requests.

Say the privacy risk early in an interview. It is a real issue that a thoughtful candidate raises before being asked.

Interview Signal is part of Pro

See a real weak answer next to a real strong one for this exact topic.

Quiz is part of Pro

Test what you just read with a short quiz, and bank the XP.

Discussion0

Join the Discussion

Sign in to leave comments, reply to others, or like insights.

Sign In to ScaleDojo

No comments yet. Be the first to start the thread!