---
title: "Scale on the resource that runs out · Agent Wranglers"
url: https://agentwranglers.se/playbook/scaling/load-balancing-and-autoscaling/scale-on-saturation
updated: 2026-10-21
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Scale on the resource that runs out

For AI agents: the [site map](https://agentwranglers.se/llms.txt) lists everything here, and this page sits under [Load balancing and autoscaling](https://agentwranglers.se/playbook/scaling/load-balancing-and-autoscaling.md).

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers). Updated 2026-10-21.

- ID: SCL-30
- Level: Recommended
- Chapter: [Load balancing and autoscaling](https://agentwranglers.se/playbook/scaling/load-balancing-and-autoscaling)
- Rule: Drive autoscaling from the metric that limits each process type, such as CPU, requests in flight per copy or the age of the oldest job. Set a minimum, a maximum and a slow scale-down.
- Applies when: The project runs its own servers, virtual machines or containers.
- How: CPU suits web servers that compute. Workers that wait on other services stay idle on CPU while their queue grows, so scale them on [the age of the oldest waiting job](https://agentwranglers.se/playbook/operations/alerts-and-on-call/queue-age). Set the target so peak load stays within [headroom](https://agentwranglers.se/playbook/operations/capacity-and-cost/headroom). Set the maximum so that the [connection budget](https://agentwranglers.se/playbook/scaling/growing-the-database/connection-budget) holds. Scale up fast and down slowly, or the service shrinks and grows in a loop. By default, Kubernetes waits 300 seconds before it scales down. Keep the minimum at 2 or more copies, spread across zones.
- Check: Run the load test at the planned peak on staging with autoscaling on. New copies start within 3 minutes of the rise, and the 95th percentile stays within its objective. Copies return to the minimum within 15 minutes after the load ends.

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### YAML example

```yaml
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: shop-worker
spec:
  scaleTargetRef: { apiVersion: apps/v1, kind: Deployment, name: shop-worker }
  minReplicas: 2
  maxReplicas: 12
  metrics:
    - type: External
      external:
        metric: { name: queue_oldest_job_age_seconds, selector: { matchLabels: { queue: exports } } }
        target: { type: Value, value: "60" }
  behavior:
    scaleDown:
      stabilizationWindowSeconds: 300
      policies: [{ type: Percent, value: 20, periodSeconds: 60 }]
```

## Sources

- [Kubernetes Horizontal Pod Autoscaling](https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/)
- [AWS Well-Architected, REL07-BP01 Use automation when obtaining or scaling resources](https://docs.aws.amazon.com/wellarchitected/latest/reliability-pillar/rel_adapt_to_changes_autoscale_adapt.html)

## Related rules

- [Run web and worker processes apart](https://agentwranglers.se/playbook/scaling/stateless-app-servers/web-and-worker-processes) in Scaling
- [Alert on the age of the oldest waiting job](https://agentwranglers.se/playbook/operations/alerts-and-on-call/queue-age) in Operations
- [Keep headroom](https://agentwranglers.se/playbook/operations/capacity-and-cost/headroom) in Operations
- [Fit the connection budget to the autoscaling maximum](https://agentwranglers.se/playbook/scaling/growing-the-database/connection-budget) in Scaling

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/scaling/load-balancing-and-autoscaling/scale-on-saturation">Agent Wranglers scaling playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Spread load by requests in flight](https://agentwranglers.se/playbook/scaling/load-balancing-and-autoscaling/least-requests-balancing)
- Next: [Give each customer a fair share](https://agentwranglers.se/playbook/scaling/load-balancing-and-autoscaling/per-tenant-limits)
- [Load balancing and autoscaling](https://agentwranglers.se/playbook/scaling/load-balancing-and-autoscaling)
