Database DesignGraph Databases (Neo4j)Medium⏱️ ~2 min

Graph Database Use Cases: When to Use vs When to Avoid

Ideal Use Cases

Graph databases excel at OLTP (Online Transaction Processing: real-time operations like lookups and updates, as opposed to batch analytics) workloads with bounded traversals where query patterns naturally map to exploring local neighborhoods.

Fraud detection: finding cycles within 3 hops (money laundering rings), detecting accounts sharing devices/addresses, identifying suspicious clusters. These touch hundreds to thousands of nodes needing results in tens to hundreds of milliseconds with ACID guarantees (Atomicity, Consistency, Isolation, Durability: ensures transactions either fully complete or fully rollback) for real-time alerts.

Dependency tracking: Supply chain (part depends on supplier depends on raw material), IT infrastructure monitoring (service depends on database depends on storage). Authorization systems with RBAC (Role-Based Access Control: permissions assigned to roles, users get roles) or ABAC (Attribute-Based Access Control: permissions based on user/resource attributes) with nested group hierarchies benefit because multi-hop traversals match the permission inheritance model.

When to Avoid

High-throughput feed fan-out: Writing to millions of follower inboxes per post creates massive write amplification and cross-partition coordination. Use denormalized fan-out tables or specialized feed services instead.

Global analytics: Algorithms like PageRank (iteratively computing node importance by counting and weighting incoming edges) or community detection over billions of edges require full graph scans and iterative computations. These belong in batch processing frameworks, not OLTP graph stores.

Decision Framework

The key criterion is query locality. Bounded multi-hop from specific start (friends within 3 hops) = graph delivers millisecond latency. Global computation across entire graph (PageRank) = batch processing. High write throughput to millions of targets = specialized infrastructure.

💡 Key Takeaways
Ideal for fraud detection: finding transaction cycles within 3 hops, detecting clusters sharing devices/addresses with ACID guarantees
Ideal for dependency tracking: supply chain, IT infrastructure, and authorization with RBAC/ABAC permission inheritance hierarchies
OLTP (Online Transaction Processing): real-time lookups and updates. ACID: transactions fully complete or rollback. Graph databases are OLTP systems.
Avoid for feed fan-out: writing to millions of inboxes creates write amplification; use denormalized tables or specialized services
Avoid for global analytics: PageRank (iterative node importance calculation) requires full scans; use batch graph processing
Decision criterion is query locality: bounded local traversals (milliseconds) vs global computations (hours) vs high-write fan-out (specialized)
📌 Interview Tips
1Fraud detection: "find accounts within 3 hops of flagged account sharing same device or phone". Touches ~5,000 nodes, returns in 50ms with ACID, triggers real-time alert.
2Authorization query: "can user X access resource Y?" Traverse MEMBER_OF → HAS_ROLE → HAS_PERMISSION edges. 3 hops, 20ms. RBAC hierarchy stored as graph.
3Wrong tool: "compute PageRank for 1B nodes" requires iterating entire graph ~20 times. Hours in batch system. Materialize scores as node properties for OLTP queries.
← Back to Graph Databases (Neo4j) Overview