|
| 1 | +--- |
| 2 | +title: Prevent rate-limiting errors for Azure Cosmos DB API for Cassandra. |
| 3 | +description: Prevent your Azure Cosmos DB API for Cassandra operations from hitting rate limiting errors with the SSR (server-side retry) feature |
| 4 | +author: dileepraotv-github |
| 5 | +ms.service: cosmos-db |
| 6 | +ms.subservice: cosmosdb-cassandra |
| 7 | +ms.topic: how-to |
| 8 | +ms.date: 10/11/2021 |
| 9 | +ms.author: turao |
| 10 | +--- |
| 11 | + |
| 12 | +# Prevent rate-limiting errors for Azure Cosmos DB API for Cassandra operations |
| 13 | +[!INCLUDE[appliesto-cassandra-api](../includes/appliesto-cassandra-api.md)] |
| 14 | + |
| 15 | +The cost of all database operations is normalized by Azure Cosmos DB and is expressed by Request Units (RU). Request unit is a performance currency abstracting the system resources such as CPU, IOPS, and memory that are required to perform the database operations supported by Azure Cosmos DB. |
| 16 | + |
| 17 | +Azure Cosmos DB Cassandra API operations may fail with rate-limiting (OverloadedException/429) errors if they exceed a table’s throughput limit (RUs). This can be handled by client side as described in the retry policy in the [Cassandra API recommendations document](https://devblogs.microsoft.com/cosmosdb/cassandra-api-java/#retry-policy). If the client retry policy cannot be implemented to handle the failure due to rate limiting error, then we can make use of the Server-side retry (SSR) feature where operations that exceed a table’s throughput limit will be retried automatically after a short delay. This is an account level setting and applies to all Key spaces and Tables in the account. |
| 18 | + |
| 19 | +## Use the Azure portal |
| 20 | + |
| 21 | +1. Sign in to the [Azure portal](https://portal.azure.com/). |
| 22 | + |
| 23 | +2. Navigate to your Azure Cosmos DB API for Cassandra account. |
| 24 | + |
| 25 | +3. Go to the **Features** pane underneath the **Settings** section. |
| 26 | + |
| 27 | +4. Select **Server-Side Retry**. |
| 28 | + |
| 29 | +5. Click **Enable** to enable this feature for all collections in your account. |
| 30 | + |
| 31 | +:::image type="content" source="./media/prevent-rate-limiting-errors/prevent-rate-limiting-errors.png" alt-text="Screenshot of the server-side retry feature for Azure Cosmos DB API for Cassandra"::: |
| 32 | + |
| 33 | +## Use the Azure CLI |
| 34 | + |
| 35 | +1. Check if SSR is already enabled for your account: |
| 36 | + |
| 37 | + ```azurecli-interactive |
| 38 | + az cosmosdb show --name accountname --resource-group resourcegroupname |
| 39 | + ``` |
| 40 | + |
| 41 | +2. **Enable** SSR for all tables in your database account. It may take up to 15 min for this change to take effect. |
| 42 | + |
| 43 | + ```azurecli-interactive |
| 44 | + az cosmosdb update --name accountname --resource-group resourcegroupname --capabilities EnableCassandra DisableRateLimitingResponses |
| 45 | + ``` |
| 46 | + |
| 47 | +3. The following command will **Disable** server-side retry for all tables in your database account by removing `DisableRateLimitingResponses` from the capabilities list. It may take up to 15 min for this change to take effect. |
| 48 | + |
| 49 | + ```azurecli-interactive |
| 50 | + az cosmosdb update --name accountname --resource-group resourcegroupname --capabilities EnableCassandra |
| 51 | + ``` |
| 52 | + |
| 53 | +## Frequently asked questions |
| 54 | + |
| 55 | +### How are requests retried? |
| 56 | + |
| 57 | +Requests are retried continuously (over and over again) until a 60-second timeout is reached. If the timeout is reached, the client will receive read or write timeout error accordingly |
| 58 | + |
| 59 | +### When is SSR most beneficial? |
| 60 | + |
| 61 | +Server-side retry (SSR) is most beneficial when there is a sudden spike for a short duration of less than 1 minute where in throttling errors can be avoided. If the work load has increased and would stay constantly above the specified RU, then SSR will not help much. The suggestion is to increase the RU appropriately. |
| 62 | + |
| 63 | +### Suggested client-side settings? |
| 64 | + |
| 65 | +After SSR is enabled, the client app should increase read timeout beyond the server retry 60-second setting. We recommend 90 seconds to be on the safer side. |
| 66 | + |
| 67 | +SocketOptions setReadTimeoutMillis |
| 68 | +DefaultDriverOption.REQUEST_TIMEOUT |
| 69 | + |
| 70 | + |
| 71 | +### How can I monitor the effects of a server-side retry? |
| 72 | + |
| 73 | +You can view the rate limiting errors (429) that are retried server-side in the Cosmos DB Metrics pane. These errors don't go to the client when SSR is enabled, since they are handled and retried server-side. |
| 74 | + |
| 75 | +You can search for log entries containing *estimatedDelayFromRateLimitingInMilliseconds* in your [Cosmos DB resource logs](../cosmosdb-monitor-resource-logs.md). |
| 76 | + |
| 77 | +### Will server-side retry affect my consistency level? |
| 78 | + |
| 79 | +Server-side retry does not affect a consistency levels. Requests are retried server-side if they are rate limited (Error 429). |
| 80 | + |
| 81 | +### Does server-side retry affect any type of error that my client might receive? |
| 82 | + |
| 83 | +No, server-side retry only affects rate limiting errors (429) by retrying them server-side. This feature prevents you from having to handle rate-limiting errors in the client application. All [other errors](troubleshoot-common-issues.md) will go to the client. |
| 84 | + |
| 85 | +## Next steps |
| 86 | + |
| 87 | +To learn more about troubleshooting common errors, see this article: |
| 88 | + |
| 89 | +* [Troubleshoot common issues in Azure Cosmos DB's API for Cassandra](troubleshoot-common-issues.md) |
| 90 | + |
| 91 | + |
| 92 | +See the following articles to learn about throughput provisioning in Azure Cosmos DB: |
| 93 | + |
| 94 | +* [Request units and throughput in Azure Cosmos DB](../request-units.md) |
| 95 | +* [Provision throughput on containers and databases](../how-to-provision-throughput-cassandra.md) |
| 96 | +* [Partition key best practices](../cassandra-partitioning.md) |
| 97 | + |
0 commit comments