Nice walkthrough on retries. It’s cool how a couple of annotations can make failure handling feel so effortless. Could this approach cause issues if the API keeps failing for longer periods though?
Let's understand Retries in Spring Boot
1 Comment
@[Andrew Mewborn] Nice followup.
This article covers how retries can be implemented in spring in scenarios where target api fails for a short period of time. But In real life applications, mishaps occur all the time and apis might not respond for hours or even days. For covering such scenarios we can use exponential backoffs instead of fixed backoffs.
@Retryable(
maxAttempts = 10,
backoff = @Backoff(delay = 2000, multiplier = 2, maxDelay = 15000)
)
Exponential backoff improves the situation by:
- Spacing out retries to reduce load on the target system.
- Avoiding a retry storm.
- Giving the remote API some time to recover.
But if the remote service is down for long, retrying — even slowly — becomes wasteful. It keeps your threads busy waiting. At that point, you need a different solution altogether.
You should switch from retrying → circuit breaking . A Circuit Breaker pattern detects continuous failures and stops retrying temporarily.
I will soon cover circuit breaker in my upcoming posts, stay tuned and stay curious.