You are designing an Azure Cosmos DB Core (SQL) API container for a smart home energy monitoring system that tracks electricity usage for 500,000 devices. Each device uploads energy telemetry logs every 10 seconds. The container must support transactional batches to update a device's telemetry log and its current state cache document atomically. Additionally, some high-frequency industrial devices will accumulate more than 20 GB of telemetry data over time. The most frequent read queries will retrieve all telemetry logs for a specific device during a given calendar month.
Which partition key strategy should you implement?
- Create a synthetic partition key by concatenating the device ID and the current year and month (e.g., DeviceId_YearMonth).Answer
- BUse the device ID (DeviceId) as the partition key.
- CUse the current year and month (YearMonth) as the partition key.
- DCreate a synthetic partition key by appending a random integer suffix between 1 and 10 to the device ID (e.g., DeviceId_RandomSuffix).
Answer
Create a synthetic partition key by concatenating the device ID and the current year and month (e.g., DeviceId_YearMonth).
The correct strategy is to create a synthetic partition key by combining the device ID and the year-month. This satisfies the 20 GB size constraint by splitting the telemetry of any single device into monthly buckets. Because transactional batch operations must target the same partition key, storing the telemetry and state cache document under the same device ID and month allows transactional updates to succeed. Lastly, queries looking for telemetry from a specific device in a specific month will target a single partition, maximizing query efficiency.
Step-by-Step Solution
Key Concept
Selecting and configuring synthetic partition keys in Azure Cosmos DB to handle high-write ingestion, satisfy transactional batch requirements, and avoid exceeding logical partition size limits.