Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

When is it safe to retry a failed call, and why should retries use exponential backoff with jitter?

It is safe to retry when the failure is transient, such as a timeout, a connection reset or an HTTP 503, and when repeating the operation cannot do harm, because it is idempotent or carries an idempotency key. Client errors such as 400 or 404 will fail the same way again, so we never retry them. We use exponential backoff so a recovering service is not hammered, add jitter so thousands of clients do not retry at the same instant, and cap both the number of attempts and the total time.

Why this question is asked

Retries look like a free win: the call failed, so try again. In practice, careless retries cause two serious problems. They can do something twice, such as charging a card twice, and they can turn a small hiccup into an outage by multiplying load just when a service is weakest. Interviewers ask this to check that we know which failures are worth retrying and how to space the attempts. In this answer, we will sort failures into retryable and not retryable, see why idempotency decides whether a retry is safe, work through exponential backoff and jitter with numbers, and finish with the limits every retry policy needs.

1Which Failures Are Worth Retrying?

A retry only helps if the next attempt has a real chance of succeeding. That is true for transient failures, problems that come from a passing condition rather than from the request itself. A connection reset, a read timeout, an HTTP 503 Service Unavailable or a 502 from a load balancer during a deployment usually go away within seconds.

A client error, a 4xx status, says the request itself is wrong. A 400 Bad Request has invalid data, a 404 Not Found asks for something that does not exist, and a 401 or 403 lacks permission. Sending the same request again gives the same answer, so a retry only adds load. Two 4xx codes are exceptions worth knowing: 429 Too Many Requests and 408 Request Timeout are temporary, and we may retry them after the time given in the Retry-After header.

Retry or not?
FailureRetry?Reason
Connection reset, connect timeoutYestransient network problem
Read timeoutOnly if idempotentthe server may have done the work
503, 502, 504Yes, with backoffservice overloaded or restarting
429 Too Many RequestsYes, after Retry-Afterwe were sending too fast
400, 404, 409, 422Nothe same request fails the same way
401, 403Noneeds new credentials, not a repeat

2Why Idempotency Decides Whether a Retry Is Safe

An operation is idempotent when doing it twice has the same effect as doing it once. Reading a product, setting an address to a value, or deleting order 42 are idempotent. Placing an order or charging a card are not: two calls create two orders.

This matters most for timeouts. When a read timeout fires, we do not know whether the server never received the request or did the work and the reply got lost. For a GET that does not matter. For a payment, a blind retry may charge the customer twice. The fix is an idempotency key: the client generates a unique id for the operation and sends it with every attempt. The server stores the key with the result, and when the same key arrives again it returns the stored result instead of charging again.

Java
POST /payments
Idempotency-Key: 7f3c9a2e-41b8-4c55-9d0e-2a1b6f0c9e11
{ "orderId": 42, "amount": 1999 }
// attempt 1: server charges the card, reply is lost -> client sees a timeout
// attempt 2: same key -> server finds key 7f3c..., returns the first result, no second charge

So the rule is: retry idempotent operations freely, and make other operations idempotent with a key before allowing retries.

3Exponential Backoff: Giving the Service Room to Recover

If we retry immediately, a service that just failed because it was overloaded gets the same load again, at once. Exponential backoff makes each wait longer than the last, usually doubling it, so a service that needs a few seconds to recover gets them. We also put a ceiling on the wait so it does not grow without limit.

Java
long base = 100, cap = 2_000;
for (int attempt = 0; attempt < 4; attempt++) {
long backoff = Math.min(cap, base * (1L << attempt));
System.out.println(backoff); // 100, 200, 400, 800
}

Notice that backoff alone still has a problem. If a thousand clients all failed at the same moment, they all wait exactly 100 ms and retry together, then exactly 200 ms and retry together again. The load arrives in synchronised spikes, which is precisely what an overloaded service cannot handle.

4Jitter: Spreading the Retries Out

Jitter adds randomness to each wait. A common form, called full jitter, picks a random wait between zero and the backoff value. The thousand clients then retry at a thousand different moments, and the load arrives as a smooth trickle instead of a spike.

Java
long backoff = Math.min(cap, base * (1L << attempt)); // 400 on the third attempt
long sleep = ThreadLocalRandom.current().nextLong(backoff + 1); // somewhere in 0..400, e.g. 137
1,000 clients retrying after one failure
PolicyWhen the retries arriveEffect on the service
Immediate retryall 1,000 at once, againsame overload, no recovery
Backoff only1,000 at 100 ms, 1,000 at 300 msrepeated synchronised spikes
Backoff with full jitterspread across each windowsmooth load, room to recover

Libraries do this for us. Resilience4j has a randomised wait setting, and Spring Framework 7's retry support has a jitter attribute (check your version). The important part is knowing why it exists, so we never turn it off.

5Limiting Attempts and Total Time

Every retry policy needs two limits. A maximum number of attempts, typically 3 including the first call, stops a permanent failure from being retried forever. A total time limit keeps the retries inside what our own caller is willing to wait: if the user's request has a 2 second budget, three attempts with 1 second timeouts cannot fit, so the policy must stop earlier.

We should also retry at one layer only. If every service in a chain retries, the attempts multiply, and three layers of 3 attempts make 27 calls to the bottom service. For longer outages, a circuit breaker should stop the retries altogether.

6Follow-up questions

Is a POST ever safe to retry?

Yes, when the server supports idempotency keys or the operation is naturally idempotent, for example a POST that creates a resource with a client-chosen id. Without either, retrying a POST after a timeout risks doing it twice, so we only retry it when we know the request never reached the server, such as a connect failure.

Should we retry a read timeout?

Only for idempotent calls. A read timeout means we stopped waiting, not that the server stopped working. For a GET it is safe. For anything that changes state, we need an idempotency key first.

Why not use a fixed delay with jitter instead of exponential backoff?

A fixed delay does not adapt to how long the problem lasts. If the service needs ten seconds to recover, fixed 200 ms retries keep hitting it throughout. Exponential growth quickly backs off for longer problems while still retrying fast for short blips.

7Conclusion

In this answer, we saw that a retry is safe only for transient failures such as timeouts, connection resets and 503s, and only for idempotent operations or those protected by an idempotency key. Exponential backoff gives a struggling service time to recover, jitter keeps many clients from retrying in lockstep, and limits on attempts and total time keep the retries inside the caller's budget.

What to say in the interviewAbout 90 seconds aloud

Open with

I retry only when two things are true. The failure must be transient, like a connection reset, a timeout, a 503 or a 502 during a deployment, or a 429 after its Retry-After time.

Then, if they want more

And the operation must be safe to repeat. Client errors such as 400, 404 or 403 will fail exactly the same way again, so retrying them just adds load.

For safety, GET, PUT and DELETE are idempotent, but a payment or an order creation is not, and a read timeout does not tell me whether the server already did the work.

So for those I require an idempotency key: the client sends a unique id with every attempt and the server returns the stored result if it sees the key again. On spacing, I use exponential backoff, for example 100, 200, 400 milliseconds with a cap, because retrying immediately sends the same load to a service that is already struggling.

I add jitter, usually full jitter, a random wait between zero and the backoff value, because without it all the clients that failed together retry together in synchronised spikes.

Finally I cap attempts, usually three including the first call, cap total time so it fits the caller's deadline, retry at only one layer, and put a circuit breaker in front for longer outages.

About this answer

Last updated
12 November 2026
Versions it names
Spring Framework 7
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "When is it safe to retry a failed call, and why should retries use exponential backoff...": https://scrivio-interview-library.netlify.app/spring-boot/resilience/95842f93a5/