In this lesson · topic 5 of 7
Topic 5
Deciding who gets shed first
6 min read
The policies in the lab treat every request alike. A real service is never that tidy. Checkout, search and a background prefetch share a fleet, and when it is overloaded they do not deserve equal treatment.
A worked overload
A service can do 1,000 requests a second. Right now 1,400 are offered:
| Class | Offered per second |
|---|---|
| Checkout | 200 |
| Search | 700 |
| Prefetch | 500 |
The server is 400 requests a second over. Shedding at random drops 400 / 1,400, about 29 percent, of every class. Checkout loses 57 requests a second. That is the worst place for the loss to land.
Shedding by class drops 400 of the 500 prefetch requests, 80 percent of that class, and touches nothing else. Checkout and search get through at 100 percent. The total served is the same 1,000. What changed is who paid.
Predict first
Where the tag comes from
The class has to be set once, at the edge, and travel with the request through every internal call. The Google SRE book describes four levels, which it calls criticality: critical plus, critical, sheddable plus and sheddable. The point is that a backend does not have to guess. If checkout calls inventory and inventory calls a pricing service, all three see a critical request. A prefetch that reaches the same pricing service arrives marked sheddable, and is the first thing to go there.
Two habits keep this honest.
- Default low. If the tag is missing, treat the request as sheddable. A default of high means every new caller is critical by accident.
- Audit the top class. Every team will label its own traffic critical. Review who is allowed to, and watch the share of traffic in each class. If 60 percent is critical, the tag means nothing.
The signal that triggers shedding
Request rate is a poor trigger because requests differ in cost. Use something that tracks the problem: queue delay, requests in flight, or CPU. Queue delay is the most direct, because it is what the callers feel.
A rule might read: above 50 ms of queue delay, drop all sheddable traffic. Above 150 ms, drop part of the next class too.
Hysteresis
Suppose shedding starts at 50 ms and stops the moment delay falls below 50 ms. Shedding works, delay falls to 40 ms, shedding stops, the prefetch traffic returns, delay climbs to 55 ms, shedding starts. The service flaps in a cycle of seconds, and callers see errors in bursts.
Give it two thresholds. Start at 50 ms and stop only when delay stays below 20 ms for some seconds. The gap is the hysteresis. It costs a little more shedding than strictly necessary, and it buys a stable system.