Neo4j

Neo4j is a graph database where relationships are first-class citizens. Instead of joining tables to follow connections, you store nodes and the typed relationships between them and traverse them directly — which makes deeply connected queries dramatically faster and simpler to express.

It shines when the relationships are the value: social graphs, recommendations, permission hierarchies, fraud rings, and knowledge graphs. For tabular data with few relationships, a relational database is still the better tool.

TL;DR

Quick Example

Cypher reads like ASCII-art of the graph — here, "products bought by people who bought what this user bought":

Core Concepts

Common Uses

Best Practices

Comparison: Graph vs Relational

Common Mistakes

Forcing a relational schema into a graph

Unbounded traversals

FAQ

When should I use a graph database?

When relationships and their traversal are central — recommendations, fraud/link analysis, permission hierarchies, and knowledge graphs. Queries that would need many self-joins or recursive CTEs in SQL often become short, fast Cypher patterns. For mostly tabular data, stick with relational.

What is Cypher?

Neo4j's declarative query language. It uses ASCII-art patterns — (node)-[:REL]->(node) — to match and return subgraphs, making relationship queries far more readable than the equivalent SQL joins.

How is a graph database different from relational joins?

Relational databases compute joins at query time, which gets expensive as you chain many or variable-depth relationships. Graph databases store relationships as direct pointers, so traversals are local and stay fast regardless of total dataset size.

When should I not use Neo4j?

When your data is mostly tabular with few relationships, or your workload is large-scale aggregations and reporting — a relational database or analytics store will outperform it. Use a graph database for the connections, not as a general-purpose store.

Related Topics

References