NotFound
NotFound

Reputation: 6172

Does CosmosDB with sessions consistency garantuee ordering

From the Microsoft documentation I don't fully understand whether or not CosmosDB using session consistency garantuees no out of order writes. The following quote makes it seem like it has the same garantuees as cosistent prefix:

The reads are guaranteed to honor the consistent-prefix (assuming a single “writer” session), ...

Although from the baseball example further down the page it seems like a reader could get a completely random order back, similar to eventual consistency. From other sources online I also can't find a definitive anwser, apart from the images shown on the Azure Portal that seem to implicitly suggest the same order as the writer.

Upvotes: 1

Views: 948

Answers (2)

Chris Anderson
Chris Anderson

Reputation: 8515

(I'm from the Cosmos DB team)

A given client using session consistency will see its own writes in order, but see other clients' writes with eventual consistency (assuming using a different session token).

We're gonna update the docs to make that more clear. New text will read something like this:

Session: Within a single client session reads are guaranteed to honor the consistent-prefix (assuming a single “writer” session), monotonic reads, monotonic writes, read-your-writes, and write-follows-reads guarantees. Clients outside of the session performing writes will see eventual consistency.

Upvotes: 3

Jay Gong
Jay Gong

Reputation: 23782

Per my research, i think session consistency level can't guarantee the clients always read the value in the order.

My evidence is from this link:

  • When the consistency level is set to bounded staleness, Cosmos DB guarantees that the clients always read the value of a previous write, with a lag bounded by the staleness window.
  • When the consistency level is set to strong, the staleness window is equivalent to zero, and the clients are guaranteed to read the latest committed value of the write operation.
  • For the remaining three consistency levels, the staleness window is largely dependent on your workload. For example, if there are no write operations on the database, a read operation with eventual, session, or consistent prefix consistency levels is likely to yield the same results as a read operation with strong consistency level.

As above said,the staleness window is dependent on your actual workload if you choose Session Consistency Level. So,if you do concern about the read order, i suggest you using bounded staleness or even Strong Consistency Level.

Upvotes: 1

Related Questions