Azure Digital Twin Application Approach
Recently i got a chance to architect an Azure Digital Project, but its a bit confusing once to decide how the event updating should follow in azure digital twin platform.
Please find the reference diagram from Microsoft below
Here we can see multiple inputs specified, But in action, we need to write some logic in azure function or write logic apps to update the ADT as there is no direct integration available in ADT to ingest from any of these input sources.
Now Lets consider that we have a use case to visualize the digital twin of a smart building. we have build which contains floors and that contains rooms as shown below. Consider that we are receiving the telemetry from IoT hub or event hub.
As shown on diagram we need to update the digital twin from the azure function based on the telemetry received. Now we can follow below methods to update the digital twins from the function.
Direct Update — Node and Relationship
in this method, The azure function should update the nodes and update its relationships by querying the ADT instances from ADT. Now lets consider some possibilities
Received Building Telemetry and No need to update Children
Lets Consider we received an event or telemetry from the building, we need to update its twin, Then we can straight away go and update the twin instances from the function.
Application sequence below
- Telemetry Received on Event triggered function
- Get building twin from ADT using api/sdk — get twin by id
- update twin
Received Building Telemetry and Need to update Children
Lets consider another situation that we need to write back the building event or its property to its children.
Application sequence below
- Telemetry Received on Event triggered function
- Get building twin from ADT using api/sdk — get twin by id
- update building twin
- get floor twin from ADT using get twin by id(need to call n number of times) or using query api
- update floor twin
Received Building Telemetry , Need to update Children and need to update relationships
Now the thigs will get more complicated if we cant to update also the relationships along with its children
Now you can think that this will get more and more complicated or time consuming if we want to update the same to its lower branches also.
Application sequence below
- Telemetry Received on Event triggered function
- Get building twin from ADT using api/sdk — get twin by id
- update building twin
- get floor twin from ADT using get twin by id(need to call N number of times) or using query api
- update floor twin N times
- get relationships using id(need to call N number of times)
- update relationships N times
These method has the drawback that your api calls to twin services will increase based on the volume.
Event Based Update
In this method this will get much more disconnected. The updating will work as chained action, This can be choose when we have no impact between node updates.
In this method we should introduce one more function to process the twin updates.
Here the green colored node update will be done by the Event triggered function. Then the Twin trigger will get invoked and update its child accordingly. This can work as repeated changed action. We can also update the relationship with the sane twin triggered function or create another separate twin triggered function for the same.
Application sequence below
- Telemetry Received on Event triggered function
- Get building twin from ADT using api/sdk — get twin by id
- update building twin
- Twin update received in twin triggered function
- get floor twin from ADT using get twin by id
- update floor twin
Combined Approach
An alternate to both these will be the combined solution which can split the processes between by updating the nodes by the Event triggered function and updating the relationships by the twin triggered function.
Application sequence below
- Telemetry Received on Event triggered function
- Get building twin from ADT using api/sdk — get twin by id
- update building twin
- get floor twin from ADT using get twin by id(need to call n number of times) or using query api
- update floor twin
- Twin update received in twin triggered function
- get relationships using id
- update relationship
If we are using much complex hagiarchy or tree structure, then the Event based updating will be the right choice for you, But in some cases we may need to collect the sibling node information, in those situation the combined approach can help you.
Direct update will only be possible if you are not considering the child or relationship updates from the function. Consider the size and complexity of the Twin Instances.