Projects / People you may know / Wrap up
Wrap up
Keep going
- Weights. Change the weights in Step 3.3 and see who moves. How would you decide which weights are best?
- Time. Use the
sinceproperty to prefer recent friendships. - Degree limits. Write a version of the suggestion query that skips friends with more than 500 friends. What does it cost, and what does it lose?
- Graph algorithms. Look at the Graph Data Science library for community detection and similarity.
What this version leaves out, and what a real engine does
- Our database is one container. Real deployments run a cluster, with copies of the data for safety and read capacity.
- Our data fits in memory. Real social graphs hold billions of relationships, and how they are laid out on disk starts to matter.
- Suggestions are computed on demand. A real app often precomputes them in a background job and stores the result.
- We used one kind of relationship between people. Real systems keep many kinds, such as follows, blocks and messages, and treat them differently.
- Privacy rules are missing. A real system never suggests someone who blocked you, and must be careful about what a suggestion reveals.
Check yourself
Answer each question in your head first, then open it to check.
In a table database a friends-of-friends query is a self-join. What did the same idea look like here, and why does a long chain get cheaper in a graph?
It was one pattern with two arrows. A graph database stores each relationship with direct pointers from its two nodes, so following a hop means looking at the node's own relationships. A join looks up matching rows in a table for every hop, and the work grows with the size of that table.Why did Asha seem to have four friends in Step 2.5, and what is the rule that prevents it?
The friendship was stored as two arrows, and a query without a direction found both. Store one arrow per mutual friendship, and read it without a direction.What did the uniqueness constraint give us besides the rule itself?
An index onid, so finding a person by id is a direct lookup and not a scan.In Step 4.3, why did the cost not grow with the 5,000 people in the graph?
The query starts from one indexed node and only follows that node's relationships, then theirs. The work depends on how many connections it reaches, not on the total size of the graph.What were the three counts in Step 4.5 for, and what would you suspect if they disagreed?
They check the query from different angles. A disagreement points to a counting mistake: duplicates from several paths, a missingDISTINCT, or a difference in what counts as already a friend.Teach it back: explain to a teammate why
DETACH DELETEexists.A relationship cannot point at a node that is gone, so the database refuses to delete a node that has any.DETACH DELETEis the explicit way to say "remove this node and every relationship attached to it".