
Cloud
Learning Level
from azure.cosmos import CosmosClient, PartitionKey
client = CosmosClient.from_connection_string(connection_string)
# Create geo-replicated database
database = client.create_database(
id="mydb",
offer_throughput=400,
consistency_level="Session"
)
# Add read regions
client._client_connection._endpoint_properties.update({
"multipleWriteLocationsEnabled": True,
"writeLocations": [
{"locationName": "East US", "failoverPriority": 0},
{"locationName": "West US", "failoverPriority": 1}
]
})def choose_partition_key(data_distribution):
"""
Analyze data distribution to choose optimal partition key
"""
if data_distribution['skew_ratio'] > 0.8:
return "/userId" # Hot partition risk
else:
return "/timestamp" # Better distributioncontainer = database.create_container(
id="conflicts",
partition_key=PartitionKey(path="/userId"),
conflict_resolution_policy={
"mode": "LastWriterWins",
"conflictResolutionPath": "/_ts"
}
)Learn about monitoring and observability.
Resources
Ojasa Mirai
Master AI-powered development skills through structured learning, real projects, and verified credentials. Whether you're upskilling your team or launching your career, we deliver the skills companies actually need.
Learn Deep • Build Real • Verify Skills • Launch Forward