Design LinkedIn Connections
Understanding the Problem
💼 What is LinkedIn? LinkedIn is a professional social network. Members connect with each other (a connection is mutual: both people agree), and every profile, search result and post shows how far away that person is from you: 1st (you're connected), 2nd (you share a connection), 3rd (two people sit between you) or out of network. Members also search for people by name and search a large catalog of job postings.
The interview question usually centers on the degree of connection: "given two members, how are they connected, and what's the shortest path between them, up to four hops?" Finding a user by name and searching for jobs are often asked as follow-ups or as separate questions. They share the same graph (people search ranks by network distance, and job results show "3 connections work here"), so we cover all three here.
Functional Requirements
Core Requirements
- Users should be able to send connection requests, accept or ignore them, and remove a connection.
- Users should be able to see the degree of connection (1st, 2nd, 3rd) to any member they look at, and the shortest path to them up to four hops.
- Users should be able to search for people by name, with results ranked so the people they're most likely looking for come first.
- Users should be able to search jobs by keyword, location and filters, and see which of their connections work at the hiring company.
Below the line (out of scope)
- The feed, messaging and notifications.
- "People you may know" recommendations (we'll touch on it, since it reuses the same graph queries).
- Recruiter tools, applying to jobs and the hiring workflow.
Non-Functional Requirements
Ask about scale. We'll assume 1 billion members, 100M daily active users, an average of 200 connections per member and a hard cap of 30,000.
Core Requirements
- Degree lookups should be fast: under 50ms at p99, because one page can need dozens of them (a search results page shows a badge on every row).
- People search should feel instant, under 100ms for typeahead and 200ms for the full results page.
- Job search should return in under 300ms and reflect new or closed postings within a minute or two.
- The system should be highly available. A degree badge that's a few seconds out of date is fine. Your own new connection should show up as 1st right away.
- The system should handle members with tens of thousands of connections without hurting everyone else's latency.
Below the line (out of scope)
- Privacy settings on who can see your connections (see /system-design/post-privacy for the same kind of check).
- Multi-region write conflicts.
Now the numbers that shape the design:
- Graph size: 1B members × 200 connections = 200B adjacency entries (each edge stored in both directions, so 100B connections). Member IDs fit in 32 bits, so that's about 800GB of raw neighbor lists. With overhead, call it 1–1.5TB. That fits in memory across a few dozen machines.
- Degree lookups: 100M DAU × 50 badges a day = 5B lookups a day, about 58k/s on average and roughly 150k/s at peak.
- Network size: with 200 connections each, your 2nd-degree network is up to 200 × 200 = 40,000 people, and your 3rd-degree network is up to 8 million.
- Connection writes: say 20M new connections a day, about 230/s. Tiny.
The last two lines are the whole problem. Reads outnumber writes by hundreds to one, and the reads walk a graph whose neighborhoods explode with each hop. Any approach that expands three hops from one side per request touches millions of nodes. Expanding two hops from each side and intersecting touches tens of thousands.
A relational database is the right place to store connections and the wrong place to traverse them. Say this early. Your interviewer wants to see you separate the system of record (a sharded table of edges) from the serving layer (an in-memory graph built for traversal).