Soru

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

A smart home energy platform collects high-frequency telemetry data from millions of IoT smart meters. Each meter writes power consumption readings every 10 seconds. Each telemetry document contains `deviceId`, `timestamp`, `deviceType` (e.g., Thermostat, SmartPlug), and `powerUsage`.

The solution must meet the following requirements:
- Support a high volume of write ingestions without encountering hot partitions.
- Ensure that all telemetry readings and device state updates for a specific meter on a given day can be executed atomically as a single transaction.
- Prevent individual logical partitions from exceeding the 20 GB size limit as data accumulates over years of operation.
- Optimize queries that retrieve daily consumption metrics for a specific meter.

Which two partition key strategies or configurations should you implement to satisfy these requirements? (Select two.)

  1. Create a synthetic partition key by concatenating the device ID and the current date (for example, deviceId_YYYY-MM-DD) for telemetry ingestion.Cevap
  2. Group the telemetry writes and state updates for a meter on a specific day into a single transactional batch using the synthetic partition key.Cevap
  3. C
    Configure deviceType as the partition key to optimize reporting queries that aggregate consumption across device categories.
  4. D
    Rely on the default session consistency level of the container to guarantee read-your-writes consistency across separate user web sessions without sharing session tokens.

Cevap

The correct answer is to use a synthetic partition key combining the device ID and the current date (deviceId_YYYY-MM-DD) and execute database writes in a single transactional batch using that partition key.
A synthetic partition key combining the device ID and the date (e.g., `deviceId_YYYY-MM-DD`) satisfies the 20 GB limit by dividing the data per device into daily segments. Since all items written for a specific meter on a single day share this partition key, they can be modified atomically using a transactional batch.

Adım Adım Çözüm

1
Analyze partition limits.
Using a static device ID as a partition key can cause unbounded growth that eventually exceeds the 20 GB logical partition limit.
Cosmos DB limits logical partitions to 20 GB, so keys with infinite growth per value must be scoped down.
2
Determine transaction scopes.
Transactional batches in Azure Cosmos DB can only target a single logical partition key.
To perform transactions for a device per day, the key must contain both the device ID and the date.
3
Avoid hot partitions.
Low-cardinality attributes like deviceType will concentrate writes onto a few physical partitions, causing rate-limiting.
A synthetic key solves this by distributing writes across many distinct values.

Anahtar Kavram

Designing synthetic partition keys to balance write throughput, logical partition size limits, and transactional boundaries.
Bu soruyu puanla