Forum Discussion
In Comsos DB, which consistency level should I use to read data in order in which they are written?
Scenario: I want to read data in the order in which they are written/updated. I am fine with any latency. I'm not performing any write operation before/after read operation.
My understanding: Since session, consistency prefix and eventual serves data from any 1 replication within a region, they won't give me data in order. It means I have only 2 options: Strong and Bounded Staleness. Is that correct?
1 Reply
- mannu2050
Microsoft
bhaumikmehta CosmosDB have a consistency level consistent prefix which ensure read in sequence of writes, refer https://learn.microsoft.com/en-us/azure/cosmos-db/consistency-levels#consistent-prefix-consistency
However, as you mentioned this is eventual in nature when it comes to Multi-region. If your intent is to read the data as soon as it is written in other regions then strong consistency is the only option. Bounded staleness means strong consistency only for the region where you are writing for remote region it will be eventual (though you can control staleness through config).
Another cheaper option would be to use Changefeed which ensures the order of change is maintained refer https://learn.microsoft.com/en-us/azure/cosmos-db/change-feed
Hope this helps