Professional Networking Platform
Design the core of a professional network: profiles, connection requests, degrees of separation, visibility by degree, a job board with tracked applications, and a feed.
Overview
A professional network has profiles, a graph of accepted connections, a job board and a feed. The interviewer picks this problem because everyone knows the product, so the hour goes to your design: how the graph is stored, how a request becomes a connection without a race, how far a search may walk the graph, and how one rule table decides what a viewer may see. This is a design exercise. It does not describe how any real company builds its system.
The problem tests four things. First, a request has a life cycle (pending, accepted, ignored, withdrawn) and two people can invite each other at the same moment. Second, the degree of separation between two people is a shortest-path question, and a search that walks the whole graph is too slow, so you must bound it. Third, visibility depends on that degree, and it should be one table, not a chain of if statements. Fourth, a job application only moves forward through its statuses, which is a small state machine.
A strong answer names the entities in the first minutes, puts the request and the graph behind one lock, explains bidirectional search capped at three steps, and writes a program a test can drive.
Scoping the problem
Ask these questions before you draw anything, because each answer changes the design.
- Are connections mutual, or can I follow someone one way? Mutual connections make an undirected graph, and follows add a directed edge. The usual answer is that connections are mutual and companies are followed.
- How far do degrees go? The answer bounds the search, and anyone beyond the bound is out of network. Usually it is 1st, 2nd and 3rd degree.
- What does each degree see on a profile? This becomes a visibility rule table, and usually closer sees more.
- Who may endorse a skill? This is a permission check on the graph. Usually only 1st-degree connections may.
- Can a person apply to the same job twice? This is a uniqueness rule with a race behind it. The usual answer is no: one application per person per job.
- Which application status moves are legal? This is a state machine. Usually moves go forward only, and hired and rejected are final.
- What is in the feed? This decides which authors are pulled and how they are ordered. Usually it is posts by connections and followed companies, newest first.
- Must anything survive a restart? That adds a store, which is not the core of the problem, so treat it as a follow-up.
Functional requirements
- Profiles with headline, summary, experience and skills; 1st-degree connections may endorse a skill
- send_request, accept, ignore and withdraw; a request is one row keyed by (sender, receiver)
- degree(a, b) returns 0 to 3, or None when the two are out of network
- view(viewer, user_id) returns only the fields the viewer's degree allows
- Companies post jobs; people search by title, location and skill, and see jobs ranked by skill overlap
- apply(user_id, job_id) once per person per job; statuses move forward only
- A feed of posts by connections and followed companies, newest first
Non-functional requirements
- Mutual invitations at the same moment connect the pair once and leave nothing pending
- Degree queries stop after three steps and walk from both ends, so cost does not grow with the whole network
- Visibility and status rules are data tables, so a new rule is an edit, not a new branch
- Duplicate applications are refused even when the same person applies from several threads at once
- Time is injected, so feed order is exact in tests
Interview questions
- Two people invite each other at the same moment. What goes wrong, and how does your code prevent it?
- Why bidirectional BFS, and why stop at three steps?
- How would you make the graph fast at scale, and keep degree queries fast?
- How does visibility stay consistent as rules grow, for example a recruiter view or an open profile?
- How would you rank jobs for a person, and how do you keep the ranking swappable?
Sign up free to read the full topic
More Low-Level Design topics
Start free on Cariara · Coding problems · System design studio