You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Graph data modelling is the process of designing your data structure using nodes, relationships, properties, and labels. A well-designed graph model makes queries intuitive, performant, and easy to evolve.
Nodes represent entities — the things in your domain:
:Person, :Employee)(:Person {name: "Alice", age: 30})
(:Product {name: "Laptop", price: 999.99})
(:City {name: "London", country: "UK"})
Relationships connect two nodes and represent how entities are related:
PURCHASED, LIVES_IN, MANAGES)(Alice)-[:PURCHASED {date: "2024-01-15", quantity: 1}]->(Laptop)
(Alice)-[:LIVES_IN {since: 2018}]->(London)
Tip: Relationship types are written in UPPER_SNAKE_CASE by convention.
Properties are key-value pairs stored on nodes and relationships:
| Data Type | Example |
|---|---|
| String | name: "Alice" |
| Integer | age: 30 |
| Float | price: 49.99 |
| Boolean | active: true |
| Date | createdAt: date("2024-01-15") |
| List | tags: ["graph", "database"] |
| Point | location: point({latitude: 51.5, longitude: -0.1}) |
Labels are tags that categorise nodes:
(:Person:Employee:Manager)Identify the main entities in your domain and represent them as nodes:
The actions and connections between entities become relationships:
Descriptive information goes on properties:
name, emaildateDesign the graph model based on the questions you need to answer:
| Question | Model Implication |
|---|---|
| "Which products did Alice buy?" | (:Person)-[:PURCHASED]->(:Product) |
| "Who are Alice's friends?" | (:Person)-[:FRIENDS_WITH]->(:Person) |
| "Which products do Alice's friends recommend?" | Traverse through friends to their reviews |
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.