Try
↑ ↓ move↵ openesc close

Interview prep / Retries and circuit breakers

Junior · Retries and circuit breakers · System design interview question

Your client library's default timeout for calling an internal service is 30 seconds. The service normally answers in 80 ms, and 99 percent of calls finish within 400 ms. Is the default a problem?

Sketch your own answer first, then compare it with the one below.

A strong answer

Yes. A 30 second timeout is 75 times the 99th percentile. When the service hangs, every caller holds a thread, a connection and its memory for the full 30 seconds. If the caller handles 200 requests a second, that is 6,000 stuck requests within 30 seconds, and the caller runs out of threads and stops answering its own users. The failure of one service has spread to its caller.

Pick the timeout from two things. One is how long the user, or the caller above you, is willing to wait. The other is how the service normally behaves. Something near the 99th or 99.9th percentile, with some margin, such as 500 ms to 1 second here, catches real hangs and rarely cuts off a healthy call.

Do not make it too tight either. A timeout at the median would fail half the calls and trigger retries for work that was about to finish.

Set it explicitly in code. Defaults in libraries are often very long or even infinite, and they were chosen without knowing your service.

Sources

Learn it by running it

The retries, timeouts and circuit breakers lesson explains the mechanism behind this question, and its lab lets you change the parameters and watch the effect.

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms