Module 4 β Relationships & Graph Modeling
π― Module Objective
By the end of this module, you will:
- Understand how relationships work in DTDL
- Learn how to connect twin models
- Understand graph-based architecture
- Model system dependencies
- Perform impact-aware design thinking
- Think like a Digital Twin Architect
This is where Azure Digital Twins becomes powerful.
1οΈβ£ Why Relationships Matter
If you only define properties, you have structured data.
If you define relationships, you have a graph.
And graphs enable:
- Dependency tracing
- Impact analysis
- Topology modeling
- Contextual queries
This is the real value of Azure Digital Twins.
2οΈβ£ What Is a Relationship?
A relationship connects one twin to another.
Example:
Building β contains β Floor
Floor β contains β Room
Room β contains β Device
Relationships create edges in the twin graph.
3οΈβ£ Relationship in DTDL
Here is a basic example:
{
"@type": "Relationship",
"name": "contains",
"target": "dtmi:com:smartbuilding:Room;1"
}
Letβs break this down:
- @type β Relationship
- name β Relationship name
- target β Target model DTMI
This means:
This model can connect to another model of type Room.
4οΈβ£ Full Example β Building Model
{
"@id": "dtmi:com:smartbuilding:Building;1",
"@type": "Interface",
"@context": "dtmi:dtdl:context;2",
"displayName": "Building",
"contents": [
{
"@type": "Relationship",
"name": "contains",
"target": "dtmi:com:smartbuilding:Floor;1"
}
]
}
This defines:
A Building can contain Floors.
But remember:
This defines the allowed relationship type.
The actual connection happens when creating twin instances.
5οΈβ£ Direction Matters
Relationships are directional.
Building β contains β Floor
NOT automatically:
Floor β contains β Building
If you need bidirectional logic, you must define it separately.
Architectural insight:
Always think about direction carefully.
6οΈβ£ Real-World Graph Example β Smart Factory
Letβs model:
Factory
β contains β ProductionLine
β contains β Machine
β monitors β Sensor
Now you have a dependency chain.
If a Sensor fails:
You can trace upward:
Sensor β Machine β ProductionLine β Factory
This enables impact analysis.
7οΈβ£ Why This Is Powerful for SRE
Imagine:
A cooling system fails.
You can ask:
- Which rooms depend on this cooling unit?
- Which machines are affected?
- What production lines stop?
This is graph traversal.
Traditional monitoring systems cannot easily do this.
Azure Digital Twins can.
8οΈβ£ Advanced Relationship Properties
Relationships themselves can have properties.
Example:
{
"@type": "Relationship",
"name": "suppliesPowerTo",
"target": "dtmi:com:smartfactory:Machine;1",
"properties": [
{
"@type": "Property",
"name": "voltage",
"schema": "double"
}
]
}
This means:
Power relationship includes voltage information.
Relationships are not just links. They can carry metadata.
9οΈβ£ Modeling Best Practices
πΉ Use Meaningful Relationship Names
Good:
- contains
- monitors
- controls
- suppliesPowerTo
- connectedTo
Bad:
- link1
- relA
Relationships describe semantics.
πΉ Keep Graph Clean
Avoid:
Over-connecting everything.
Your graph should represent real-world dependencies.
Only model relationships that matter for:
- Queries
- Impact analysis
- Operational reasoning
πΉ Think in Layers
Layer 1 β Infrastructure
Layer 2 β Logical grouping
Layer 3 β Devices
Layer 4 β Sensors
Design top-down.
π Production Architecture Example
Hospital example:
Hospital
β contains β Floor
Floor
β contains β Room
Room
β contains β Equipment
Equipment
β poweredBy β PowerUnit
PowerUnit
β backedBy β Generator
Now imagine:
Generator fails.
Graph query shows:
All equipment β All rooms β All floors β Entire hospital impact.
That is Digital Twin power.
1οΈβ£1οΈβ£ Relationship vs Component (Important Distinction)
Relationship:
- Connects separate twin instances
- Creates graph edges
- Used for topology
Component:
- Embeds a model inside another
- Used for composition
We will deeply cover Components in Module 5.
1οΈβ£2οΈβ£ Query Thinking
When designing relationships, ask:
βWhat questions will I want to ask?β
Examples:
- Show all machines connected to Line A
- Show all rooms powered by Unit 3
- Show all devices in Building X
- Show impact of cooling failure
Design relationships to answer business questions.
1οΈβ£3οΈβ£ Common Beginner Mistakes
β Modeling everything as flat structure
β Not defining relationships
β Wrong direction
β Over-modeling unnecessary connections
β No naming convention
Remember:
Digital Twins without relationships is just structured JSON.
π§ Key Takeaways
- Relationships create graph structure
- Graph enables impact analysis
- Relationships are directional
- Relationships can have properties
- Design based on query needs
This is where DTDL becomes architectural.
π§ͺ Practice Exercise
Design this mentally:
Data Center
- DataCenter
- Rack
- Server
- CoolingUnit
- PowerSupply
Think:
Which relationships should exist?
Example:
Rack β contains β Server
Server β poweredBy β PowerSupply
Server β cooledBy β CoolingUnit
Now imagine PowerSupply failure.
Trace impact.
That is graph modeling.
π Whatβs Next?
In Module 5, we move to advanced modeling:
- Inheritance (extends)
- Components
- Reusability
- Modular design
- Enterprise modeling patterns
This is where you move from modeler to architect.