I want to implement Retry pattern in PHP (Guzzle) to determine if I need to send the request again in case of failure or not. And in case I need to, should I use some delay before sending it again or not. NOTE: it's internal services communication, and each service is in scaling group and behind a load balancer, so we assume that target URL's is existing URL but may be unavailable for some reason, also all servers are NGINX
Is there any best practices whether to perform a retry or not and with delay or not??
As far as I know, status 503
means the server is overloaded, so probably in such a case small delay can help to wait for new instance to start and help to distribute the load???
What to do in case of a 502/504
error, also retry with some delay???
What to do in case of a 500
error?? In my understanding 500
should be thrown when something is wrong with a server or logic in general and we do not need to perform any retry???
What about 400
, same action as if we got 500
??
What about 404
?? There can be two types of 404
, one is if the endpoint is really not existed (I do not think it's possible in case of communication between internal services), and another is requested resource not found (for example user not found by credentials). I think in case of 404
we do not need to perform a retry
422
I use in case of some domain error or validation error, but maybe the server can return it in some other case? If it's only triggered by me I can assume no retry needed.
What about other status codes, also there NGINX specific codes???
I know that probably I need to make a specific retry strategy per URI cases, but I believe there are some common/reusable rules.