Module 4 β€” Relationships & Graph Modeling


🎯 Module Objective

By the end of this module, you will:

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:

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:

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:

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:

Bad:

Relationships describe semantics.


πŸ”Ή Keep Graph Clean

Avoid:

Over-connecting everything.

Your graph should represent real-world dependencies.

Only model relationships that matter for:


πŸ”Ή 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:

Component:

We will deeply cover Components in Module 5.


1️⃣2️⃣ Query Thinking

When designing relationships, ask:

β€œWhat questions will I want to ask?”

Examples:

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

This is where DTDL becomes architectural.


πŸ§ͺ Practice Exercise

Design this mentally:

Data Center

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:

This is where you move from modeler to architect.

πŸ’¬
AI Learning Assistant