Cosmos DB Throttled Requests

George Wolfi 286 Reputation points

Hi there,

I have a few thousands request every 30 secs. I have autopilot mode on with 4000 RU/s.
But I can see I'm getting lot of throttling requests. I'm currently storing all the insert functions into a task and
then using Task.WhenAll.

// Cosmos Tasks Execution  
await Task.WhenAll(concurrentTasks);  


The bulk insert would have been a batter choice for me, but I couldn't find any.
Is there any way where I can wait a couple of seconds so that I don't get 429 errors.

I have added a custom throttling function in the builder but seems to be not working.

configurationBuilder.AddCustomHandlers(new ThrottlingHandler());  

Help would be appreciated. Thanks

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,064 questions
{count} votes

Accepted answer
  1. Mark Brown - MSFT 2,756 Reputation points Microsoft Employee

    If the instance of your Cosmos client only does these bulk inserts then create your client using the AllowBulkExecution setting below.

    new CosmosClient(endpoint, authKey, new CosmosClientOptions() { AllowBulkExecution = true});

    Would be helpful to see the code for your custom handler to better understand why that is not working. But generally speaking you should trap for 429 responses and implement a backoff/retry policy with Polly with a one second interval. However, with bulk mode enabled you should see far fewer of these anyway.


0 additional answers

Sort by: Most helpful