Question

Difficulty: MediumConfigure Partition Keys and Partitioning Strategies in Azure Cosmos DB

A logistics company is designing an Azure Cosmos DB container to store delivery tracking records. The system receives a high volume of writes representing tracking status updates. Each tracking record contains a `shipmentId`, a `destinationCountry`, and a `statusDate` (formatted as YYYY-MM-DD). The system must support transactional batch writes (using `TransactionalBatch`) for all status updates of a single shipment on a specific date. The destination country has low cardinality, with 10 countries representing 95% of all shipments. You must prevent hot partitions during peak shipping seasons while satisfying the transactional boundary. Which two actions should you perform to configure the partitioning strategy?

  1. Create a synthetic partition key by concatenating shipmentId and statusDate in each item.Answer
  2. Set the container's partition key path to the custom synthetic property.Answer
  3. C
    Configure destinationCountry as the partition key to optimize queries that filter by country.
  4. D
    Configure Session consistency to guarantee transactional ACID compliance for batch updates across different shipment partitions.

Answer

Create a synthetic partition key by concatenating shipmentId and statusDate in each item, and configure the container's partition key path to point to the custom synthetic property.
To support transactional batches for updates of a single shipment on a specific date, all involved items must share the same partition key. Concatenating shipmentId and statusDate to create a synthetic partition key satisfies this constraint. Selecting this synthetic property as the container's partition key distributes writes evenly due to its high cardinality, preventing hot partition issues that would arise from using destinationCountry.

Step-by-Step Solution

1
Analyze partition key requirements for transactional batches.
Identified that TransactionalBatch operations in Azure Cosmos DB require all operations to target the same logical partition key.
Azure Cosmos DB only supports multi-document transactions (TransactionalBatch) within a single logical partition.
2
Evaluate candidate fields for partition keys based on cardinality and write patterns.
Determined that using destinationCountry results in hot partitions due to low cardinality (10 countries representing 95% of traffic). Determined that a synthetic key combining shipmentId and statusDate provides high cardinality and satisfies the transactional boundary.
High cardinality prevents hot partitions by distributing writes across many logical and physical partitions, while combining shipmentId and statusDate keeps the transactional operations scoped to a single logical partition.
3
Define the container's partition key configuration.
Concatenate the fields in the item and configure the container's partition key path to point to this new synthetic property.
Azure Cosmos DB does not automatically generate synthetic keys; they must be created in the application code and the partition key path configured on the container to match.

Key Concept

Azure Cosmos DB partitioning strategy, including synthetic partition keys and transactional boundaries.
Estimated Time:2m 0s
Rate this question