DP-420 · Question #52
You are working on an app that will save the device metrics produced every minute by various IoT devices. You decide to collect the data for two entities; the devices and the device metrics produced…
The correct answer is C. Create a document with the deviceid property and other device data, and add a property called. The correct answer is C: Create a document with the deviceid property and other device data, and add a property called 'type' (or similar discriminator) to distinguish between entity types within the same container. This is a standard Cosmos DB design pattern called…
Question
You are working on an app that will save the device metrics produced every minute by various IoT devices. You decide to collect the data for two entities; the devices and the device metrics produced by each device. You were about to create two containers for these identified entities but suddenly your data engineer suggests placing both entities in a single container, not in two different containers. What would you do?
Options
- ACreate a document with the deviceid property and other device data, and add a property called
- BCreate a document with the deviceid property and other device data. After that embed each
- CCreate a document with the deviceid property and other device data, and add a property called
- DNone of these.
How the community answered
(34 responses)- A3% (1)
- B9% (3)
- C76% (26)
- D12% (4)
Explanation
The correct answer is C: Create a document with the deviceid property and other device data, and add a property called 'type' (or similar discriminator) to distinguish between entity types within the same container. This is a standard Cosmos DB design pattern called 'multi-entity containers' or 'single-table design.' Since Cosmos DB is schema-agnostic, different entity types can coexist in the same container. A discriminator property (e.g., 'type': 'device' or 'type': 'metric') allows queries to filter by entity type. This approach reduces the number of containers, simplifies partition key design, and can lower provisioned throughput costs. Option B (embedding all metrics into the device document) would cause unbounded document growth as metrics accumulate every minute per device - this is an anti-pattern for high-frequency time-series data. Option A may suggest a similar approach but without the type discriminator, making querying harder.
Topics
Community Discussion
No community discussion yet for this question.