When many triggers fire at once, the runs they start can pile up: each one calls the same tools, hits the same rate limits, and competes for the same budget. A queue with a concurrency limit fixes that: incoming runs wait in line, and only a set number run at the same time. The rest start when a slot frees up. Pick the limit from what the tools and the budget can actually handle, not from a guess, and decide what happens to a run that waits too long: it runs late, or it is dropped with a message. A queue with no limit is just a pile; a limit with no queue is just a refusal.
What you need
- A trigger that can fire many times at once, such as a webhook or a schedule
- A concurrency limit based on what the tools and budget can handle
- A named outcome for a run that waits too long: run late, or drop with a message
Step 1: Set the concurrency limit from what the tools can handle
Choose the number of runs that may execute at once, based on the tools’ rate limits and the budget. A limit higher than the tools can serve just moves the failure into the tools.
Step 2: Queue the runs that arrive over the limit
When a run arrives and all slots are busy, put it in the queue in arrival order instead of starting it. A run that is refused outright is lost work; a queued run is delayed work.
Step 3: Test by firing ten triggers at once
Fire ten triggers at the same time and confirm only the limited number run together, the rest wait in order, and every run eventually starts or is dropped with a message.
Worked example: synthetic run queue check
The table below is a synthetic example. It shows the expected result of the run queue; no runs were started.
| Check | Expected | Result |
|---|---|---|
| 10 triggers fire at once | 3 run, 7 queue | Pass |
| Queued runs start in order | Yes | Pass |
| No run is lost silently | Yes | Pass |
| Rate limits not hit | Yes | Pass |
Expected result (UNTESTED). three runs execute at once, seven wait in arrival order, and every run starts or is dropped with a message. This check was not run live; the table shows the expected result for the synthetic example.
Limits
- A queue that grows without bound is a backlog, so set a maximum wait and a drop policy.
- Queued runs can go stale: check the input is still valid when the run finally starts.
- A limit set too low wastes capacity; a limit set too high wastes the tools.
- First-in-first-out is fair, but urgent runs may need a priority lane.
