SproutStackSproutStack home

Failures, Retries & Rate Limits

5 min readBeginner-friendlyFree to read

Before this, it helps to know: Idempotency & Exactly-Once Illusion.

Read a little, play a little. No scary maths, and no rush.

Share:

Everything fails — plan the funeral

Disks die, networks blip, deploys go sideways at 5 PM on Fridays. The question is never whether a dependency fails, but what your system does in the seconds after. Beginners build the happy path; interview-ready engineers narrate the sad path without being asked.

Timeouts: don't wait forever

Every outbound call gets a deadline — say 200 milliseconds for an internal service. Without one, a hung dependency holds your threads hostage until your own callers time out, and the failure avalanches upward. A timeout converts "stuck forever" into "failed fast," which is something you can actually handle.

Retries: with manners

Failed fast? Retry — but politely, and at most twice:

  • Only retry idempotent operations. Retrying "charge card" creates double charges; retrying "fetch order" is harmless.
  • Backoff exponentially: wait 100ms, then 200ms, then 400ms — give the struggling server room to breathe.
  • Add jitter: randomize each wait so a thousand clients don't all retry in lockstep (a synchronized retry wave is called a retry storm, and it finishes what the outage started).

Circuit breaker: stop knocking on a dead door

If half your calls to a service are failing, stop calling it for a while — "open the circuit" and fail fast locally instead. After a cooldown, let one probe request through (half-open); if it succeeds, close the circuit and resume. Libraries implement this in ~10 lines, and interviewers light up when you mention it unprompted.

Bulkheads and budgets

A bulkhead (named after ship compartments) isolates failures: the recommendations service gets its own thread pool, so when it floods, checkout keeps sailing. And rate limiting at the edge (token bucket per user, 429 + Retry-After) keeps one abusive client from becoming everyone's outage.

A worked example: one slow dependency

A product page calls a recommendations service. One afternoon that service starts taking five seconds per response.

  • Without protections: every page request waits five seconds, the web servers run out of free workers, and the whole site stops responding, including checkout, which never needed recommendations.
  • With them: a 200 ms timeout fails the call fast, the page shows a simple fallback ("popular this week") instead, and after enough failures the circuit breaker stops calling the slow service entirely until it recovers.

Users see a slightly plainer page. Nobody sees an outage.

callif closedif open or slowProduct pageCircuit breaker200 ms timeoutRecommendationsslow: 5 s per callFallbackpopular this week
The page never waits more than 200 ms for recommendations. When the breaker is open, it skips the slow service and shows the fallback straight away.

Decide the fallback before you need it

For each dependency, write down in advance what the feature does when that dependency fails: hide the section, show cached data, show a default, or queue the work for later. Making this choice during an incident, under pressure, almost always produces a worse answer.

Practice failing

Failure handling that has never run probably does not work. Teams test it on purpose: add artificial delay to a dependency in a test environment, switch one off during a planned exercise, and confirm that timeouts, fallbacks, and alerts behave as designed. It is far better to discover a missing timeout on a quiet Tuesday than during a real outage.

Remember this

  • Timeout everything, retry twice with backoff + jitter, idempotent-only.
  • Circuit breaker after ~50% failures; bulkheads isolate the blast radius.

Check your understanding

5 questions · first-try answers earn the most XP

1. Why should every outbound dependency call have a timeout?
2. What is a retry storm, and what is the usual cause of one?
3. What does a circuit breaker do when a downstream service is failing?
4. Which operations are safe to retry automatically after a timeout?
5. What does a bulkhead pattern isolate, and why?

My notes

Saved in this browser. Highlight a line above and save it, or write it in your own words.

Nothing saved yet. Your highlights will live here.

References

Finished reading?

Ticking it here also ticks the chapter in the sidebar, the section count and your streak — it is all one number.

Practice this in an incident

Try a design drill

Related chapters

Spotted a mistake or want a topic covered? Report an issue

📬 An occasional email when new lessons land

New lessons and showdowns, no more than a few times a month. No spam, unsubscribe anytime. We store your email only to send the newsletter.