NoSQLAdvanced
When is a graph database the right tool?
“When would you reach for Neo4j over Postgres?”
What this tests
- Traversal vs join
- Recognising graph-shaped queries
Answers by level
Read the beginner answer first and notice what is missing.
When the queries are traversals — multi-hop paths — not when the data merely has relationships (all relational data does). In a relational store each hop is a self-join on the edge table and the planner’s cost grows per hop; by the third or fourth hop it is unrunnable. A graph engine follows pointers node to node in constant time per hop.
Recommendations, fraud rings, dependency chains, permission inheritance, shortest path.
Green flags · Red flags
Strong green flag · Names the hop count where relational joins break down.
Green flags
- Queries as traversals, not "has relationships"
- Knows the per-hop join cost
- Keeps a relational record of truth
Red flags
- "Data has relationships → graph DB"
- Unaware graph stores are bad at aggregates
Follow-up questions
F1
Is friend-of-friend a good reason to adopt a graph database?
Scenario
A fraud team needs "accounts within 4 hops of a flagged account sharing a device". Postgres or graph, and why?