Try
↑ ↓ move↵ openesc close

Interview prep / Retries and circuit breakers

Senior · Retries and circuit breakers · System design interview question

A request passes through three services in a chain, and each one retries its call to the next. What is the problem, and how do you fix it?

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

A strong answer

Retries multiply across layers. If each layer makes up to three attempts, a single failed request at the bottom can produce three attempts from the layer above for each of its three, and so on up the chain. The load on the lowest service, which is usually the one in trouble, grows as the product of the attempts at every level.

The fix is to decide where retries belong. Usually it is one layer, the one nearest the user or the one that knows the operation is safe to repeat. The other layers fail fast and pass the error up. Where a lower layer must retry, it uses a retry budget so the total is capped.

Also pass the deadline down the chain. If the first caller waits 2 seconds, the layers below get the time that is left, not a new timeout each. Otherwise work continues below after the top caller has gone, which wastes capacity.

Return clear signals. A lower layer that is overloaded should say so, with an error that tells the layers above not to retry.

Three layers of three attempts each means 27 attempts at the bottom for one user request.

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