The autoscaler that made the backlog worse
Failure story 21, in observability and recovery.
The challenge
Section titled “The challenge”The job queue was growing, so the autoscaler quadrupled the number of workers. An hour later, the queue is growing faster than before. What happened?
The setup
Section titled “The setup”| Assumption | Value |
|---|---|
| Jobs | Each job makes one call to a downstream document-rendering service |
| Arrivals | 250 jobs a second during the afternoon peak |
| Downstream | Completes up to 200 calls a second, as long as it has no more than about 100 calls in progress. Beyond that, contention makes every call slower and many time out |
| Workers | Each handles 10 jobs concurrently; failed calls are retried up to 2 times |
| Autoscaler | Adds workers when queue depth rises, from 10 up to 40 |
These are constructed numbers. The shape, where throughput falls when a saturated service is given more concurrent work, is common.
What happened
Section titled “What happened”| Aspect | 10 workers | 40 workers (after scaling) |
|---|---|---|
| Calls in progress at the downstream | 100 | 400 |
| Downstream calls a second, including retries | 200 | about 380 |
| Completed jobs a second | 200 | about 140 |
| Queue growth a second (250 arriving) | 50 | about 110 |
| Age of the oldest job after an hour at that rate | about 12 minutes | about 26 minutes, and rising faster |
The queue was a symptom. The bottleneck was the downstream service, and adding workers only sent it more work than it could do, more slowly, with retries on top.
Why it went wrong
Section titled “Why it went wrong”Scaling on queue depth assumes that more workers means more throughput. That’s true only while the workers themselves are the bottleneck. When the constraint is somewhere else, extra workers convert waiting in the queue, which is cheap, into waiting inside the downstream service, which is expensive: connections, threads and memory held while calls time out. The retries then add load exactly when there’s no capacity for it, the same mechanism as in Retries make systems more reliable.
Two designs
Section titled “Two designs”| Aspect | Design A: scale on queue depth | Design B: bounded concurrency and a retry budget |
|---|---|---|
| Limit on downstream calls | None: workers × 10 | 100 in progress, shared by all workers |
| Retries | Up to 2 per call | Capped at 10% of calls |
| Scaling signal | Queue depth | Age of the oldest job, and only if the downstream has headroom |
| At 250 jobs a second | 140 completed; the queue grows by 110 a second | 200 completed; the queue grows by 50 a second |
| When arrivals fall below 200 | Slow recovery while timeouts clear | The queue starts shrinking immediately |
Design B doesn’t make the backlog disappear, because nothing can complete more than the downstream allows. It keeps the system at its real capacity instead of below it, and makes the remaining choice explicit: shed or defer low-priority jobs, tell producers to slow down, or add capacity downstream.
The check
Section titled “The check”Run the same workload, 250 jobs a second for an hour, against both designs, and plot three lines on one chart:
- Completed jobs a second. Expected: Design B holds at about 200; Design A falls after scaling.
- Age of the oldest job. Expected: rising in both, faster in A.
- Total downstream attempts, including retries. Expected: bounded in B; nearly double in A.
If a design’s completion line falls when the worker count rises, scaling on queue depth is making things worse.
This check is in the checks catalog as test templates in Java and Python.
When the simpler design is enough
Section titled “When the simpler design is enough”- The workers are the bottleneck: CPU-bound jobs with no shared downstream, such as image resizing on the worker itself.
- The downstream scales with the load, and you’ve confirmed it does, at the same speed.
For educators
Section titled “For educators”Discussion question. Which of your services scale on a signal that measures demand (queue depth, requests) instead of their own saturation (CPU, connections in use, latency)? What happens to each when the real bottleneck is elsewhere?
Exercise. Using Design B, the business says rendering for paying customers must stay within 2 minutes; free-tier jobs can wait. 40% of arrivals are paying customers. What do you change?
Worked answer
Split the queue, or prioritize within it, and give paying jobs first claim on the 100 concurrent downstream calls. Paying jobs arrive at 100 a second, well within the 200 the downstream can complete, so they flow with almost no wait. The remaining capacity, about 100 a second, goes to free-tier jobs, which arrive at 150 a second: their queue grows by 50 a second during the peak and drains afterwards. The 2-minute objective is then measured on the paying queue’s oldest-job age. Adding workers still does nothing: the downstream’s 200 a second is the limit for both groups combined.
Further reading
Section titled “Further reading”- Amazon Builders’ Library: Avoiding insurmountable queue backlogs (opens in a new tab).
Related pages
Section titled “Related pages”Written and edited by Abhinav Taduka, enterprise software architect.
New pages are added regularly. Follow Abhinav on LinkedIn to see them first.