Azure Cosmos DB Throughput Management guide in Python SDK: Unexpected Throttling
I just started working with I've been working on this all day and I'm getting frustrated with I'm working on a service using Azure Cosmos DB with the Python SDK (version 4.2.0) and I'm running into throttling issues that I need to seem to resolve. My application is designed to scale horizontally, and I'm using a collection with a provisioned throughput of 1000 RU/s. However, during peak load times, I receive a lot of `HTTP 429` errors indicating that I'm being throttled, even though I believe my usage should be within the allocated throughput. I've implemented retry logic around my database calls using `AsyncRetry` and exponential backoff, but I'm still seeing a high frequency of throttling, especially during bulk insert operations. Here's a simplified version of my code that performs multiple insert operations: ```python from azure.cosmos import CosmosClient, exceptions import asyncio from tenacity import retry, wait_exponential client = CosmosClient('your-endpoint', 'your-key') container = client.get_database_client('your-database').get_container_client('your-container') @retry(wait=wait_exponential(multiplier=1, min=4, max=10), stop=stop_after_attempt(5)) async def insert_item(item): try: await container.create_item(item) except exceptions.CosmosHttpResponseError as e: if e.status_code == 429: print('Throttled, retrying...') raise # Will trigger the retry logic else: raise # Reraise for other errors async def main(): items = [{'id': str(i), 'data': 'Sample data'} for i in range(100)] tasks = [insert_item(item) for item in items] await asyncio.gather(*tasks) asyncio.run(main()) ``` I've also been monitoring the metrics in the Azure portal and noticed that the RU consumption spikes significantly during those peak times, but I need to pinpoint the exact operations causing the spike. I tried increasing the RU/s to 2000, but the scenario continues, which seems counterintuitive. Is there a recommended way to handle throughput more effectively or any insights on why my application might be hitting these limits? What strategies can I implement to better manage throughput in Azure Cosmos DB with the Python SDK? I'm on Ubuntu 20.04 using the latest version of Python. What are your experiences with this? I'm using Python 3.10 in this project. I'm working on a application that needs to handle this.