Design People You May Know
Understanding the Problem
🤝 What is People You May Know? People You May Know (PYMK) is the module on a social or professional network that suggests accounts you might want to connect with: a former classmate, a colleague who just joined, a friend of three of your friends. It's a link prediction problem on a graph of a billion members: out of everyone on the network, find the few dozen people you already know or would want to, and rank them by how likely a connection request is to be sent, accepted, and turn into a real relationship.
PYMK matters more than its size on the screen suggests. On social networks, how many connections a new member makes in their first weeks is one of the strongest predictors of whether they stay, and PYMK is how most of those connections get made. It's a growth system as much as a recommender.
The graph infrastructure (storing a billion-member connection graph, degree lookups, shortest paths) is covered in Design LinkedIn Connections. Here we focus on candidate generation over the graph and the ranking model.
Functional Requirements
Core Requirements
- The system should show each member a ranked list of suggested people, on a dedicated page and in modules elsewhere (the feed, after accepting a request, during sign-up).
- Candidates should come from the connection graph (friends of friends), shared context (same school, employer, city, groups), interests, and contacts the member chose to upload.
- Suggestions should be ranked by the likelihood the member sends a request and the other person accepts it.
- Dismissed suggestions shouldn't come back, blocked people must never appear, and suggestions must not expose private information.
Below the line (out of scope)
- Graph storage, connection requests and notifications.
- People search.
- "Follow" suggestions for creators and pages (a related problem, more like content recommendation).
Non-Functional Requirements
Core Requirements
- 1 billion members, 300 million daily active, an average of a few hundred connections each, with a long tail of members with thousands.
- PYMK modules are requested about 20,000 times per second at peak, and should return in under 200 ms at p99.
- Freshness: after a member makes a new connection, their suggestions should reflect it within minutes. New members need good suggestions on their first screen.
- Privacy and safety: suggestions must never reveal sensitive relationships, suggest minors to unknown adults, or help harassers find people who blocked them.
Below the line (out of scope)
- Cross-region graph replication.
The candidate math is what makes PYMK interesting. With an average degree of 300, a member has up to 300 × 300 = 90,000 two-hop paths. Many of those land on the same people, so call it tens of thousands of distinct friends of friends. For a member with 5,000 connections, it's millions. And across the whole network:
1B members × ~90,000 two-hop paths ≈ 10^14 path enumerations
That's far too much to recompute daily for everyone. Two practical moves fix it: only expand through each member's strongest ~100 ties (cutting it to ~10,000 paths per member), and only recompute for members who are active or whose neighborhood changed. That brings the daily batch down to on the order of 10^12 to 10^13 path enumerations, which a large Spark job can handle.
Lead with the fact that PYMK is a two-sided problem. A suggestion only works if both people want the connection. Ranking by "would the viewer click Connect" alone fills celebrities' inboxes with requests they'll ignore, and makes the product feel spammy for everyone.
Framing It as an ML Problem
ML Objective
The business wants healthy network growth: more connections that lead to activity (messages, comments, feed engagement between the two), especially for new members. It does not want connections nobody uses, unwanted requests, or suggestions that feel creepy.
The model predicts, for a viewer v and candidate c:
- P(invite | impression): the viewer sends a request after seeing the suggestion.
- P(accept | invite): the candidate accepts it.
- P(active | connection): the two interact within 30 days of connecting.
And we combine them:
score(v, c) = P(invite) × P(accept | invite) × (1 + λ · P(active | connection))
P(invite) × P(accept) is the probability that showing this suggestion produces a connection. The activity term favors connections that matter. A negative term for "I don't know this person" reports can be subtracted the same way.
Inputs and Outputs
- Input: viewer ID, surface (PYMK page, new-member onboarding, post-accept module), and the graph and profile data for the viewer and candidates.
- Output: an ordered list of ~20 suggestions, optionally with a reason ("12 mutual connections", "Also worked at Acme"), plus a request ID for logging.
Choosing the ML Approach
Link prediction framed as ranking, in three stages:
- Candidate generation: graph algorithms and context matching propose ~2,000 people per viewer, mostly precomputed daily.
- Ranking: a model scores each viewer × candidate pair with the multi-task outputs above.
- Re-ranking: caps (no more than a few suggestions per day to the same popular candidate across all viewers), diversity of sources, fatigue for suggestions already shown many times.
Unlike a content recommender, the "items" are people, and the features that matter are pair features (how the two are related in the graph), not item features. That's what makes graph-based candidate generation and pair features the core of the design.
Data and Labels
Sources
- Graph: connection edges with creation times, plus the follow graph and group memberships.
- Profiles: schools and employers with dates, city, industry, skills. On a social network: hometown, school, workplace.
- Interactions: profile views (in both directions), messages, comments and reactions on each other's content, appearing in the same photos, being in the same events or groups.
- Contacts: address books members chose to upload, and phone numbers or emails they registered with. Strictly opt-in.
- PYMK logs: impressions (suggestion shown in the viewport), invites sent, accepts, ignores, dismissals ("X" on a card), "I don't know this person" reports.
How labels are produced
- Invite label: did the viewer send a request within the session (or a day) of the impression?
- Accept label: did the candidate accept within, say, 14 days? This label is delayed; many accepts come days later, when the candidate next opens the app. We wait the full window before using an invite as a negative.
- Activity label: did they interact within 30 days of connecting? Even more delayed, and computed in a daily batch.
- Negatives: impressions with no invite; invites ignored or declined after the window; explicit dismissals and "don't know" reports as strong negatives.
Selection bias in the accept head. We only observe accepts for invites that were sent, which are already the best suggestions. A model trained on sent invites never sees the pairs it will be asked to score. The fix is to model P(invite and accept) over all impressions as P(invite) × P(accept | invite), the same structure used for CTR and conversion in Ads Ranking.
Class imbalance. Invite rates per impression are low (a few percent), and the conversion all the way to an active connection is lower. Keep all positives and downsample negatives, with the usual correction.
Label leakage. The graph changes constantly, so features must be computed from the graph as of the impression time. If "mutual connections" is computed from today's graph, it includes connections formed because of the suggestion, and the edge between viewer and candidate itself can leak into a 2-hop count. Training on logged features (or point-in-time graph snapshots) avoids this.
A common mistake is training link prediction by randomly hiding edges in today's graph and predicting them back. That's a fine academic setup, but it ignores time: the model learns from future edges. For a production system, train on what was shown and what happened next.
Feature Engineering
Viewer features
- Degree, account age (new members behave completely differently), activity level, how many invites they usually send and how selective they are.
- Country, language, school and employer profiles, completeness of profile.
Candidate features
- Degree, account age, activity, profile completeness and photo.
- Invite load: how many invites they receive per week and what fraction they accept. A candidate who accepts 5% of invites gets a low P(accept) for everyone.
- Account trust score (likely fake or spam accounts are filtered or heavily penalized).
Pair features (the core)
- Graph proximity: number of mutual connections; Adamic-Adar (sum over mutuals of 1 / log(degree of the mutual), so a mutual friend with 100 connections counts more than one with 5,000); Jaccard similarity of neighborhoods; personalized PageRank score from viewer to candidate.
- Tie strength of the mutuals: three close friends in common beat ten acquaintances in common.
- Shared context: same school with overlapping years, same employer with overlapping dates, same city, same groups, same events.
- Interaction signals: viewer viewed candidate's profile (or the reverse), commented on the same posts, tagged in the same photos, in each other's contacts (if both opted in).
- Embedding similarity: dot product of graph embeddings, interest embedding similarity.
- Demographics distance: age bucket difference and distance between cities, as weak signals.
Context features
- Surface (onboarding vs PYMK page vs post-accept), position on the page, how many times this suggestion has been shown before (impression count), time since the last impression.
Real-time vs batch
- Batch (daily): graph proximity features, embeddings, shared-context matches, candidate invite-load stats.
- Streaming (minutes): new connections and the resulting new mutuals, recent profile views, recent dismissals.
Pair features are expensive to store (one row per viewer × candidate), so we store them with the precomputed candidate list rather than for all pairs, and compute a few (mutual count with the latest edges) online through the graph service.
Modeling
Candidate Generation
The biggest decisions are here: ranking can only choose among people candidate generation found.
- Friends of friends, the dominant source: two-hop neighbors through the viewer's strongest ties, with mutual count and Adamic-Adar computed along the way. On social networks a large share of accepted connections comes from this source alone.
- Random walks and personalized PageRank: short walks from the viewer that tend to land on people who are well connected to the viewer's neighborhood, including three-hop candidates FoF misses. Precomputed with Monte Carlo walks.
- Shared context: everyone who attended the same school in overlapping years, worked at the same employer at the same time, or belongs to the same small groups. Matched with inverted indices on (school, years) and (employer, dates).
- Contacts: members whose phone or email appears in the viewer's uploaded address book, or whose address book contains the viewer. Very high precision, and the most privacy-sensitive.
- Graph embeddings + ANN: node embeddings trained on the graph (node2vec-style random-walk embeddings, or a GNN like GraphSAGE), indexed in an ANN index so we can fetch the nearest few hundred members to the viewer's embedding. This catches people who are close in the graph's structure but not within two hops.
Each source gets a quota, the merged list is deduplicated, and existing connections, pending invites, blocked members, people the viewer dismissed and accounts flagged as fake are removed.
Ranking
Bad Solution: Rank by Mutual Connections
Approach
Sort friends of friends by mutual connection count.
Challenges
It's a reasonable first feature and easy to explain ("12 mutual friends"). But it's biased towards popular people (a local celebrity shares mutuals with everyone), it ignores shared context (a colleague with 2 mutuals is a better suggestion than a stranger with 10 through a large group), it can't rank non-FoF sources against FoF ones, and it says nothing about whether the candidate would accept.
Good Solution: GBDT on Graph and Context Features
Approach
Train a gradient-boosted tree model (XGBoost or LightGBM) on the pair, viewer, candidate and context features to predict P(invite), and a second one for P(accept | invite), trained on all impressions with the product structure.
Challenges
This is a strong baseline and often a very good production model: the features are dense, crisp and well understood, and trees handle them well. Its limits are that every relationship pattern must be engineered as a feature, it can't use raw IDs or embeddings richly, and two separate models don't share what they learn.
Great Solution: Multi-Task Model With Graph Embeddings
Approach
A deep model over the pair:
- Viewer and candidate towers built from their profile features and GNN embeddings. A GraphSAGE-style model aggregates features from sampled neighbors, so a member's embedding reflects their neighborhood, not just their own profile. New members get useful embeddings from their first few connections.
- Pair features (mutual counts, Adamic-Adar, shared context, interactions) fed through their own MLP. These carry most of the signal and must not be lost inside the towers.
- Interaction layer between the towers and the pair features.
- Heads for P(invite), P(accept | invite) (trained as the product over impressions), P(active), and P(dismiss / don't know).
Challenges
GNN training on a billion-node graph needs neighbor sampling and a distributed graph store; embeddings are recomputed daily or weekly, so they lag the graph a little. The pair-feature MLP and the towers can't be split into a pure two-tower model, so this model is used in ranking, while a two-tower version of the GNN embeddings powers the ANN candidate source.
Re-Ranking
- Recipient caps: limit how many viewers see the same candidate in a day, proportional to their capacity to respond. A popular person suggested to 50,000 people a day gets a flood of requests.
- Fatigue: demote suggestions after several impressions without an invite. If you've ignored someone 5 times, you probably don't want to connect.
- Source diversity: mix school, work and FoF suggestions, so the page isn't all one context.
- Reasons: attach the strongest explainable reason (mutuals, shared employer), filtered by privacy rules (never "they have you in their contacts").
Training
Losses. Binary cross-entropy per head. The P(invite and accept) head is trained on all impressions; there's no separate accept head trained only on sent invites.
Negatives. Impressions without an invite, after the session ends; invites not accepted within 14 days; dismissals as weighted negatives. Don't treat unshown candidates as negatives; the viewer may know them well.
Imbalance. Downsample non-invite impressions; correct predictions back for the re-ranking caps, which use absolute probabilities to estimate how many invites a candidate will receive.
Cadence. Daily retraining of the ranker; weekly GNN embedding training with daily inference for new and changed members; daily candidate generation for active members, plus incremental refresh after graph changes.
Scale. 300M daily active members × ~20 impressions on the days they see PYMK, so on the order of a few billion impressions a day. Plenty for a daily retrain after downsampling.
Evaluation
Offline Metrics
- Ranking: AUC and log loss per head, on a time-based split.
- Candidate recall: of the connections members actually formed in the next 7 days (by any route, including search), what fraction were in their candidate list? This measures candidate generation separately from ranking.
- Recall@K and precision@K of accepted invites in the top 20.
- Segments: new members, members with few connections, high-degree members, by country. A model that improves established members and hurts new ones is a bad trade.
Online Metrics and A/B Testing
- Primary: accepted connections per viewer (not invites sent), connections that become active.
- Growth: new-member connections in the first 7 days and new-member retention.
- Guardrails: "I don't know this person" and report rates, blocks after connecting, invites received per member (especially for high-degree members), accept rate, privacy complaints.
PYMK experiments have strong network effects: if treatment viewers send more invites, control members receive more of them, and accept rates in both arms change. Measure outcomes on the recipient side too, and use cluster-based randomization (partition the graph into communities and randomize by community) when the effect on recipients matters, accepting a loss of statistical power.
Serving
PYMK is mostly batch prediction with online re-scoring:
- Daily batch: a Spark (or graph-processing) job takes a snapshot of the graph, generates candidates from each source for every active member, computes pair features, and writes the top ~2,000 candidates with features into a key-value candidate store.
- Incremental refresh: connection changes stream through Kafka (change data capture from the graph database). When a member makes a new connection, a Flink job adds the new friend's strongest ties as candidates and updates mutual counts, so suggestions change within minutes. This is especially important during onboarding, when every connection changes the neighborhood a lot.
- Online ranking: at request time the PYMK Service reads the candidate list, filters dismissed and blocked members, fetches fresh features, scores the candidates and applies re-ranking.
Latency budget for 200 ms at p99:
| Step | Budget |
|---|---|
| Read candidate list (~2,000 with stored pair features) | ~15 ms |
| Filter dismissed, blocked, already connected | ~10 ms |
| Fresh features (live mutual counts for top ~300, member features) | ~40 ms |
| Score ~2,000 with GBDT or ~300 with deep model | ~40 ms |
| Re-rank, caps, reasons | ~15 ms |
| Network and slack | the rest |
If the batch output for a member is missing or stale, fall back to an online FoF expansion through the graph service limited to their top ties, or to shared-context candidates.
Potential Deep Dives
1) How do we generate graph candidates for a billion members?
Bad Solution: Full Two-Hop Join Every Day
Approach
Self-join the edge table in Spark to get every two-hop path for every member, group by (viewer, candidate), count mutuals.
Challenges
About 10^14 paths, with huge skew: a member with 5,000 connections connected to others with 5,000 produces 25 million paths alone. The job is slow, expensive, and the skewed keys make it fail in practice.
Good Solution: Truncated FoF on Strong Ties
Approach
For each member, keep only their top ~100 ties by tie strength (interaction-weighted). Expand two hops through those, cap the fan-out from any single high-degree node, and keep the top candidates per viewer by weighted mutual count. Only recompute for members who were active in the last 30 days.
Challenges
Much cheaper, and strong ties produce better suggestions anyway. But it still recomputes a lot every day, misses candidates connected through weaker ties, and lags behind changes by up to a day.
Great Solution: Incremental Updates Plus Walks and Embeddings
Approach
Combine the truncated batch job with event-driven incremental updates: a new edge (A, B) only changes the two-hop neighborhoods of A, B and their strongest ties, so we update those candidate lists from the stream instead of recomputing the world. Add random-walk candidates (personalized PageRank with a few hundred short walks per member, which is cheap and naturally down-weights hubs) and embedding-based candidates through an ANN index, which reach people the truncated FoF misses.
Challenges
Incremental and batch results must be merged carefully: the daily job is the source of truth, and the stream patches it until the next run. Hubs need special handling in every method (cap their contribution, or treat them as "context" like a large group rather than as a friend).
2) How do we suggest people to a member with no connections?
New members are where PYMK matters most and works worst: no graph, no history.
- Contacts: if the member opts in to uploading their address book, contacts already on the network are the highest-precision candidates by far. Members whose own uploaded contacts include the new member's email or phone are candidates too, subject to privacy rules.
- Onboarding data: school, employer, city entered at sign-up; the email domain for professional networks (a work email at acme.com points at Acme employees).
- Invite source: a member who signed up from someone's invitation link should see that person first, then their connections.
- Bootstrap quickly: after the first one or two connections, FoF through those connections becomes available, and the incremental refresh makes the next page better within minutes. New-member onboarding is the surface where incremental updates pay off most.
- A separate model or segment for new members, because the features that matter (contacts, shared context) are completely different from those for established members.
3) How do we avoid suggestions that are creepy or harmful?
Some of the most effective signals are also the most sensitive. A suggestion can reveal that someone has you in their contacts, viewed your profile, or was at the same place. This matters as much as accuracy:
- Never explain with sensitive reasons. Show "12 mutual connections" or "Also worked at Acme," never "has your number."
- Sensitive-relationship protection. A contact-book match between a doctor and a patient, or a therapist and a client, can reveal something private. Allow members to opt out of being suggested via contacts, give extra weight to dismissals, and avoid using signals like precise location co-occurrence at all.
- Blocks and safety. Blocked members are filtered at every stage and in both directions. Don't suggest a member to someone they've blocked, and don't suggest accounts of minors to adults outside their school or family network.
- Fake accounts and scrapers. A spammer wants to be suggested to as many people as possible. Account-trust scores filter candidates, and per-sender invite rate limits stop mass invites.
- Policy review of features. Any new signal used in PYMK should go through a privacy review, because members don't expect it to be used to find them.
Interviewers notice when you bring up privacy without being asked. In PYMK it's not a side note: a single creepy suggestion is a news story, and the strongest features (contacts, profile views) are exactly the ones that can cause it.
4) How do we avoid overloading popular members?
The ranking model's P(accept) helps, but caps are still needed:
- Recipient capacity: estimate how many invites a member can respond to per week. In re-ranking, track how many viewers we've shown a candidate to today and demote them once expected invites (Σ P(invite)) exceed their capacity.
- Low-accept candidates: members who rarely accept are naturally demoted by P(accept), so suggestions go to pairs who both want the connection.
- Follow instead of connect: for public figures and creators, suggest following instead, which doesn't create a request they have to handle.
5) How do we keep suggestions fresh?
- Graph events (new connection, new job, joined a group) trigger incremental candidate refresh.
- Impression fatigue removes suggestions shown many times without action, so the page doesn't show the same 20 people every week.
- Time-sensitive context: a member who just changed employers should see their new colleagues first; candidates from the new employer get a boost that decays over a few weeks.
- Monitoring: candidate list freshness (age of the batch output per member), share of impressions coming from stale lists, and accept rate by candidate age.
What is Expected at Each Level?
Mid-level
You should frame PYMK as link prediction, propose friends of friends as the main candidate source with mutual connections and shared context as features, train a GBDT on impressions with invite labels, and evaluate with AUC and accepted connections in an A/B test. With prompting, you should recognize the need for P(accept) and handle new members with contacts and onboarding data.
Senior
You should design the two-sided objective (P(invite) × P(accept)), multiple candidate sources with quotas, and pair features like Adamic-Adar and shared context with time overlap. Expect to discuss delayed accept labels and selection bias, point-in-time graph features to avoid leakage, the batch-plus-incremental pipeline, the scale of two-hop expansion and how to truncate it, and privacy rules for reasons and contacts.
Staff+
You should drive the conversation to the system-level trade-offs: how PYMK fits network growth and new-member retention, recipient load as a marketplace constraint, network effects in experiments and cluster randomization, GNN embeddings vs graph heuristics and where each belongs, and the privacy and safety review that every new signal needs. Knowing that a GBDT on strong graph features is often the production answer, and that candidate recall usually matters more than a better ranker, is a strong signal.