---
title: "Bound the backlog and push back on · Agent Wranglers"
url: https://agentwranglers.se/playbook/scaling/background-jobs-and-queues/bounded-backlog
updated: 2026-10-21
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Bound the backlog and push back on producers

For AI agents: the [site map](https://agentwranglers.se/llms.txt) lists everything here, and this page sits under [Background jobs and queues](https://agentwranglers.se/playbook/scaling/background-jobs-and-queues.md).

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

- ID: SCL-19
- Level: Required
- Chapter: [Background jobs and queues](https://agentwranglers.se/playbook/scaling/background-jobs-and-queues)
- Rule: Set a maximum backlog for every queue, as a count or an age. When it is reached, slow or refuse new work instead of letting the backlog grow without end.
- Risk: The app down or unusable
- How: A backlog that grows for hours fills the queue server's memory and delivers work nobody wants any more, such as an expired reset link. Set the limit from the delay users accept, which [Alert on the age of the oldest waiting job](https://agentwranglers.se/playbook/operations/alerts-and-on-call/queue-age) measures. When full, answer the producer with 503 and `Retry-After`, as [Turn work away before overload](https://agentwranglers.se/playbook/operations/capacity-and-cost/load-shedding) does. Or drop work that has lost its value, and count it in the metrics. AWS lists long backlogs and missing queue age metrics as anti-patterns. Queues inside a process follow [Cap every collection that grows with use](https://agentwranglers.se/playbook/architecture/errors-and-nulls/bounded-collections).
- Check: Stop the workers on staging and add jobs past the limit. New jobs are refused or slowed with a logged reason, and the queue server's memory stays below its limit. Every queue has a written maximum backlog.

## 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.

### JavaScript example

```js
const MAX_WAITING = 50_000;

export async function enqueueExport(queue, data) {
  if (await queue.getWaitingCount() >= MAX_WAITING) {
    throw new ServiceBusyError('export queue full', { retryAfterSeconds: 60 });
  }
  return queue.add('export', data);
}
```

### Python example

```python
MAX_WAITING = 50_000

def enqueue_export(queue, data):
    if queue.count >= MAX_WAITING:
        raise ServiceBusy("export queue full", retry_after_seconds=60)
    return queue.enqueue(run_export, data)
```

## Sources

- [AWS Well-Architected, REL05-BP04 Fail fast and limit queues](https://docs.aws.amazon.com/wellarchitected/latest/reliability-pillar/rel_mitigate_interaction_failure_fail_fast.html)
- [Google SRE book, Addressing Cascading Failures](https://sre.google/sre-book/addressing-cascading-failures/)

## Related rules

- [Alert on the age of the oldest waiting job](https://agentwranglers.se/playbook/operations/alerts-and-on-call/queue-age) in Operations
- [Turn work away before overload](https://agentwranglers.se/playbook/operations/capacity-and-cost/load-shedding) in Operations
- [Cap every collection that grows with use](https://agentwranglers.se/playbook/architecture/errors-and-nulls/bounded-collections) in Architecture

**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/background-jobs-and-queues/bounded-backlog">Agent Wranglers scaling playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Give every job a time limit](https://agentwranglers.se/playbook/scaling/background-jobs-and-queues/job-time-limits)
- Next: [Keep urgent jobs in their own queue](https://agentwranglers.se/playbook/scaling/background-jobs-and-queues/urgent-queue)
- [Background jobs and queues](https://agentwranglers.se/playbook/scaling/background-jobs-and-queues)
