Skip to main content
Global concurrency is a queue-level setting that determines the maximum number of jobs that can be processed simultaneously across all worker instances connected to the queue.

Setting Global Concurrency

Use the setGlobalConcurrency method to set a concurrency limit:

Method Signature

concurrency
number
required
Maximum number of simultaneous jobs that all workers can handle. For instance, setting this to 1 ensures that no more than one job is processed at any given time across all workers. If this limit is not defined, there will be no restriction on concurrent jobs.

Example

Getting Global Concurrency

Retrieve the current global concurrency setting:

Removing Global Concurrency

Remove the global concurrency limit, allowing unlimited concurrent jobs:

How It Works

Global concurrency works differently from worker-level concurrency:

Worker-Level Concurrency

Controls how many jobs a single worker can process simultaneously:

Global Concurrency

Controls how many jobs all workers combined can process simultaneously:
Worker-level concurrency does not override global concurrency. The global limit is always respected, even if individual workers could process more jobs.

Practical Examples

Example 1: Rate-Limited API

If your jobs call an external API with strict rate limits:

Example 2: Database Connection Pool

Limit concurrent database operations to match your connection pool size:

Example 3: Resource-Intensive Jobs

Prevent overloading your infrastructure:

Example 4: Dynamic Concurrency

Adjust concurrency based on system load:

Combining Global and Worker Concurrency

When using both global and worker-level concurrency:

Use Cases

When to Use Global Concurrency

  • External API rate limits
  • Database connection pool limits
  • Shared resource constraints (memory, CPU, network)
  • Third-party service quotas
  • License limitations (e.g., max concurrent users)

When NOT to Use Global Concurrency

  • Jobs are completely independent with no shared resources
  • You want maximum throughput
  • Each worker should control its own concurrency

Monitoring

Check the current state: