20
votes

My question is from the view of developer (not specifically respect to User) and may be bit messy. I want to know that how the structure of Nodes and Relationships is get stored in database logically. Like, when I say that I have bla bla information. Where? - then the answer is, in BOOK, either in form of Grid or lines on a page. In case of RDBMS, data is stored in Grid/Tabular format. But I am unable to understand how graph is get stored in Neo4j/graph database. I am using neo4j client 2.1.2.

1
Think reference chains and graphs: slideshare.net/thobe/an-overview-of-neo4j-internalsduffymo

1 Answers

17
votes

http://www.slideshare.net/thobe/an-overview-of-neo4j-internals is very outdated but this gives you a good overview of Neo4j logical representation.

A node references:

  • its first label (my guess is that labels are stored as a singly linked list)
  • its first property (properties are organized as a singly linked list)
  • its start/end relationships

Relationships are organized as doubly linked lists. A relationship points to:

  • its first property (same as nodes)
  • the predecessor and successor relationship of its start node
  • the predecessor and successor relationship of its end node

Because of this chaining structure, the notion of traversal (i.e. THE way of querying data) easily emerges. That's why a graph database like Neo4j excels at traversing graph-structured data.

My rough guess would be also, since Neo4j version 2.1 (and its newly introduced dense node management), nodes' relationships are segregated by type. By doing so, if a node N is for example a start node for 5 relationships of type A and for 5 million rels of type B, traversing rels of type A for N remains O(n=5).