Why model?
If you use a Neo4j graph to support part or all of your application, you must collaboratively work with your stakeholders to design a graph that will:
-
Answer the key use cases for the application.
-
Provide the best Cypher statement performance for the key use cases.
Components of a Neo4j graph
The Neo4j components that are used to define the graph data model are:
-
Nodes
-
Labels
-
Relationships
-
Properties
Data modeling process
Here are the steps to create a graph data model:
-
Understand the domain and define specific use cases (questions) for the application.
-
Develop the initial graph data model:
-
Model the nodes (entities).
-
Model the relationships between nodes.
-
-
Test the use cases against the initial data model.
-
Create the graph (instance model) with test data using Cypher.
-
Test the use cases, including performance against the graph.
-
Refactor (improve) the graph data model due to a change in the key use cases or for performance reasons.
-
Implement the refactoring on the graph and retest using Cypher.
Graph data modeling is an iterative process. Your initial graph data model is a starting point, but as you learn more about the use cases or if the use cases change, the initial graph data model will need to change. In addition, you may find that especially when the graph scales, you will need to modify the graph (refactor) to achieve the best performance for your key use cases.
Refactoring is very common in the development process. A Neo4j graph has an optional schema which is quite flexible, unlike the schema in an RDBMS. A Cypher developer can easily modify the graph to represent an improved data model.
Check your understanding
1. Neo4j elements for graph data modeling
What Neo4j elements must you understand to begin the graph data modeling process?
-
✓ Nodes
-
✓ Labels
-
✓ Properties
-
✓ Relationships
-
❏ Columns
Hint
These are the key elements of a Neo4j property graph.
Solution
All four options are correct. You will need to know about Nodes, Labels, Properties and Relationships.
2. Iterative modeling
What term do we use to define how we will improve an existing graph data model?
-
❏ Schema evolve
-
✓ Refactor
-
❏ Rebuild
-
❏ Migrate
Hint
This is done by both data modeling stakeholders and Cypher developers to improve the performance of a graph or to accomodate another key use case of the domain.
Solution
The term we use for evolving a data model is Refactoring. In order to optimize your graph model for specific use cases you must Refactor it.
Summary
In this lesson, you learned about the steps for graph data modeling. In the next lesson, you will learn about understanding the domain for a graph data model.