Engineering With Java

Engineering With Java

Java Bug Fix Coding Question - Call to External API

Concept, Coding and Examples.

Suraj Mishra's avatar
Suraj Mishra
Feb 19, 2026
∙ Paid

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 )

So far we have covered 44+ real world based interview questions and will add up to 100 by end of this year.

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:

User's avatar

Continue reading this post for free, courtesy of Suraj Mishra.

Or purchase a paid subscription.
© 2026 Suraj Mishra · Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture