Home > Net >  CosmosDB: Will call go to write replica if provided read replica region doesn't exist?
CosmosDB: Will call go to write replica if provided read replica region doesn't exist?

Time:08-26

I have a CosmosDB instance on Azure, with 1 write replica and multiple read replicas. Normally we call SetCurrentLocation to make calls to read replica. My understanding is that this automatically create PreferredLocations for us. But not sure how the preferredlocations work.

Now let's say the location passed to the SetCurrentLocation method is improper. That is, there's no replica in that single location we passed, but the location is a valid azure region. In that case, will the call go to the write replica, or a closer by read replica?

CodePudding user response:

SetCurrentLocation will order Azure regions based on geographical distance between the indicated region and them, and the SDK client will then take this ordered list and map it with your account available regions. So it ends up being your account available regions ordered by distance to the region you indicated on SetCurrentLocation.

For an account with a single write region, all write operations always go to that region, the Preferred Locations affect read operations. More information at: https://docs.microsoft.com/azure/cosmos-db/troubleshoot-sdk-availability

CodePudding user response:

Further adding to Matias's answer, from https://docs.microsoft.com/en-us/azure/cosmos-db/sql/troubleshoot-sdk-availability:

Primary region refers to the first region in the Azure Cosmos account region list. If the values specified as regional preference do not match with any existing Azure regions, they will be ignored. If they match an existing region but the account is not replicated to it, then the client will connect to the next preferred region that matches or to the primary region.

So if the specified location is bad, or there's no read replica there, the client will try connect to the next location, where eventually the primary region (in this case, the singular write replica) is used.

  • Related