Use cases
- Limit how many runs of a task execute at once: Setting task concurrency
- Share one limit across several tasks: Sharing a limit between tasks
- Give each tenant its own separate concurrency: Concurrency keys and per-tenant limits
- Per-tenant limits with a ceiling on the total: Per-key and total limits together
- Cap a tenant across every task they run: A per-tenant cap across multiple tasks
- Cap a shared resource, like an external API, across tasks and tenants: A global cap for a shared resource
- Switch a run’s limits when you trigger it: Setting limits when you trigger a run
Default concurrency
By default, all tasks have an unbounded concurrency limit, limited only by the overall concurrency limits of your environment.Your environment has a base concurrency limit and a burstable limit (default burst factor of 2.0x
the base limit). Individual tasks and limits are capped by the base concurrency limit, not the
burstable limit. For example, if your base limit is 10, your environment can burst up to 20
concurrent runs, but any single limit can allow at most 10 concurrent runs. If you’re a paying
customer you can request higher burst limits by contacting us.
Setting task concurrency
Set theconcurrency option on a task to limit how many of its runs execute at once. { total: n } caps the task outright:
/trigger/one-at-a-time.ts
totalcaps every run of the task together, whether or not runs use aconcurrencyKey.perKeycaps eachconcurrencyKeypool separately; runs triggered without a key share one pool.
/trigger/per-user.ts
The
queue: {"{ concurrencyLimit: n }"} option keeps working but is deprecated in favor of
concurrency. Its single number means “per key when runs pass a concurrencyKey, whole queue
when they don’t” — the concurrency shape says which you mean explicitly.Sharing a limit between tasks
Declare a named limit withconcurrencyLimit() and put it in each task’s concurrency. Every task holding the limit draws from the same pools:
/trigger/limits.ts
concurrency takes a single item or an array: at most one inline shape (which caps that task alone) plus up to two named limits. A run starts only when every limit it holds has capacity, and it occupies a slot in each while it executes:
/trigger/summarize.ts
Names you declare with
concurrencyLimit() are 1-122 characters using only letters, numbers,
underscores and hyphens.Setting limits when you trigger a run
The trigger-timeconcurrency option takes limit names and replaces the task’s declared named limits for that run. The task’s inline limit always applies:
app/api/report/route.ts
Concurrency keys and per-tenant limits
If you’re building an application where you want to run tasks for your users, you might want a separate limit for each of your users (or orgs, projects, etc.). You can do this by passing aconcurrencyKey when you trigger. Each unique key value gets its own pool under every perKey bound the run holds:
app/api/report/route.ts
Per-key and total limits together
perKey on its own lets total concurrency grow with the number of active keys: ten active users under perKey: 5 can run 50 at once. Add total to bound everything as a group. Each key still gets at most perKey, and all runs together — keyed or not — never exceed total:
/trigger/per-user-capped.ts
A per-tenant cap across multiple tasks
A named limit’sperKey bound follows each run’s own concurrencyKey, so one declaration caps each tenant across every task holding the limit:
/trigger/webhooks.ts
app/api/webhook/route.ts
A global cap for a shared resource
To cap something global, like total traffic to an external API, across many tasks and all tenants: declare a limit with only atotal and share it. It counts every run holding it, whether or not the run has a concurrencyKey:
/trigger/sync.ts
concurrencyKey share the same total, so this works even when only some of your triggers have a natural key.
Concurrency and subtasks
When you trigger a task that has subtasks, the subtasks will not inherit the parent’s limits. Unless otherwise specified, subtasks run under their own task’s configuration:/trigger/subtasks.ts
Waits and concurrency
With our task checkpoint system, tasks can wait at various waitpoints (like waiting for subtasks to complete, delays, or external events). The way this system interacts with the concurrency system is important to understand. Concurrency is only released when a run reaches a waitpoint and is checkpointed. When a run is checkpointed, it transitions to theWAITING state and releases its concurrency slots back to every limit it holds and the environment, allowing other runs to execute or resume.
This means that:
- Only actively executing runs count towards concurrency limits
- Runs in the
WAITINGstate (checkpointed at waitpoints) do not consume concurrency slots - You can have more runs in the
WAITINGstate than a limit allows to execute - When a waiting run resumes (e.g., when a subtask completes), it must re-acquire its slots
concurrency: { total: 1 }:
- You can only have exactly 1 run executing at a time
- You may have multiple runs in the
WAITINGstate for that task - When the executing run reaches a waitpoint and checkpoints, it releases its slot
- The next queued run can then begin execution
Short time-based waits keep their slot
Checkpointing takes time, so a run doesn’t checkpoint the moment it reaches a waitpoint. Forwait.for() and wait.until() it happens 60 seconds into the wait, so anything shorter stays EXECUTING and holds its slots for the whole wait. If you’re polling in a loop, use an interval comfortably above 60 seconds so the slots are actually released between polls.
Waiting for a subtask
When a parent task triggers and waits for a subtask, the parent task will checkpoint and release its concurrency slots once it reaches the wait point. This prevents environment deadlocks where all concurrency slots would be occupied by waiting tasks./trigger/waiting.ts
triggerAndWait call, it checkpoints and transitions to the WAITING state, releasing its slots. Once the subtask completes, the parent task will resume and re-acquire them.
Managing concurrency limits with the SDK
TheconcurrencyLimits namespace manages your named limits at runtime (anonymous inline limits appear under derived task/<task-id> names):
Listing limits
Retrieving a limit
Retrieve a limit by its name to see its bounds and live counts:Overriding a limit
Overrides change only the fields you pass; the declared values are kept and restored byreset:
Pausing a limit
Pause a limit to stop every run holding it from being dequeued; runs that are already executing continue to completion. The configured bounds are kept, and resuming restores them:total to 0 also blocks every run holding the limit, but pause is the first-class way to do this and leaves your configured bounds untouched.
