You have an Azure Cosmos DB SQL API container partitioned by /customerId. When an order is placed, your service must atomically: (1) create the order document, (2) update the customer profile’s openOrderCount, and (3) delete the customer’s cart document. All three documents share the same customerId value. You want all operations to succeed or fail together without using server-side stored procedures. What should you do?
Choose an answer
Tap an option to check your answer.
Correct answer: Use the Azure Cosmos DB SDK’s TransactionalBatch to issue create, replace, and delete operations with the same PartitionKey value equal to the customerId..
Why this is the answer
The correct answer is using TransactionalBatch. Azure Cosmos DB guarantees ACID transactions within a single logical partition. Since all three documents share the same customerId and the container is partitioned by /customerId, they reside in the same logical partition. TransactionalBatch allows you to group multiple point operations (create, replace, delete) targeting the same logical partition into a single atomic transaction, ensuring all succeed or all fail. Enabling cross-partition ACID transactions is not an option in Cosmos DB; transactions are strictly scoped to a single logical partition. The Change Feed Processor is for reacting to changes, not for ensuring atomicity of a set of operations. Performing three separate requests with ETags does not guarantee atomicity; one operation could succeed while another fails, leaving the data in an inconsistent state.
Pass your exam — without the endless answer hunt
Get every verified question and explanation for this exam in one place, and save hours of prep. 1,000+ certifications · 20+ languages · free to start.
Pass your exam faster → No card needed