Design People You May Know: Graph-Based Friend Recommendations

ML system design for People You May Know: friends-of-friends candidates, graph embeddings, link prediction, batch precomputation and accepted connections.

Advanced 3 min read · Updated

The question: design "People You May Know" (PYMK) for a social or professional network: suggest people a user is likely to know and connect with. It's a recommendation problem on a graph, where the strongest signals are mutual connections, shared schools and workplaces, and contacts, and where the candidate space (every member) is too large to score directly.

1. Clarify requirements

QuestionAnswer
Goal?More meaningful connections, which drive engagement and retention, especially for new users
Scale?1B users, average 300 connections, graph of ~150B edges
Surfaces?A PYMK module on the home page and the network tab; also emails
Freshness?Suggestions can be computed daily, but should react to a new connection within minutes
Constraints?Privacy: don't reveal sensitive relationships; allow opting out; respect blocks

2. Frame it as an ML problem

Link prediction: for a (viewer, candidate) pair, predict p(connection request sent and accepted) within some window. Optimising only sends would reward spammy suggestions; acceptance captures real relationships.

3. Candidate generation

Scoring a billion people per user is impossible, so generate a few thousand candidates from several sources:

ViewerFriends of friends2-hop walkShared affiliationsschool · employerImported contactswith consentGraph embeddingsANN neighboursMerge + dedupe~3,000Rankerp(accept)Top 20
Candidate sources for PYMK. Friends-of-friends gives most good candidates; shared affiliations and contacts add people with few mutual friends; graph embeddings find the rest.
  • Friends of friends (FoF): with 300 connections each, a user has up to ~90,000 two-hop neighbours. Keep those with the most mutual connections (cap per hop to avoid celebrities exploding the walk).
  • Shared affiliations: same school and graduation years, same employer and team, same city.
  • Contacts: people whose phone number or email is in the user's uploaded address book (and vice versa), with consent.
  • Graph embeddings: node embeddings (node2vec-style random walks, or a graph neural network) placed in an ANN index to find people close in the graph who aren't two hops away.

4. Features and model

GroupExamples
Graph overlapNumber of mutual connections, Adamic-Adar score (mutuals weighted by how selective they are), common neighbours ratio
AffiliationSame school and overlapping years, same company and overlapping tenure, same city
InteractionProfile views in either direction, appearing in the same group or thread, tagged together
CandidateAccount age, connection count, acceptance rate of past requests, activity
ViewerNetwork size (new users need suggestions most), recent activity
EmbeddingSimilarity of viewer and candidate graph embeddings

A gradient-boosted tree or deep ranker predicts p(accept). Mutual connections are typically the strongest feature, but weighting them (a mutual who has 5,000 connections means less than one who has 50) improves results. See embeddings and choosing a model.

5. Batch plus real-time serving

Graph snapshotDaily batch jobcandidates + scoresSuggestions storeuser → top 200New connection eventReal-time updateradd new FoFPYMK APIfilter + rerank
PYMK runs mostly offline: a daily graph job generates and scores candidates into a key-value store. A real-time path reacts to new connections by adding their friends as fresh candidates.
Daily batch : 1B users × ~3,000 candidates = 3T pairs to score → too many;
              prune FoF by mutual count first (keep ~500), score 500B pairs on a big
              Spark/GPU cluster, store top 200 per user: 1B × 200 × 8 B ≈ 1.6 TB
Online      : read top 200, drop already connected/pending/dismissed/blocked,
              light rerank with fresh signals, return 20 in < 50 ms

6. Product and privacy rules

  • Never suggest people the viewer blocked or who blocked them; respect "don't suggest me" settings.
  • Be careful with sensitive inference: suggesting a therapist's other patients, or revealing that two people share a contact, is a real harm. Exclude sensitive contact categories and some signals entirely.
  • Remove a suggestion after dismissal and don't bring it back for a long time.
  • Limit how many times one person is suggested to others per day, so popular users aren't flooded with requests.

7. Evaluation

  • Offline: recall@k of connections formed in the following week (time-based split); AUC of p(accept).
  • Online: accepted connections per user, acceptance rate of sent requests, new-user connections in the first week, plus guardrails: request ignore and report rates.
  • Watch the graph effect: a test arm changes who connects to whom, which affects control users too. Cluster-based randomisation (by community) reduces this leakage. See A/B testing.

Where it’s used

Social networks

Friend suggestions dominated by mutual friends, contacts and shared groups.

Professional networks

Connection suggestions weighted towards shared employers, schools and industry.

Follow suggestions

"Who to follow" mixes graph proximity with interest similarity and creator popularity.

In an interview

  • Frame it as link prediction on accepted connections, not sent requests.
  • Generate candidates from friends of friends, affiliations, contacts and graph embeddings.
  • Compute heavy scoring in daily batch, with a real-time path for new connections.
  • Address privacy, blocking and the network effect in experiments.

Frequently asked questions

How does People You May Know work?

It generates candidates from friends of friends, shared schools and workplaces, contacts and graph embeddings, ranks them with a model predicting accepted connections, mostly in daily batch, and updates in real time when you make a new connection.

What is the strongest signal for friend recommendations?

Mutual connections, ideally weighted so that a mutual friend with few connections counts more than one with thousands.

Further reading