Prevent rate-limiting errors for Azure Cosmos DB for MongoDB operations

APPLIES TO: MongoDB

Azure Cosmos DB for MongoDB operations might encounter rate-limiting, resulting in 16500 errors in mongo request metrics, if they exceed a collection's throughput limit (RUs).

Enable Server Side Retry (SSR) to automate operation retries. SSR retries requests across all collections in your account with short delays. If a 60-second timeout is reached, a client receives an ExceededTimeLimit exception (50).

Use the Azure portal

  1. Sign in to the Azure portal.

  2. Navigate to your Azure Cosmos DB for MongoDB account.

  3. Go to the Features pane underneath the Settings section.

  4. Select Server Side Retry.

  5. Click Enable to enable this feature for all collections in your account.

Screenshot of the server-side retry feature for Azure Cosmos DB for MongoDB

Use the Azure CLI

  1. Check if SSR is already enabled for your account:

    az cosmosdb show --name accountname --resource-group resourcegroupname
    
  2. Enable SSR for all collections in your database account. It may take up to 15 min for this change to take effect.

    az cosmosdb update --name accountname --resource-group resourcegroupname --capabilities EnableMongo DisableRateLimitingResponses
    
  3. The following command will Disable server-side retry for all collections in your database account by removing DisableRateLimitingResponses from the capabilities list. It may take up to 15 min for this change to take effect.

    az cosmosdb update --name accountname --resource-group resourcegroupname --capabilities EnableMongo
    

Frequently asked questions

How can I monitor the effects of a server-side retry?

You can view the rate limiting errors (16500) with mongo requests metric, that are retried server-side in the Azure Cosmos DB Metrics pane. Keep in mind that these errors don't go to the client when SSR is enabled, since they are handled and retried server-side.

You can search for log entries containing estimatedDelayFromRateLimitingInMilliseconds in your Azure Cosmos DB resource logs.

Will server-side retry affect my consistency level?

server-side retry does not affect a request's consistency. Requests are retried server-side if they are rate limited.

Does server-side retry affect any type of error that my client might receive?

No, server-side retry only affects rate limiting errors by retrying them server-side. This feature prevents you from having to handle rate-limiting errors in the client application. All other errors will go to the client.

Next steps

To learn more about troubleshooting common errors, see this article:

Trying to do capacity planning for a migration to Azure Cosmos DB? You can use information about your existing database cluster for capacity planning.