Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the http codes to automatically retry the request?

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).

like image 680
Jeremy L Avatar asked Aug 09 '18 14:08

Jeremy L


1 Answers

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

like image 61
Alexey Soshin Avatar answered Dec 21 '22 02:12

Alexey Soshin