Timeouts, retries & circuit breakers

Timeout budgets, exponential backoff with jitter, retry storms, circuit breakers, bulkheads, graceful degradation. Distinguishes operators from diagram-drawers.

About 27 min read3-question knowledge check

The mental model

A restaurant kitchen with one waiter. A table orders a dish that needs a special ingredient from the shop next door. The shop is slow today. The waiter walks over, waits, walks back — and while waiting, nobody else gets served. Now imagine every table orders that dish. The whole restaurant stops, not because the kitchen is broken, but because every server is standing in someone else's queue.

That is a distributed backend without failure handling. The three tools are the three things a sensible waiter does:

  • Timeout — "I will wait two minutes, then come back and tell you it is unavailable." Without it, one slow dependency holds a thread, a connection, and a customer forever.
  • Retry — "the shop dropped my order slip, I will ask once more." Without it, transient blips become user-visible errors. With it done wrongly, you send five waiters and finish off a shop that was merely struggling.
  • Circuit breaker — "the shop has failed the last twenty times, stop walking over there; check again in thirty seconds." Without it, you keep paying full timeout cost on every request to a dependency you already know is down.

The reason these are non-negotiable is a property of distributed systems that surprises people: a slow dependency is worse than a dead one. A dead process on a reachable host returns connection-refused in a millisecond and your code takes the fallback path. A blackholed host or partitioned network is not that cheap: it costs a full connect timeout, which is why connect timeouts and breakers matter. A dependency answering in 30 seconds silently consumes every worker in your pool, and your service — which is perfectly healthy — stops answering requests it could have served. That is cascading failure, and it is how a problem in one non-critical service takes down a whole product.

The fourth idea ties them together: a timeout budget. Every request that enters your system gets a total time allowance, and each hop spends part of it. If the caller will give up at 3 seconds, there is no point your downstream call having a 10-second timeout — you are doing work nobody will read.

The full lesson continues with 15 more sections
  • Deep dive
  • Internal architecture
  • Real-world use cases
  • Best practices
  • Common mistakes
  • Performance
  • Security
  • Production troubleshooting
  • Advantages & disadvantages
  • Alternatives
  • Interview expectations
  • Interview questions
  • Facts to remember
  • Cheat sheet
  • Quick revision