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.Custom ID Restrictions
Fromsrc/classes/job.ts:1582:
Duplicate Detection
When you attempt to add a job with an existing ID, BullMQ will:- Check if the ID already exists
- Ignore the new job
- Emit a
duplicatedevent via QueueEvents
Job Options Interface
Fromsrc/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
