Introduction
Azure Cosmos DB uses Request Units (RU/s) to manage throughput. When your workload exceeds provisioned RU/s, Cosmos DB returns 429 (Too Many Requests) errors, rejecting operations until capacity becomes available.
Symptoms
429 Throttling error:
{
"code": 429,
"message": "The request rate is too large. Please retry after 1000 milliseconds.",
"activityId": "abc123-def456"
}SDK retry exhaustion:
// In application logs:
Microsoft.Azure.Documents.DocumentClientException: Message: {"Errors":["Request rate is large"]}
ResourceType: DocumentCollection, Method: GETMonitoring showing throttling:
```bash $ az monitor metrics list \ --resource /subscriptions/SUB/resourceGroups/my-rg/providers/Microsoft.DocumentDB/databaseAccounts/my-cosmos \ --metric "TotalRequestUnits" "ThrottledRequests"
# High throttled request count ```
Common Causes
- 1.Provisioned RU/s too low - Workload exceeds capacity
- 2.Hot partition - All traffic to single partition
- 3.Inefficient queries - Queries consuming too many RUs
- 4.Burst traffic - Sudden spike exceeding throughput
- 5.Autoscale not configured - Manual provisioning can't scale fast
- 6.Large documents - Big documents consume more RUs
- 7.Missing retry logic - Application doesn't handle 429
Step-by-Step Fix
- 1.Check logs for specific error messages
- 2.Verify configuration settings
- 3.Test network connectivity
- 4.Review recent changes
- 5.Apply corrective action
- 6.Verify the fix
Step 1: Check Current RU/s Provisioning
# Get throughput settings
az cosmosdb sql container show \
--account-name my-cosmos \
--resource-group my-rg \
--database-name my-db \
--name my-container \
--query '{Throughput:resource.throughput,AutoscaleSettings:resource.autoscaleSettings}'Step 2: Monitor RU Consumption
```bash # Check RU consumption metrics az monitor metrics list \ --resource /subscriptions/SUB/resourceGroups/my-rg/providers/Microsoft.DocumentDB/databaseAccounts/my-cosmos \ --metric "TotalRequestUnits" \ --interval PT1H \ --query 'value[0].timeseries[0].data'
# Get per-container RU consumption az monitor metrics list \ --resource /subscriptions/SUB/resourceGroups/my-rg/providers/Microsoft.DocumentDB/databaseAccounts/my-cosmos \ --metric "TotalRequestUnits" \ --aggregation total \ --interval PT1H ```
Step 3: Increase Provisioned RU/s
```bash # Increase manual throughput az cosmosdb sql container throughput update \ --account-name my-cosmos \ --resource-group my-rg \ --database-name my-db \ --name my-container \ --throughput 2000
# Switch to autoscale az cosmosdb sql container throughput update \ --account-name my-cosmos \ --resource-group my-rg \ --database-name my-db \ --name my-container \ --max-throughput 4000
# Autoscale automatically scales from 400-4000 RU/s ```
Step 4: Analyze Query RU Cost
```sql -- Run query with RU cost SELECT c.id, c.name FROM c
-- Check request charge in response headers -- x-ms-request-charge: 5.0 RUs
-- Optimize expensive queries: -- Add indexes on filter properties -- Use partition key in WHERE clause -- Limit returned properties ```
Step 5: Add Indexing Policy
{
"indexingPolicy": {
"automatic": true,
"indexingMode": "consistent",
"includedPaths": [
{
"path": "/name/?"
},
{
"path": "/status/?"
}
],
"excludedPaths": [
{
"path": "/largeJsonField/*"
}
]
}
}Apply via CLI:
az cosmosdb sql container update \
--account-name my-cosmos \
--resource-group my-rg \
--database-name my-db \
--name my-container \
--idx @indexing-policy.jsonStep 6: Implement Retry Logic
```csharp // C# SDK with retry logic var cosmosClientOptions = new CosmosClientOptions { MaxRetryAttemptsOnRateLimitedRequests = 9, MaxRetryWaitTimeOnRateLimitedRequests = TimeSpan.FromSeconds(30) };
var client = new CosmosClient(connectionString, cosmosClientOptions);
// SDK automatically retries on 429 with exponential backoff ```
```python # Python SDK with retry logic from azure.cosmos import CosmosClient from azure.cosmos.exceptions import CosmosHttpResponseError
client = CosmosClient(url, credential=key) database = client.get_database_client('my-db') container = database.get_container_client('my-container')
max_retries = 5 retry_delay = 1
for attempt in range(max_retries): try: result = container.read_item(item_id, partition_key) break except CosmosHttpResponseError as e: if e.status_code == 429: time.sleep(e.retry_after_ms / 1000) else: raise ```
Step 7: Check for Hot Partitions
```bash # Check partition key distribution az cosmosdb sql container show \ --account-name my-cosmos \ --resource-group my-rg \ --database-name my-db \ --name my-container \ --query 'resource.partitionKey'
# If all requests go to one partition, redesign partition key # Good partition key: High cardinality, even distribution # Bad partition key: Low cardinality (e.g., status field) ```
Step 8: Use Bulk Execution
```csharp // For high-throughput writes, use bulk mode var bulkOptions = new CosmosClientOptions { AllowBulkExecution = true };
var client = new CosmosClient(connectionString, bulkOptions);
// Concurrent tasks var tasks = items.Select(item => container.CreateItemAsync(item, new PartitionKey(item.Id)));
await Task.WhenAll(tasks); ```
Step 9: Optimize Document Size
```bash # Larger documents consume more RUs # Rule of thumb: 1 KB ≈ 1 RU for read, 5-10 RUs for write
# Reduce document size: # - Remove unused fields # - Store large blobs in Blob Storage, keep reference in Cosmos # - Use short property names
# Check document size az cosmosdb sql container show \ --account-name my-cosmos \ --resource-group my-rg \ --database-name my-db \ --name my-container \ --query 'resource.documentSizeDistribution' ```
Step 10: Monitor Throttling Metrics
```bash # Set up alert for throttling az monitor metrics alert create \ --name cosmos-throttling-alert \ --resource-group my-rg \ --scopes /subscriptions/SUB/resourceGroups/my-rg/providers/Microsoft.DocumentDB/databaseAccounts/my-cosmos \ --condition "avg TotalRequestUnits > 80" \ --window-size 5m \ --evaluation-frequency 1m
# Check current throttling rate az monitor metrics list \ --resource /subscriptions/SUB/resourceGroups/my-rg/providers/Microsoft.DocumentDB/databaseAccounts/my-cosmos \ --metric "ThrottledRequests" ```
Cosmos DB RU Estimates
| Operation | Approximate RU Cost |
|---|---|
| Read 1 KB item | 1 RU |
| Write 1 KB item | 5 RUs |
| Query (indexed) | 1-10 RUs |
| Query (scan) | 10-100+ RUs |
| Stored procedure | Variable |
Verification
```bash # After increasing RU/s, monitor throttling az monitor metrics list \ --resource /subscriptions/SUB/resourceGroups/my-rg/providers/Microsoft.DocumentDB/databaseAccounts/my-cosmos \ --metric "ThrottledRequests" \ --interval PT1H
# Should show zero or minimal throttled requests
# Test application load # Should handle requests without 429 errors ```
Related Issues
- [Fix Azure Cosmos DB Partition Hotspot](/articles/fix-azure-cosmos-db-partition-hotspot)
- [Fix Azure Cosmos DB SQL Query Slow](/articles/fix-azure-cosmos-db-sql-query-slow)
- [Fix Azure Cosmos DB Change Feed Lag](/articles/fix-azure-cosmos-db-change-feed-lag)
Related Articles
- [Technical troubleshooting: Fix Azure Aks Pod Crashloopbackoff Issue in Azure](azure-aks-pod-crashloopbackoff)
- [Technical troubleshooting: Fix Azure Api Management Policy Expression Runtime](azure-api-management-policy-expression-runtime-error)
- [Technical troubleshooting: Fix Azure App Configuration Feature Flag Not Refre](azure-app-configuration-feature-flag-not-refreshing)
- [Technical troubleshooting: Fix Azure App Service 503 Always On Disabled Issue](azure-app-service-503-always-on-disabled)
- [Technical troubleshooting: Fix Azure Application Gateway Err SSL Unrecognized](azure-application-gateway-err-ssl-unrecognized-name-alert)
<script type="application/ld+json"> { "@context": "https://schema.org", "@type": "TechArticle", "headline": "Fix Azure Cosmos DB Throttling (429 Too Many Requests)", "description": "Troubleshoot Cosmos DB 429 throttling errors. Increase RU/s, optimize queries, and implement proper retry logic.", "url": "https://www.fixwikihub.com/fix-azure-cosmos-db-throttling", "publisher": { "@type": "Organization", "name": "FixWikiHub", "url": "https://www.fixwikihub.com" }, "author": { "@type": "Person", "name": "FixWikiHub Editorial Team" }, "datePublished": "2026-04-02T04:09:55.239Z", "dateModified": "2026-04-02T04:09:55.239Z" } </script>