Courseiva

AZ-204 Develop for Azure storage Practice Question

You are developing a .NET application that stores documents in Azure Cosmos DB for NoSQL. The application requires optimistic concurrency control to prevent lost updates when multiple users edit the same document. You need to implement the mechanism using the latest SDK. What should you do?

⚠ Common exam trap

Many exam-takers confuse consistency levels with concurrency control; strong consistency ensures up-to-date reads but does not prevent lost updates.

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

✓

Enable the ETag property on the document and include it in the request options for replace operations.

Optimistic concurrency in Cosmos DB is implemented by using the ETag of a document. When you retrieve a document, you get its ETag. When you replace it, you include the ETag in the request options. If the ETag does not match the current version, the operation fails, allowing you to handle the conflict. This is the standard pattern supported by the SDK. Other options like stored procedures, consistency levels, or unique indexes do not provide the same level of concurrency control.

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 stored procedure that checks the document version before updating.

    Why it's wrong here

    Stored procedures in Cosmos DB execute within a transaction scope on a single partition, but they do not inherently provide optimistic concurrency control across multiple requests. You could implement a version check inside a stored procedure, but that would require custom logic and does not leverage the built-in ETag mechanism. Stored procedures are not the recommended way to handle concurrency because they add complexity and can become bottlenecks. The ETag-based approach is simpler and natively supported by the SDK, making it the better choice for preventing lost updates.

  • ✓

    Enable the ETag property on the document and include it in the request options for replace operations.

    Why this is correct

    Cosmos DB provides optimistic concurrency control through the ETag property of a document. The ETag is a system-generated value that changes on every update. By including the ETag in the ItemRequestOptions for a replace operation, the SDK sends it as an If-Match header. If the document has been modified since the ETag was retrieved, the operation fails with a PreconditionFailed (412) error. This allows the application to handle conflicts gracefully, such as by retrying or notifying the user. This is the standard and recommended approach for optimistic concurrency in Cosmos DB.

  • ✗

    Use a unique index on the document ID to prevent duplicate writes.

    Why it's wrong here

    Unique indexes enforce uniqueness on specified properties, but they do not help with optimistic concurrency control for updates. If two users try to update the same document, both updates would have the same document ID, and the index would not prevent the second write from overwriting the first. Unique indexes are useful for preventing duplicate documents, but they do not detect concurrent modifications. The ETag-based approach is specifically designed to handle this scenario by ensuring that the write only succeeds if the document has not changed since it was read.

  • ✗

    Set the consistency level to Strong for the Cosmos DB account.

    Why it's wrong here

    Consistency levels in Cosmos DB control the trade-off between consistency and latency, but they do not provide optimistic concurrency control. Strong consistency ensures that reads always return the latest committed write, but it does not prevent two users from overwriting each other's changes if they both read the same document and then write. Optimistic concurrency requires a mechanism to detect conflicts at write time, such as ETags. Changing the consistency level would not solve the lost update problem and could increase latency, so it is not the correct solution.

About these practice questions

This AZ-204 question is part of Courseiva's 883-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written and reviewed by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

Last reviewed September 2026 · checked against the official Microsoft exam blueprint

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.