Pavel Evdokimov
Pavel Evdokimov

Reputation: 816

Bulk delete in Azure CosmosDB leads to 429 error

I've implemented bulk deletion as recommended with newer SDK. Created a list of tasks to delete each item and then awaited them all. And my CosmosClient was configured with BulkOperations = true. As I understand, it's implied that under the hood new SDK does its magic and performs bulk operation.

Unfortunatelly, I've encountered 429 response status. Meaning my multiple requests hit request rate limit (it is low, development only tier, but nontheless). I wonder, how single bulk operation might cause 429 error. And how to implement bulk deletion in not "per item" fashion.

UPDATE: I use Azure Cosmos DB .NET SDK v3 for SQL API with bulk operations support as described in this article https://devblogs.microsoft.com/cosmosdb/introducing-bulk-support-in-the-net-sdk/

Upvotes: 0

Views: 400

Answers (1)

Mark Brown
Mark Brown

Reputation: 8763

You need to handle 429s for deletes the way you'd handle for any operation by creating an exception block, trapping for the status code, then checking the retry-after value in the header, then sleeping and retrying after that amount of time.

PS if you're trying to delete all the data in the container, it can be more efficient to delete then recreate the container.

Upvotes: 1

Related Questions