Soru

Zorluk: OrtaConfigure Partition Keys and Partitioning Strategies in Azure Cosmos DB

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?

  1. Create a synthetic partition key by concatenating the device ID and the current year and month (e.g., DeviceId_YearMonth).Cevap
  2. B
    Use the device ID (DeviceId) as the partition key.
  3. C
    Use the current year and month (YearMonth) as the partition key.
  4. D
    Create a synthetic partition key by appending a random integer suffix between 1 and 10 to the device ID (e.g., DeviceId_RandomSuffix).

Cevap

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.

Adım Adım Çözüm

1
Analyze storage and partition constraints
Since some industrial devices will generate telemetry exceeding 20 GB, a single device ID cannot be used as the partition key directly.
Azure Cosmos DB logical partitions have a maximum storage limit of 20 GB.
2
Evaluate transactional boundaries
Items modified within a transactional batch must share the same partition key.
Transactional batches cannot span multiple logical partitions.
3
Select a partition key that satisfies all constraints
A synthetic key combining DeviceId and YearMonth satisfies the 20 GB limit, keeps transactional updates in the same partition (occurring at the same time), and ensures the primary query is single-partition.
It groups data logically by device and month, distributing writes across partitions while keeping related monthly records together.

Anahtar Kavram

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.
Bu soruyu puanla