user1142433
user1142433

Reputation: 1551

Azure DocumentDB Consistency for Distributed Web Apps

I have a pretty standard (Asp.Net Core) web app which is deployed in Azure. I'm using multiple app servers that are not using session affinity, so the same user might hit different servers during subsequent requests.

I'd like to use Azure DocumentDB to handle some data storage for me. The usage pattern is that each logged-in user will issue a command up to 10 times per minute to read and then update a data record. Each user will read and write one record. Each user has their own record.

After reading the DocumentDB documentation regarding consistency, I'm left with a few question on how they work.

My requirements are

  1. A user must always read the latest version of the record, regardless of which AppServer they connect to while they are logged in.
  2. If a user logs out and then logs back in at some point later (could be 30 seconds, could be an hour) they need to read the most recent version of the record, including any writes that might have happened.
  3. I require regional fail-over capability for the DocumentDb. That seems to rule out "Strong" consistency levels, which I would otherwise be happy to pay for.

I'm thinking I need to use "Session" consistency, but I'm not sure how to handle the SessionToken in the context of a web farm scenario.

I suppose I could store the SessionToken as a cookie, but what is the lifespan of a DocumentDB "session"? The documentation seems to be silent on this. Also, what happens if the user logs out and back in and the session is expired?

Maybe I don't have a full understanding of how writes are replicated within DocumentDB and perhaps the solution to all of this in how the read/write regions for DocumentDB are configured?

If I have one primary read/write DocumentDB in my primary data center region and a secondary "read" DocumentDB in another region, does that address my consistency and fail-over requirements?

Any clarification would be much appreciated!

Upvotes: 1

Views: 269

Answers (1)

Aravind Krishna R.
Aravind Krishna R.

Reputation: 8003

DocumentDB session tokens never expire. You can certainly follow the cookie pattern to guarantee strong consistency for a user across login/logout. If the account is setup with bounded staleness, you can also guarantee strong reads by using a second DocumentClient that only reads from the write region of the account.

Upvotes: 2

Related Questions