Native graph storage and memory

Neo4j · Expert · 15 min

Sizing memory and understanding traversal cost both depend on how the store is laid out on disk.

Neo4j is a native graph database: relationships are physical records that point directly to their nodes and neighbouring relationships. Moving from a node to its neighbours follows those pointers instead of looking anything up in an index. This is index-free adjacency, and it is why a traversal's cost depends on the part of the graph it touches, not on total database size.

In the classic record formats, nodes, relationships and properties live in separate store files of fixed-size records. A node record points to its first relationship and first property; each relationship record sits in two doubly linked lists, one per end node. Nodes whose degree exceeds a threshold (about 50) become dense nodes whose relationships are grouped by type and direction, so (n)-[:LIKES]->() on a node with millions of other relationships only walks the LIKES group. Newer Enterprise databases default to the block format, which stores a node's properties and relationships together in larger blocks for better locality.

Memory is split between the JVM heap (query execution, transaction state) and the page cache, an off-heap cache of store file pages. For predictable performance the page cache should hold the whole store, or at least the hot part; neo4j-admin server memory-recommendation suggests sizes. Large transactions and big collect() results consume heap, which is why batching writes matters.

Remember

  • Index-free adjacency: relationships point directly at nodes and neighbours
  • Dense nodes group relationships by type and direction
  • Block format co-locates a node's data for locality
  • Size the page cache for the store and the heap for queries and transactions

Watch out for

  • Giving most RAM to the heap and leaving the page cache too small to hold the graph.

Check yourself

  1. Why does traversing two hops from a node stay fast as the database grows from millions to billions of nodes?

Sign in to answer, see the explanations, and get this lesson back as a quick review later.

Official docs: neo4j.com/docs/operations-manual/current/performance/memory-configuration/

Builds on

Unlocks

Nothing builds on this yet.