Implementing exponential backoff to manage rate-limit errors in Square

I am implementing an integration with Square. In General Requirements section, there is a requirement: Your app uses exponential backoff to manage rate-limit errors.

I am using Square .NET SDK. When creating a client there is an option to set numberOfRetries.

My question is that does it meet the requirement or not?

I can’t see the actual code that uses this setting in the source code given on github.

Any help would be appreciated!

The SDK has exponential backoff build into it so you can set the number of retries and the SDK will take care of the rest. :slightly_smiling_face:

Thank you for the response.

I get to see that there are other config settings as well like BackoffFactor, RetryInterval, StatusCodesToRetry and MaximumRetryWaitTime.

What are the default values for these settings?

Do I need to just add numberOfRetries to meet the requirement or settings all values are must?
I think the requirement is to only handle Too Many Requests 429 error like this.

I would appreciate if there are any more details on this.

The Square .NET SDK includes built-in rate limiting features to help developers handle API request rate limits. Here are the default values for the relevant configuration settings:

  • BackoffFactor: The default backoff factor is 2. This means that the wait time between retries will be doubled each time a retry occurs.
  • RetryInterval: The default retry interval is 1 second. This is the initial amount of time to wait before the first retry attempt.
  • StatusCodesToRetry: By default, the SDK will retry on HTTP status codes 429 (Too Many Requests), 503 (Service Unavailable), and 500 (Internal Server Error).
  • MaximumRetryWaitTime: The default maximum retry wait time is 60 seconds. This is the maximum amount of time that the SDK will wait before making a retry attempt.

To handle the “Too Many Requests” (429) error, you can indeed focus on setting the numberOfRetries configuration option, which determines how many times the SDK will retry a request that has failed due to rate limiting. By setting this value, you can control how aggressively your application retries requests.

However, it’s important to note that while setting numberOfRetries can help manage rate limits, you should also consider the other settings to ensure that your retry strategy is effective and does not create additional load on the system. For instance, having a reasonable BackoffFactor and MaximumRetryWaitTime can prevent your application from retrying too quickly and potentially exacerbating the rate limiting issue. :slightly_smiling_face:

Thanks a lot for sharing the details