Overview of Request Concurrency

Learn how Cosmos DB handles conflicts by default and what we can do about it.

Request concurrency issues

In Cosmos DB, documents have versions identified with the _etag property. When different clients update the same document, there can be concurrency issues.

In this lesson, we’ll see how Cosmos DB helps us reduce issues and how we can handle them.

Single-region writes

Let’s see three examples of concurrency issues that might happen.

Imagine Alice and Bob working in the same region, trying to update the same document.

First scenario

Alice and Bob update the same document at the same time. Which one will succeed?

Second scenario

In chronological order:

  • Alice reads version 1.

  • Bob reads version 1.

  • Alice successfully updates the documents, creating version 2.

  • Bob tries to make an update.

Will Bob override and lose the changes made by Alice?

Third scenario

Similar to the second scenario:

  • Alice reads version 1.

  • Bob reads version 1.

  • Alice deletes the document.

  • Bob tries to make an update.

Will Bob recreate the document? Will it be version 1 again ...