How can I retry a failed request without retrying every kind of error?
Quick answer
Retry only when the failure is explicitly treated as temporary by the service and repeating the operation is safe. Set a maximum number of attempts and keep delays inside the caller’s deadline. Do not retry every exception or assume a status code has the same meaning for every API. For failures you have not classified, stop and use ordinary error handling or review the service’s guidance. [S1] [S2]
The question, the details, the next step.
A practical checklist
Confirm the service documents the failure as transient for this operation.
Confirm repeating the operation is safe; if uncertain, do not retry.
Set a maximum total attempt count and a caller deadline.
Use bounded backoff with jitter, and keep each wait within the remaining deadline.
Limit aggregate retries where many requests can fail together; consider a circuit breaker.
Send unclassified failures to ordinary error handling or review.
A few more useful answers
Should every HTTP 5xx response be retried?
No universal status-code rule is established here. Azure guidance describes 5xx responses as typical candidates, but says to check the specific service’s behavior and retry guidance. [S1]
Is it safe to retry a request that changes data?
Not automatically. Check whether repeating the operation is safe and how the service handles repeated submissions; non-idempotent repeats can cause inconsistencies. [S1]
Does a maximum attempt count prevent overload?
It bounds retries per request, but does not by itself limit retries across many requests. Guidance also recommends limiting aggregate retries and considering a circuit breaker for repeated dependency failures. [S2]
Sources
References used for this guide.
- [S1] Transient Fault Handling - Azure Architecture Center learn.microsoft.com · Checked
- [S2] RESTful Web API Implementation Best Practices - Azure Architecture Center learn.microsoft.com · Checked
