Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Document DB - ETag Optimistic Concurrency with Session Consistency

If I have a DocumentDB database with Session consistency, what guarantees are there for concurrent writes of the same document using etags? For example, with A and B operating in different sessions:

  • Read:A - etag:1
  • Read:B - etag:1
  • Write:A - etag:1 (match, etag = 2)
  • Write:B - etag:1 ?

The assumption is that Write:B fails since etag is 2, but I haven't found any explicit documentation on what guarantee there is for where DocumentDB reads the etag value from on the server, as in, could it read from a secondary replica where the etag is still 1, and let Write:B still go through?

This question Session Guarantee on DocumentDB discusses the issue in the comments, but does not seem to come to a conclusion.


Web Documentation

From the FAQ https://learn.microsoft.com/en-us/azure/documentdb/documentdb-faq enter image description here

From the example source (implies, but does not state, that this holds true at all consistency levels?) https://github.com/Azure/azure-documentdb-dotnet/blob/master/samples/code-samples/DocumentManagement/Program.cs: enter image description here

like image 281
David Faivre Avatar asked Nov 17 '16 18:11

David Faivre


Video Answer


1 Answers

DocumentDB team member here. Confirming Larry's reply that conditional writes with ETags will be enforced for all consistency levels. The write request must include the ETag (If-Match header in REST, RequestOptions.AccessCondition in .NET).

EDIT on 7/29/2019 with accounts configured for multi-region writes, there are no guarantees for ETag with multi-region writers, and you have to resolve concurrent writes via conflict resolution procedures. ETag validation still applies for single-region write accounts, as before.

like image 73
Aravind Krishna R. Avatar answered Nov 01 '22 07:11

Aravind Krishna R.