title: Limit Queue Concurrency to Protect Resources impact: HIGH impactDescription: Prevents resource exhaustion from too many concurrent workflows tags: queue, concurrency, worker, limits, resources
Limit Queue Concurrency to Protect Resources
Concurrency limits cap how many workflows from a queue run at once. Worker concurrency applies per DBOS process and is the recommended control; global concurrency applies across every process sharing the system database.
Incorrect (unlimited concurrency for memory-hungry work):
// Every enqueued workflow starts as soon as a worker polls: memory blows up
dbos.registerQueue("ml-queue", new QueueOptions());
Correct (bounded per-process concurrency):
// Each process runs at most 5 of these workflows at a time
dbos.registerQueue("ml-queue", new QueueOptions().withWorkerConcurrency(5));
// Cap across the whole deployment (use sparingly, see caveat below)
dbos.registerQueue("api-queue", new QueueOptions().withConcurrency(10));
// Both together: at most 10 globally, at most 2 per process
dbos.registerQueue("mixed-queue",
new QueueOptions().withConcurrency(10).withWorkerConcurrency(2));
In-order processing (sequential):
// Only one workflow at a time across all processes - guarantees order
dbos.registerQueue("sequential-queue", new QueueOptions().withConcurrency(1));
void onEvent(String event) {
dbos.startWorkflow(() -> proxy.processEvent(event),
new StartWorkflowOptions().withQueue("sequential-queue"));
}
Choosing a limit:
workerConcurrency— maximum concurrent workflows from this queue in a single process. Use it for CPU- or memory-intensive work so no process is overwhelmed; total throughput scales with the number of processes.concurrency— maximum concurrent workflows from this queue across all processes. Use it to protect a shared downstream resource such as a database connection pool or a licensed service.
Caveat for global concurrency: every PENDING workflow on the queue counts toward the limit, including workflows
left behind by earlier application versions. A stuck workflow therefore consumes a slot until it is cancelled or
resumed.
When using worker concurrency, each process must have a unique executor ID (DBOSConfig.withExecutorId); this is
automatic with DBOS Conductor or Cloud.
Limits can be changed at runtime without redeploying, with dbos.updateQueue(name, options); workers pick
up the new configuration on their next polling iteration (queue-management.md).
To rate-limit starts rather than cap in-flight work, use a rate limit (queue-rate-limiting.md). To apply limits per tenant or user, set a per-partition limit, which can sit alongside the queue-wide limits on the same queue (queue-partitioning.md).
Reference: Managing Concurrency