In this lesson · topic 6 of 7
Topic 6
Let the client throttle itself
5 min read
A rejection is cheap, but it is not free. The server still has to accept the connection, read the request and write an error. At 100,000 rejections a second that adds up, and it is spent on an already overloaded machine. The cheapest rejection is one that never leaves the client.
The rule
The Google SRE book describes adaptive throttling. Each client keeps two counts over a recent window, about two minutes:
- requests: attempts made by the application code, including those the client itself refused,
- accepts: attempts the backend accepted.
Then, for each new request, the client rejects it locally with probability
max(0, (requests − K × accepts) / (requests + 1))
K is a multiplier. The book uses 2.
Reading the formula
When the backend accepts everything, accepts equals requests. The numerator is requests − 2 × requests, which is negative, so the probability is zero. Nothing is throttled.
Now the backend starts rejecting. Take 1,000 requests with 400 accepted:
- (1,000 − 2 × 400) / 1,001 = 200 / 1,001, about 20 percent of new requests are refused locally.
If only 200 of the 1,000 were accepted:
- (1,000 − 400) / 1,001 = 600 / 1,001, about 60 percent.
If 600 of 1,000 were accepted, the numerator is 1,000 − 1,200 = −200, and the probability is zero. The client sends everything.
Predict first
Why K is above 1
With K = 1 the client would start refusing at the first rejection, and it would try to send only what the backend accepts. It would have almost no spare traffic to notice that the backend had recovered. With K = 2 the client keeps sending up to twice what the backend accepts, so there is always a stream of requests testing the water. If the backend recovers, accepts climb, and the throttle fades by itself.
A higher K throttles later and sends more load into the trouble. A lower K protects the backend more and reacts to recovery more slowly. The book uses 2 as its example and says to tune it to how much rejected traffic the backend can stand.
What it does not do
- It does not know why the backend is rejecting. A backend that sheds one class of request while serving the rest causes the client to throttle everything. Per-class counts, kept separately, fix this.
- It acts on the client’s own history. A new or quiet client starts with no information and sends freely.
- The effect is a smooth reduction in load, not a hard cap. Pair it with a retry budget so retries cannot undo it.