You are designing an Azure Cosmos DB container to store customer order records for an online retail application. Each order document contains `OrderId`, `CustomerId`, `OrderDate`, and `ShippingStatus`. The application frequently queries orders for a given customer and requires transactional updates when modifying multiple orders for the same customer.
Which two requirements are satisfied by selecting `CustomerId` as the partition key for this container?
- It enables multi-document transactions using transactional batches or stored procedures for orders belonging to the same customer.Answer
- It ensures that queries filtering by the customer identifier to retrieve order history are served as single-partition queries.Answer
- CIt guarantees that a single logical partition will never exceed the 20 GB storage limit, regardless of the volume of orders per customer.
- DIt automatically implements Session consistency across multiple independent client sessions without needing to pass a session token.
Answer
Selecting the customer identifier as the partition key satisfies the requirements by enabling multi-document transactions for orders within the same customer scope and ensuring that customer history queries are single-partition queries.
Selecting the customer identifier as the partition key ensures all orders for a single customer reside in the same logical partition. This enables transaction execution (stored procedures, transactional batch) across those documents and allows the database to route customer-specific queries to a single partition, minimizing Request Unit (RU) consumption.
Step-by-Step Solution
Key Concept
Selecting an appropriate partition key in Azure Cosmos DB is essential for maintaining transactional boundaries and optimizing query performance.
Estimated Time:1m 0s