An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
Hello @Dhruvesh Sheladiya ,
Welcome to Microsoft Q&A .Thank you for reaching out to us.
A device twin in Azure IoT Hub is a cloud‑maintained JSON document automatically created for every registered device. It acts as a persistent digital representation of a physical device and enables reliable, state‑based synchronization between cloud applications and devices, even when connectivity is intermittent or unavailable.
A key principle is that a device twin always stores only the latest known state, not a history of changes. This makes it a state synchronization mechanism rather than a messaging or event system.
Please refer the following
Understand Azure IoT Hub device twins - Azure IoT Hub | Microsoft Learn
The device twins are structured as follows -
Each device twin consists of the following components:
- Device Identity Metadata - Read‑only fields maintained by IoT Hub, such as device ID and generation ID, representing the device identity in the registry.
- Tags - Cloud‑only metadata used for device grouping, filtering, and querying at scale. Tags are not visible to device applications and are managed exclusively by back‑end applications.
- Desired Properties (Cloud > Device Intent) - Desired properties represent the target configuration or expected state defined by cloud applications. Examples include telemetry intervals, target firmware versions, and configuration policies. Only the latest desired state is stored, and intermediate updates are not queued. Devices receive the latest desired configuration when connectivity is available.
- Reported Properties (Device > Cloud Reality) - Reported properties represent the actual device state reported by the device application. This includes applied configuration, runtime status, and health indicators such as battery level or firmware version. These properties allow cloud applications to compare expected versus actual state.
- Metadata and Versioning - Each desired and reported section includes a $version field, and the twin uses an etag to support optimistic concurrency control. Versioning ensures consistent updates when multiple services interact with the same twin.
Synchronization works as follows -
Device twin synchronization is event‑driven and eventually consistent and not real‑time.
When a device is online, desired property updates are delivered immediately through the active IoT Hub connection. The device applies the configuration and updates reported properties to confirm the applied state.
When a device is offline, IoT Hub does not queue individual desired property notifications. Instead, only the latest desired state is retained. Upon reconnection, the device retrieves the full twin document, receives the latest desired properties snapshot, applies the configuration, and updates reported properties accordingly. Intermediate updates are not replayed, ensuring the device always converges to the most recent state.
Please refer the following - Understand Azure IoT Hub device twins - Azure IoT Hub | Microsoft Learn
For designing desired vs reported properties effectively -
Desired properties should model configuration intent, remain stable, and avoid high‑frequency or runtime data. Reported properties should reflect actual device state, confirm applied configurations, and include timestamps or error details where relevant.
A simple guiding principle applies: desired properties represent what is intended, while reported properties represent what is actually achieved. This separation enables reliable configuration tracking and rollout validation.
As for Device Twins vs Direct Methods :
Device twins are designed for persistent state synchronization and configuration management, supporting offline scenarios and long‑term reconciliation of device state. In contrast, direct methods are intended for immediate, time‑sensitive commands such as rebooting a device or running diagnostics and require the device to be online at the time of invocation. Device twins do not provide real‑time responses, while direct methods do. As a result, device twins are best suited for configuration, compliance tracking, and firmware rollout scenarios, whereas direct methods are appropriate for operational commands.
For using using device twins at scale
For large device fleets, the following practices are recommended:
- Use tags to group devices by region, type, or business context
- Use queries to target subsets of devices
- Perform bulk updates using IoT Hub Jobs
- Avoid frequent or high‑volume twin updates
- Use etag and $version to ensure safe concurrent updates
Please refer the following - https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-query-language
Limits and troubleshooting considerations:
The total device twin size limit is approximately 64 KB, with 8 KB for tags, 32 KB for desired properties, and 32 KB for reported properties. Property nesting depth is limited to five levels, and update rates are subject to IoT Hub tier‑based throttling.
Please check the following troubleshooting steps if in need-
- Verifying that desired property $version increments after updates
- Confirming that device SDK callbacks receive desired property changes
- Ensuring reported properties are updated after configuration is applied
- Checking throttling or quota errors during bulk updates
- Validating reconnect behavior for offline devices
- Confirming correct etag usage when multiple services update the same twin
Please let us know if the above response was helpful
Thank you