AZ-204 Practice Question: Connect to and consume Azure services and third-party services
Your application uses Azure Cosmos DB for NoSQL. You need to implement server-side computed properties that depend on multiple document fields. The computation must be performed atomically. Which approach should you use?
⚠ Common exam trap
Candidates often confuse the atomic execution of a stored procedure with the eventual consistency of the change feed or the query-time computation of a UDF, failing to recognize that only stored procedures provide a transactional scope for read-modify-write operations on the same document.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Use a stored procedure to compute and update the property in a single transaction
Stored procedures in Azure Cosmos DB for NoSQL execute within a transactional scope, allowing you to atomically compute a property based on multiple document fields and update the document in a single operation. This ensures that the computation and update are performed as an all-or-nothing unit, which is required for atomicity. Pre-triggers, change feeds, and UDFs do not provide atomic read-modify-write semantics across multiple fields.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Use a pre-trigger to compute the property on write
Why it's wrong here
Pre-triggers execute custom JavaScript logic immediately before an item is created or updated in Azure Cosmos DB. While they can modify the item being written, they are not inherently part of the same ACID transaction as the actual write operation itself. If the subsequent write operation fails after the trigger has executed, the changes made by the trigger might not be rolled back, leading to potential inconsistencies and a lack of atomicity for the computed property.
- ✗
Use the change feed to compute the property asynchronously
Why it's wrong here
The change feed provides a persistent, ordered log of all changes to a Cosmos DB container, enabling asynchronous processing of data modifications. However, computing a property and then updating the document based on a change feed event involves a separate, subsequent write operation. This makes the entire process inherently asynchronous and non-atomic with the initial write that generated the change, meaning the computed property update will not occur within the same transaction as the original document modification.
- ✗
Use a user-defined function (UDF) in queries
Why it's wrong here
User-Defined Functions (UDFs) in Azure Cosmos DB for NoSQL are JavaScript functions designed to extend the query language, allowing for custom logic to be applied during read operations. UDFs are strictly read-only and cannot perform any write operations, including creating, updating, or deleting documents. Therefore, they cannot be used to compute a property and then atomically update that property within a document, as their scope is limited to data transformation and filtering within queries.
- ✓
Use a stored procedure to compute and update the property in a single transaction
Why this is correct
Stored procedures in Azure Cosmos DB for NoSQL are JavaScript functions executed directly on the database engine within a single transaction. They provide full ACID (Atomicity, Consistency, Isolation, Durability) guarantees for all operations performed within a single logical partition. This ensures that if a stored procedure computes a property and then updates the document, either all operations commit successfully as a single unit, or none do, guaranteeing the atomic persistence of the computed property with the document's state.
Go deeper
Related to this question
About these practice questions
Courseiva writes every AZ-204 question from scratch — 881 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This AZ-204 practice question is part of Courseiva's free Microsoft certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the AZ-204 exam.