API retry logic in Amazon Web Services

WillMcavoy picture WillMcavoy · Oct 19, 2016 · Viewed 13.7k times · Source

http://docs.aws.amazon.com/general/latest/gr/api-retries.html

This document mentions that "each AWS SDK implements automatic retry logic and AWS SDK for Java automatically retries requests."

What is the default mechanism for Java AWS SDK, if i don't specify any retry config? I have been using the Java AWS SDK and get a straightforward service exception if something fails on AWS service side. I have never experienced any "automatic" retry mechanism. Can someone explain what this retry mechanism is?

Answer

laughedelic picture laughedelic · Nov 2, 2016

The same documentation page says:

The AWS SDK for Java automatically retries requests, and you can configure the retry settings using the ClientConfiguration class.

You should check the official documentation for ClientConfiguration, it has plenty of methods to tune its behaviour regarding retry logic. Here are the most important:

  • withMaxErrorRetry Sets the maximum number of retry attempts for failed retryable requests (ex: 5xx error responses from services)
  • withRequestTimeout Sets the amount of time to wait (in milliseconds) for the request to complete before giving up and timing out [...]
  • withThrottledRetries Retry throttling is a feature which intelligently throttles retry attempts when a large percentage of requests are failing and retries are unsuccessful [...]
  • withRetryPolicy This is the most interesting, it allows you to choose RetryPolicy and change:
    • BackoffStrategy The hook for providing custom back-off strategy to control the sleep time between retries
    • RetryCondition The hook for providing custom condition on whether a failed request should be retried
    • maxErrorRetry
    • honorMaxErrorRetryInClientConfig (whether to respect the configuration setting mentioned above)

Also note that if you haven't noticed the automatic retry mechanism, it could be due to the client-side errors. These settings are only for retrying requests in case of server (5xx) or throttling errors:

client errors (4xx) indicate that you need to revise the request to correct the problem before trying again

If you claim that it were "service side" fails, you should provide some code to reproduce the situation and analyze what is actually happening.


Now about defaults:

What is the default mechanism for Java SDK, if i don't specify any retry config?

You can lookup the default values of the ClientConfiguration constant fields. But note, that it may differ depending on the service you use (in particular DynamoDB is a special case). Check also PredefinedClientConfigurations and PredefinedRetryPolicies classes.