Neo4j Data Modeling

How to Design a Neo4j Schema

Neo4j is a graph database management system described as an ACID-compliant transactional database with native graph storage and processing. It implements a labelled property graph model, where nodes and relationships have an ID to uniquely identify them, as well as a set of key-value pairs, or properties, to characterize the nodes and the connections.

Neo4j makes it easy to adjust small details as well as broad definitions, so developers and architects can easily determine the structure of the data model and how to define entities for queries. Developing a Neo4j data model is done feature by feature, user story by user story to match the iterative and incremental delivery of applications.

Some people might start with a piece of paper or a whiteboard, adding node labels and relationship types. Next step would be to write Cypher code and load data to confirm that the structure is correct. Such process can quickly become cumbersome as application complexity increases, and it makes sense to get the assistance of a data modeling tool to smooth the evolution of a graph data model.

Try Hackolade Studio for FREE

There's no risk, no obligation, and no credit card required!

Just access the application in your browser.

Get started for FREE

No credit card. No registration. No download. Runs in browser. No cookies. Local storage of models. Security first.

Neo4j Data Modeling Tool

Hackolade is the pioneer in data modeling for NoSQL databases, having developed a visual tool to perform the schema design of hierarchical and graph structures.

Neo4j data modeling tool

Hackolade is a Neo4j schema design software that dynamically forward-engineers Cypher scripts as the user visually builds a Neo4j data model. It can also reverse-engineer an existing Neo4j instance to derive the schema so a data modeler or information architect can enrich the model with descriptions, metadata, and constraints.

Building on the capabilities of Neo4’s db.schema() command, Hackolade persists the state of the instance data model, and generates HTML documentation of the database schema to serve as a platform for a productive dialog between analysts, designers, architects, developers, and DBAs. The Neo4j schema design tool supports several use cases to help enterprises manage their databases.

Describe the Data Model in Terms of Application Needs

To identify the entities and relationships, it is useful to make an inventory of the questions that will be asked of the data. This approach is often called “query-driven” or “access patterns”-oriented. Agile user stories express the needs which influence the shape and content of the graph data model.

Neo4j data model

By developing the data model in a test-driven approach, the understanding of the domain is documented, so as to validate that queries behave correctly. With test-driven data modeling, unit tests are based on small, representative example graphs drawn from the domain. Query performance tests are written alongside unit tests.

Nodes for Things, Relationships for Connections

Nodes are usually defined to represent the entities -- the things of interest in the application domain. The node properties represent the attributes and metadata of the entities.

Relationships are defined to express the links or connections between the entities, and to structure the domain by establishing the semantic context for each entity. The direction of the relationship further clarifies the relationship semantics. The relationship properties represent the quality or strength of the relationship, plus necessary metadata.

Neo4j nodes visualization tool

A relationship must have a start and an end node, and obviously cannot link more than these 2 entities. If it turns out that something that’s been modeled as a relationship needs to be connected to more than 2 entities, that would be a sign that the relationship needs to be refactored into its own node, and that the data model needs to evolve.

In terms of graph traversal performance, it is preferable to define distinct relationship types if there is a limited enumeration of relationship qualifiers. That’s because relationship type properties are stored separately and hence require an additional storage access. If the enumeration is not limited, then properties best represent qualifiers for the relationship type, for example for shorted-weighted-path algorithms.

Components of a Neo4j Data Model

Conventional relational databases visualize a schemas in Entity-Relationship Diagram. One of the shortcomings is that traditional ER diagrams only allow single, undirected relationships between entities, while in the real-world, relationships between entities are numerous and semantically rich.

With Hackolade, the limits of entity-relationship model conventions are stretched to accommodate the needs of NoSQL document databases and graph databases.

Neo4j Graph Schema Visualization

Graph users and developers prefer to look at structures with circles and curves lines, rather than blocks and straight lines. In effect, the 2 approaches are conceptually similar, with just visual differences. Nevertheless, it is important for a graph data modeling tool to provide the interactions that are most intuitive to users.

A graph view provides a compact, high-level diagram of the graph schema structure:

Neo4j graph schema visualization

Properties for node labels and relationship types are available by drilling into the graph:

Neo4j graph properties views

Entity Relationship Diagram (ERD)

For users who prefer a more traditional ER view, Hackolade was adapted to allow relationships be directed, and have properties. It also lets users define multiple relationships between nodes.

Neo4j ERD entity-relationship diagram

Hierarchical View of Nested Objects

It is not advised to store blobs of data in Neo4j. And Neo4j does not support map data types (equivalent to JSON sub-objects.) But Neo4j does support lists (JSON arrays) but not lists of maps.

Properties (attributes) of either node labels of relationship types can be maintained within the graph diagram, the ER diagram, or in an additional hierarchical schema view with focus on the entity at hand, where metadata, descriptions, and constraints are easily viewed and maintained, along with a log of team comments gathered as the model adapts over time for the schema evolution.

Neo4j hierarchical view of nested objects

Outputs of a Data Modeling Tool for Neo4j

Hackolade dynamically generates the Cypher script derived from the data model created via mouse clicks. When applied to an instance, the script creates a sample graph with nodes and relationships, including constraints and indexes.

Neo4j visual data modeling tool generates Cypher script

A rich HTML documentation provides a human-readable report that includes diagrams, node label details, relationships types, and all their metadata. Many additional features have been developed to help data modelers.

Benefits of Data Modeling

Information stored in databases drives businesses decisions. Data modeling becomes critical to leverage data as a corporate asset, understand data interrelationships, and its rules. Hackolade increases agility of a data-centric architecture by making its structure transparent and by facilitating its evolution. The benefits of data modeling for Neo4j are extensive and measurable.

NoSQL schema design is a best practice so applications can evolve, scale, and perform well. An effective data model contributes to the reduction in development time, the increase in application quality, and the lowering of execution risks across the enterprise.

Free trial

To experience the first Neo4j data modeling tool and try the full experience of Hackolade Studio free for 14 days, download the latest version of Hackolade Studio and install it on your desktop. There's no risk, no obligation, and no credit card required! The software runs on Windows, Mac, and Linux, plus it supports several other leading NoSQL databases. Or you can run the Community edition in the browser.

Try Hackolade Studio for FREE

There's no risk, no obligation, and no credit card required!

Just access the application in your browser.

Get started for FREE

No credit card. No registration. No download. Runs in browser. No cookies. Local storage of models. Security first.