Retries multiply down the layers, so retry in one layer
Retries help one request, but across layers they can turn a small failure into an outage.
Three layers each make up to 4 attempts. How many attempts can one user action send to the database?
Layer 3's 64 attempts all land on the database.
Retries are how a partial failure becomes a total one. The SRE book defines a cascading failure as a failure that grows over time through positive feedback, and retries are the classic feedback.
In its example, three layers each retry 3 times, so one user action can become 4 × 4 × 4 = 64 attempts on the database.
The Builders' Library does five layers at three tries each: 35=243 times the load on the database, which makes it unlikely to ever recover.
- Retry in one layer. In a batch service that's the dispatcher. Workers and clients report failures and don't retry on their own.
- Budget the retries. Beyond three attempts per request, Google's clients retry only while retries stay below 10% of their requests. The SRE book works out that this holds retry growth to about 1.1 times the load, instead of nearly 3 times. Amazon gets a similar effect by limiting retries locally with a token bucket.
- Use circuit breakers with care. A circuit breaker stops all calls to a downstream service once errors pass a threshold. The Builders' Library warns that breakers add modes to a system that are hard to test, and can add a lot of time to recovery.
Batch gets a gentler breaker for free. When a model's replicas start failing, pause dispatch to that model and let the queue hold the work. Don't burn retries and turn transient failures into errored results.
A paused queue spends window, which you have plenty of, as long as window burn says so.
In the editor, write attempts(tries): the attempts one user action can send to the bottom layer, when layer i makes up to tries[i]. Then write load(requests, failed, budget): the load as a multiple of normal when each failed request is retried once, and retries stop at budget of the requests.
- 1
Write
attempts(tries): the attempts one user action can send to the bottom layer, when layer i makes up totries[i]. - 2
Write
load(requests, failed, budget): the load as a multiple of normal when each failed request is retried once, but retries stop atbudgetof the requests.
Run your code to check it. Output shows here.