Skip to content

Commit f14ef35

Browse files
andrewmathew1Andrew Mathew
andauthored
Added preferred locations to readme (Azure#39812)
* added preferred locations to readme * edited readme --------- Co-authored-by: Andrew Mathew <[email protected]>
1 parent a6f978c commit f14ef35

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

sdk/cosmos/azure-cosmos/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,25 @@ Always ensure that the managed identity you use for AAD authentication has `read
110110
More information on how to set up AAD authentication: [Set up RBAC for AAD authentication](https://learn.microsoft.com/azure/cosmos-db/how-to-setup-rbac) <br>
111111
More information on allowed operations for AAD authenticated clients: [RBAC Permission Model](https://aka.ms/cosmos-native-rbac)
112112

113+
### Preferred Locations
114+
To enable multi-region support in CosmosClient, set the `preferred_locations` parameter.
115+
By default, all writes and reads go to the dedicated write region unless specified otherwise.
116+
The `preferred_locations` parameter accepts a list of regions for read requests.
117+
Requests are sent to the first region in the list, and if it fails, they move to the next region.
118+
119+
For example, to set West US as the read region, and Central US as the backup read region, the code would look like this:
120+
```python
121+
from azure.cosmos import CosmosClient
122+
123+
import os
124+
URL = os.environ['ACCOUNT_URI']
125+
KEY = os.environ['ACCOUNT_KEY']
126+
client = CosmosClient(URL, credential=KEY, preferred_locations=["West US", "Central US"])
127+
```
128+
Also note that if all regions listed in preferred locations fail, read requests are sent to the main write region.
129+
For example if the write region is set to East US, then `preferred_locations=["West US", "Central US"]`
130+
is equivalent to `preferred_locations=["West US", "Central US", "East US"]` since the client will send all requests to the write region if the preferred locations fail.
131+
113132
## Key concepts
114133

115134
Once you've initialized a [CosmosClient][ref_cosmosclient], you can interact with the primary resource types in Cosmos DB:

0 commit comments

Comments
 (0)