Java Bug Fix Coding Question - Call to External API
Concept, Coding and Examples.
Context
You have a service that calls an external API. If the API fails, it retries. But something is wrong with the retry logic. Identify issues in the code, discuss, and fix the code.
📢 Get actionable Java/Spring Boot insights every week — from practical code tips to real-world use-case based interview questions.
Join 5200+ subscribers and level up your Spring & backend skills with hand-crafted content — no fluff.
First 100 paid subscribers will get the annual membership at $50/year ( 62 already converted to paid, 38 remaining )
Not convinced? Check out the details of the past work
Think about the solution out loud in your mind first before looking at the solution
Issues With the Code
1.Infinite Loop
while (true) { ... }Issue:
No exit condition → code can retry endlessly if the API keeps failing.
Wastes CPU, potentially hangs the application.
Fix:
Add a max retry limit.
int MAX_RETRIES = 5;
while (attempts < MAX_RETRIES) { ... }2.No Backoff or Delay Between Retries
Issue:
Immediate retries overload the external API.
Can trigger rate limiting or cascading failures if multiple clients retry at the same time.
Fix:





