Search code examples
javadesign-patternsretrypolicyexponential-backoff

Why we apply delay between retry requests


When we have a piece of code that often fails and must be retried. Then we use retry pattern.

try {
        //do request here
} catch (Exception e) {
        //wait for some millisecond and retry
        retry();
}

We normally delay for some millisecond before retry that request. I want to know that why we need some delay? What will happen if retry request did not wait and send request again.


Solution

  • It is unlikely that a problem with the server is fixed in a few microseconds so an immediate retry is very unlikely to work and would only contribute to problem. So a delay between retry is best practice to follow.