Your answer is the chapter 6 of the O’Reilly’s Graph Databases book about Graph Database Internals. This chapter describes how Neo4j works internally, including how the Native Graph Storage works.
Neo4j stores nodes, relationships, labels and properties in separated files.
Nodes are stored in the file neostore.nodestore.db
. This file has a fixed-size by each new created node. For each node added to the database this file is increased by 9 bytes. This way a node with id 100 can be easily found in the 900 byte into the file (id 100 x 9 bytes per node = 900 byte). Node records have pointers to the first node relationship, first node property and for the node labels.
Relationships are stored in the file neotore.relationshipstore.db
. This is a fixed-size file too. Each relationship has pointers to the start and end nodes, relationship type (in the neostore.relationshiptypestore.db
file), next and previous relationship records for each of the start and end nodes, and a flag indicating if the relationship is the first in the relationship chain.
Properties of nodes and relationships are stored in the file neostore.propertystore.db
. Each property record has a pointer to the next property and can holds a maximum of 4 properties. Each property has a pointer to the property name (neostore.propertystore.db.index
file), the property type. The property value can be an inline value or a pointer to a dynamic file for large strings (neostore.propertystore.db.strings
) and arrays (neostore.propertystore.db.arrays file
).