Retrying#
When interacting with Melissa’s web services, requests may occasionally fail due to network instability, temporary server issues, or rate limits. Integrating a robust retry mechanism into your request handling ensures that processes can continue smoothly despite intermittent disruptions.
When to Use Retries#
Certain situations will benefit from retries, including:
Transient Errors: Issues like network congestion, timeouts, DNS resolution failures, and connection loss typically resolve on their own. Retrying can help the request succeed once the issue clears.
Server-Side Errors: These errors, often accompanied by 5xx HTTP status codes, indicate server issues. Retrying allows time for adequate recovery.
Rate Limiting: Exceeding the allowed request rate results in throttling and a 429 status code response. Retrying with a delay can help prevent surpassing rate limits. For more details, please refer to Melissa’s Rate Limiting page.
When Not to Retry#
Avoid retries for 4xx HTTP status codes (except 429s), as they indicate client-side errors. Instead, verify that your request format is correct and that you are using a valid license.
Strategies#
Retry Limits: Set a cap on the number of retry attempts (e.g., five) or the total time spent retrying a request. This prevents indefinite retries.
Exponential Backoff: Instead of retrying immediately, increase the delay between attempts exponentially to reduce server strain. For example, wait 1 second after the first retry, 2 seconds after the second, 4 seconds after the third, and so on until the retry limit is reached.
Jitter: Add a random interval to wait times to prevent synchronized retries, reducing server contention during temporary outages.
Logging#
Logging relevant information when requests fail is crucial for debugging. Data such as request details, error messages, HTTP status codes, and the total number of retries will help identify the root cause of any issues you are encountering.
Libraries#
Retry logic does not need to be implemented from scratch. In fact, many popular programming languages provide comprehensive libraries to aid in creating and maintaining effective retry strategies.
Resilience4j (Java)
Polly (C#)
urllib3.Retry (Python)
retry (JavaScript)