Store things and the links between them, and walk those links quickly (Neo4j).
A graph database stores things and the links between them as first-class data. It is built to answer questions like "who are the friends of my friends?" quickly.
In a relational database, a link between two rows is rebuilt every time you ask, with a JOIN. The database finds matching ids using an index. One join is fine. Six joins in a row on large tables get slow.
A graph database stores the link itself. Many engines use index-free adjacency: each node keeps direct references to its neighbouring relationships. To move from a person to their friends, the engine follows these references. It does not search a big index at every hop. So the cost of a query depends on how much of the graph you touch, not on how big the whole database is.
| Model | How data looks | Query language | Example engines |
|---|---|---|---|
| Property graph | Nodes and edges, both can have properties and labels. | Cypher, openCypher, GQL, Gremlin | Neo4j, Neptune, Memgraph |
| RDF (triple store) | Facts as subject-predicate-object triples. | SPARQL | Neptune, GraphDB, Jena |
| Multi-model | Graph plus documents or key-value in one engine. | AQL and others | ArangoDB, Azure Cosmos DB (Gremlin API) |
| Graph analytics engine | Big batch jobs over a graph (PageRank, communities). | Pregel-style code | Spark GraphX, TigerGraph |
MATCH (me:Person {name: 'Asha'})-[:FRIEND]->(f)-[:FRIEND]->(fof)
WHERE NOT (me)-[:FRIEND]->(fof) AND fof <> me
RETURN fof.name, count(f) AS mutualFriends
ORDER BY mutualFriends DESC
LIMIT 10;SELECT f2.friend_id, COUNT(*) AS mutual FROM friends f1 JOIN friends f2 ON f2.user_id = f1.friend_id WHERE f1.user_id = :me AND f2.friend_id <> :me AND f2.friend_id NOT IN (SELECT friend_id FROM friends WHERE user_id = :me) GROUP BY f2.friend_id ORDER BY mutual DESC LIMIT 10;
A simplified model with maths only (no random numbers). It ignores caching, overlap between friend lists, and the fact that a modern relational database is very good at shallow queries. The honest lesson: the gap grows with depth and data size, and graph databases shine when you hop many times.
| Term | Meaning in easy words |
|---|---|
| Node / vertex | A thing in the graph, such as a person |
| Edge / relationship | A link between two nodes, with a type and a direction |
| Property | A key=value stored on a node or an edge |
| Label | A tag that groups nodes, such as Person or Product |
| Traversal | Walking from node to node along edges |
| Hop | One step along an edge |
| Index-free adjacency | Each node holds direct references to its neighbours, so a hop needs no index search |
| Cypher / Gremlin / SPARQL | Query languages for graphs |
| Super-node | A node with a very large number of edges |
| Knowledge graph | A graph of facts about the world, used to answer questions |
| Choice | We gain | We lose |
|---|---|---|
| Graph database | Fast many-hop queries, clear model | Harder horizontal scale, narrower use |
| SQL with joins | One familiar system, strong for reports | Slow and long queries for deep links |
| Recursive SQL (CTE) | Stay in one database for shallow graphs | Gets slow at depth and size |
| Store both directions of an edge | Easy reverse queries | More storage and writes |
| Keep graph as a read copy | Main database stays simple | Sync delay and an extra pipeline |