Projects / People you may know
Neo4j · about 10 hours · 4 phases
Build a friend suggestion engine in Neo4j
When we open a social app, it shows a row of "people you may know". Behind that row sits a question about connections: who is a friend of my friends, and not yet my friend? In a table database that question needs a join, then another join, then another one for every extra hop. In about 10 hours we will build the engine ourselves in Neo4j, a database that stores connections as first-class things: a small social graph, suggestions ranked by mutual friends and shared interests, a look at why the query stays fast, and a check that three different queries agree.
You work in four phases of about 2.5 hours each. Every phase ends with something you can run and see. By the end you will have:
- twelve people and fourteen friendships in a graph, with a rule that blocks duplicate people,
- friends, friends of friends and the shortest route between two people, each as one short query,
- a ranked list of suggestions that mixes mutual friends with shared interests,
- a 5,000 person graph where you read the query plan and see how much work a suggestion costs,
- three different ways of counting the same suggestions, and all three agree.
You only need to know what a table and a row are. Cypher, the query language, is explained as it appears.
The four phases
People and friendships
You end with twelve people, fourteen friendships and a rule that refuses a second person with the same id.
- 1.1 Your first two people20 min
- 1.2 Ten more at once20 min
- 1.3 A rule for unique ids20 min
- 1.4 Try to break it15 min
- 1.5 Friendships40 min
- 1.6 Direction25 min
Friends, friends of friends and routes
You end with a list of suggested friends for Asha, ranked by mutual friends, plus the shortest route between two people.
- 2.1 Friends20 min
- 2.2 Friends of friends40 min
- 2.3 Any number of hops30 min
- 2.4 The shortest route25 min
- 2.5 Two arrows for one friendship25 min
Ranked suggestions
You end with a top five list for Asha ranked by a score, and a plan that shows what an index changed.
- 3.1 Interests30 min
- 3.2 People who share interests30 min
- 3.3 One score50 min
- 3.4 Read the plan25 min
- 3.5 Add an index20 min
Five thousand people
You end with a graph of 5,000 people, a suggestion query with its cost, and three counts that agree.
- 4.1 Load 5,000 people25 min
- 4.2 Give them friends35 min
- 4.3 A suggestion, and what it cost35 min
- 4.4 Who has the most friends20 min
- 4.5 Count the same thing three ways25 min
- 4.6 Deleting a person20 min