Recently while I was doing Performance Testing in one of the APIs interacting with Cosmos DB, I encountered a problem as Azure Cosmos DB API’s started returning Http Code 429. Http Status Code 429 indicates that too many request been received or request rate is very large. This error would happen when we have concurrent users trying to write or read from same cosmos db collection.
Following diagram covers the architecture of the performance test I am performing:
Based on analysis it found out to be the Throttling happening from Azure Cosmos DB, as we make requests that may use more than provisioned Request Units(RU) per second. We were using default Cosmos DB configuration for a fixed collection of 1000 RU’s per second which is sufficient enough for a 500 reads and 100 writes for a 1 kb file. You can refer more about Request Units from Azure Docs.
Solution(s):
1. Now first logical step we can do is to get rid off this error by increasing the Throughput for the collection. I am going to increase to 10000 RU/s maximum allocatable for a Storage Capacity: Fixed. This should ideally improve the Throughput for 250 or more virtual users hitting.
2. Second logical step is to improve the code: Improve the connection parameters in the Document DB SDK –> DocumentDbClient. For this I referred to the Microsoft Docs: Performance tips for Azure Cosmos DB and .NET
Providing optimum values to the following Properties in RetryOption class to be passed as parameter to Connection Policy.
In my case I provided a value of 30 to give ultimate results:
new RetryOptions() { MaxRetryAttemptsOnThrottledRequests = 30, MaxRetryWaitTimeInSeconds = 30 }
That should resolve most of the 429 issues when dealing with Cosmos DB SDK
Discover more from Cloud Distilled ~ Nithin Mohan
Subscribe to get the latest posts sent to your email.