Why a retry budget saves a slow host
Two clients send the same 80 requests per second to the same host. At 8 s the host slows down and can serve only 60 per second. At 24 s it is fixed.
Both clients retry failed requests up to 3 times. Only the right one has a retry budget. Press Play: the page slows down at key moments and says what happened.
Retries + retry budget
retryBudget: { ratio: 0.1, windowMs: 1000 }Load on the host (attempts per second, over the last 1 s)
The dashed line is what the host can serve. Above it, the host falls behind and requests time out.
Requests that succeed (per second, out of 80)
The budget gets more requests through during the outage, and all of them once the host is fixed.
Why plain retries never let go
- The host slows down. Requests wait longer than the client's timeout, so the client counts them as failures.
- Every failure comes back as a retry, up to 3 times. One request can become 4 attempts.
- The host now gets about 3.6× its normal traffic. It spends time on requests whose clients already gave up, so it serves even fewer.
- Fewer served means more failures, which means more retries. The loop feeds itself.
Look at the left lane after the host is fixed. It can serve 120/s again, but the retries keep sending it more than that, so it stays down.
This is a metastable failure. The original cause is gone, and the retries alone keep the outage going.
What the budget changes
The budget doesn't look at whether a single request deserves a retry. It looks at the whole partition: retries may add at most ratio on top of the first attempts seen in the last windowMs.
With ratio: 0.1, the host gets at most about 1.1× its normal load over any 1 s window, however bad things get.
A refused retry fails right away with its last error, so the caller hears about it quickly instead of waiting.
As soon as the host is fixed, load is already below capacity and everything succeeds.
Try moving the sliders: with 1 max retry, even the left lane recovers. With a budget ratio of 0.5, the right lane carries more load during the outage.
In Vereda
This page follows the logic of tryWithdraw in src/queue/retry-budget.ts. A test, test/demos/retry-budget.parity.test.ts, checks the budget rule on this page against the real RetryBudget.
The host is a model. Its capacity, overload collapse, random failures and retry delay are invented for the demo, and no test checks them.
In the model, the host's throughput drops as it gets overloaded, down to 30% at 2.2× its capacity. 5% of requests fail at random, and retries wait 0.3 s before they go out.
The model has no client timeout: a request the overloaded host doesn't serve counts as failed, standing in for one that timed out.
Load is shown over the last second, the window the budget counts in. Tick by tick, admitted retries arrive in bursts: a window's allowance goes out as soon as room frees up.
Here minRetriesPerSec is 1 instead of Vereda's default of 10, so the ratio is what you see working.
