14

I am using the mix Spring-Cloud + feign + spring-retry to help retry requests on the client side (all are Kotlin-based back-ends)

My spring-boot conf is like this:

myApp:
  ribbon:
    OkToRetryOnAllOperations: true
    retryableStatusCodes: 404, 503

(note: OkToRetryOnAllOperations=true is only present to retry also POST/PUT requests)

Retrying 404 & 503 HTTP codes sounds good, but I cannot figure out if there is a "classic" or "default" list of error codes to retry. Does this kind of good practice exist?

We suppose all the requests are idempotent on the server side (if not, retrying could cause problems).

Jeremy L
  • 251
  • 1
  • 3
  • 12
  • Those codes could be relevant to retry the requests too: 408, 500, 502, 504 ? – Jeremy L Aug 09 '18 at 14:55
  • Does this answer your question? [Which HTTP errors should never trigger an automatic retry?](https://stackoverflow.com/questions/47680711/which-http-errors-should-never-trigger-an-automatic-retry) – Michael Freidgeim Mar 03 '23 at 12:27

2 Answers2

19

As a very rough rule of thumb:
4XX - client did something bad
5XX - server did something bad

But it very much depends of the actual API.
Should you retry 500? Maybe, because the server had an unexpected hiccup while connecting to DB. Or, maybe you're sending it something it's not expecting, and instead of returning you 4XX it crashes.

There is usually not much reason to retry 404, unless you expect that this resource will appear.

The only HTTP codes which is valid for retry are 408, 502, 503 and 504

AWS clients also retry 429.

Alexey Soshin
  • 16,718
  • 2
  • 31
  • 40
10

In general, I recommend these:

  • 408 Request Timeout
  • 425 Too Early
  • 429 Too Many Requests
  • 500 Internal Server Error
  • 502 Bad Gateway
  • 503 Service Unavailable
  • 504 Gateway Timeout

But it really depends on the API, so you can look up its documentation if it has it. For example, Whatsapp uses 500 for errors that can be retried or not.

Lucas Vazquez
  • 1,456
  • 16
  • 20