Skip to main content

Overview

All jobs in BullMQ need a unique job ID. This ID is used to construct a key for storing data in Redis and serves as a pointer to the job as it moves between different states during its lifetime.
The uniqueness requirement is scoped by queue. You can have the same job ID in different queues without issues. The counter for automatically generated IDs is also scoped by queue.

Automatic IDs

By default, job IDs are generated automatically as an increasing counter:

Custom IDs

The main reason to specify a custom ID is to avoid duplicated jobs. Since IDs must be unique, adding a job with an existing ID will be ignored and not added to the queue.
Jobs removed from the queue (either manually or via removeOnComplete/removeOnFail) will not be considered duplicates. You can add the same job ID many times as long as the previous job has been removed.

Custom ID Restrictions

From src/classes/job.ts:1582:
Custom job IDs must not:
  • Be pure integers (e.g., “123” is invalid, but “job-123” is valid)
  • Contain the : separator (as it conflicts with Redis naming conventions)
Use different separators like - or _ instead.

Duplicate Detection

When you attempt to add a job with an existing ID, BullMQ will:
  1. Check if the ID already exists
  2. Ignore the new job
  3. Emit a duplicated event via QueueEvents

Job Options Interface

From src/interfaces/base-job-options.ts:98:

Use Cases

Custom job IDs are useful for:
  • Preventing duplicate submissions: Use user ID + action as the job ID
  • Idempotent operations: Ensure an operation runs only once
  • Job tracking: Use meaningful IDs that correspond to your business logic

API Reference

View the Duplicated Event API Reference