Databases
Graph Databases
How graph databases model data as nodes and relationships, when they outperform relational databases, and a Cypher query walkthrough.
- Graph DB
- Neo4j
- Database Design
What is a Graph Database?
A graph database stores data as nodes (entities) connected by relationships (edges), with both nodes and edges able to hold properties. Instead of computing relationships at query time via joins, the relationships are the data structure — making deeply connected queries dramatically faster.
Property Graph Model
| term | meaning |
|---|---|
| Node | An entity — a person, product, place, etc. |
| Relationship / Edge | A named, directed connection between two nodes |
| Property | A key-value attribute on a node or relationship |
| Label | A category/type tag on a node (e.g. Person, Product) |
Querying with Cypher (Neo4j)
Why Graphs Win for Connected Data
A relational query for “friends of friends who like the same movies” needs several joins that get slower as the network grows. A graph database traverses relationships directly, so query time depends on the size of the traversal, not the size of the whole dataset.
| aspect | rdbms (joins) | graph db (traversal) |
|---|---|---|
| Multi-hop queries | Slower — more JOINs = more cost | Fast — follows pointers directly |
| Schema flexibility | Fixed columns per table | Add new relationship types freely |
| Best for | Tabular, aggregate-heavy data | Networks: social, fraud, recommendations |
| Examples | PostgreSQL, MySQL | Neo4j, ArangoDB, Amazon Neptune |
Common Use Cases
- Social networks — friends, followers, mutual connections.
- Recommendation engines — “people who bought X also bought Y” as a graph traversal.
- Fraud detection — spotting rings of connected accounts/transactions that look suspicious together but not individually.
- Knowledge graphs — linking entities and facts for search and AI reasoning (also often paired with a vector database for hybrid search).
When Not to Use a Graph DB
If your data is mostly tabular with shallow relationships (a handful of one-to-many links), a relational database with proper indexes will usually outperform a graph database while being simpler to operate and query with plain SQL.