How to avoid 429 error "TooManyRequests" on downloading the blob file from storage using Azure SDK for Java?

Anastasiia Ilina 71 Reputation points
2020-08-17T16:42:08.36+00:00

Hello, Azure community!
I would like to ask for your advice regarding the proper work with the storage in the following situation:
Recently we've faced an exception with Status code 429 saying "TooManyRequests" and the message: "The request is being throttled as the limit has been reached for operation type - Read_PerHour.".

We face this kind of response from Azure from time to time while downloading files via our API, which works with Microsoft Azure SDK for Java, version 1.22.0. It seems we may be hitting subscription or tenant limits.
How we work with Azure SDK:
Firstly, we get the storage accounts (com.microsoft.azure.management.Azure#storageAccounts) and then we get storage account by resource group (com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByResourceGroup#getByResourceGroup).
We do this to retrieve the account key to buid the connectionString. Then we get CloudStorageAccount (by com.microsoft.azure.storage.CloudStorageAccount#parse) and then we use create a CloudBlobClient (com.microsoft.azure.storage.CloudStorageAccount#createCloudBlobClient), to get the container and to get the CloudBlockBlob by file path (com.microsoft.azure.storage.blob.CloudBlobContainer#getBlockBlobReference(java.lang.String)). And afterwards to download the file we call com.microsoft.azure.storage.blob.CloudBlob#openInputStream()

So the question is, where exactly in such a flow we overwhelm Azure with the requests and hit the limits? And what is the efficient way to download files via Azure SDK for java (let's consider the situation when we really have the heavy load of download requests), and not to get this error about exceeding the limits?

Thank you very much in advance for any thoughts and advice!

Azure Files
Azure Files
An Azure service that offers file shares in the cloud.
1,213 questions
Azure Storage Accounts
Azure Storage Accounts
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
2,871 questions
Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,575 questions
Azure Stack Hub
Azure Stack Hub
An extension of Azure for running apps in an on-premises environment and delivering Azure services in a datacenter.
181 questions
0 comments No comments
{count} vote

2 answers

Sort by: Most helpful
  1. Sumarigo-MSFT 44,906 Reputation points Microsoft Employee
    2020-08-18T11:33:00.673+00:00

    @Anastasiia Ilina Based on the throttling error details: I would recommend you please refer to this article and let me know the status
    https://video2.skills-academy.com/en-us/azure/virtual-machines/troubleshooting/troubleshooting-throttling-errors

    18315-capture.jpg

    When you reach the limit, you receive the HTTP status code 429 Too many requests. The response includes a Retry-After value, which specifies the number of seconds your application should wait (or sleep) before sending the next request. If you send a request before the retry value has elapsed, your request isn't processed and a new retry value is returned.

    After waiting for specified time, you can also close and reopen your connection to Azure. By resetting the connection, you may connect to a different instance of Azure Resource Manager.

    Azure SDK, the SDK may have an auto retry configuration. For more information, see Retry guidance for Azure services.

    Some resource providers return 429 to report a temporary problem. The problem could be an overload condition that isn't directly caused by your request. Or, it could represent a temporary error about the state of the target resource or dependent resource. For example, the network resource provider returns 429 with the RetryableErrorDueToAnotherOperation error code when the target resource is locked by another operation. To determine if the error comes from throttling or a temporary condition, view the error details in the response.

    For more information, refer to this article: https://video2.skills-academy.com/en-us/azure/azure-resource-manager/management/request-limits-and-throttling

    Troubleshooting API throttling errors

    The limits are documented here: https://video2.skills-academy.com/en-us/azure/azure-subscription-service-limits (please see Subscription limits - Azure Resource Manager section). And you can see the 429 error code from here.

    Based on the documentation, currently you're allowed to make 15000 Read requests/hour for Azure Resource Manager API.

    There is a similar discussion thread in SO please refer to the suggestion

    If the issue still persist, I would like to work closer on this issue

    Hope this helps!

    Kindly let us know if the above helps or you need further assistance on this issue.

    -------------------------------------------------------------------------------------------------------------------------

    Please don’t forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    1 person found this answer helpful.

  2. Sumarigo-MSFT 44,906 Reputation points Microsoft Employee
    2020-08-24T15:38:57.39+00:00

    @Jesse Vander Does Firstly, apologies for the delay in responding here and any inconvenience this issue may have caused. Are you trying to hit SRP limit of 800 account operations per 5 minutes. https://video2.skills-academy.com/en-us/azure/azure-resource-manager/management/azure-subscription-service-limits#storage-resource-provider-limits

    Yes, you can read blobs without enumerating the storage account each time. As far as an example or pattern for Java SDK, I’m not familiar if we have anything better than https://video2.skills-academy.com/en-us/java/api/overview/azure/storage-blob-readme?view=azure-java-stable#download-a-blob-to-a-stream
    Do you need to build the connection string each time (and how many operations per second they are doing) or if they can cache the resource group and storage account names vs. fetching each time.