Skip to main content

Overview

Deduplication in BullMQ delays and deduplicates job execution based on specific identifiers. Within a specified period, or until a job completes or fails, no new jobs with the same identifier will be added to the queue. Instead, these attempts trigger a deduplicated event. From src/classes/job.ts:160:

Simple Mode

Simple Mode extends deduplication until the job’s completion or failure. While a job remains incomplete, subsequent jobs with the same deduplication ID are ignored.
While this job is not in completed or failed state, subsequent jobs with the same deduplication ID will be ignored, and a deduplicated event will be emitted.
Simple Mode is useful for long-running jobs or critical updates that must not be duplicated until resolved, such as processing a file upload.

Throttle Mode

Throttle Mode assigns a TTL (Time to Live) to a job. If a similar job is added during this TTL period, it’s ignored, preventing queue overload.
After adding this job, any subsequent job with the same deduplication ID customValue added within 5 seconds will be ignored. From src/types/deduplication-options.ts:
Throttle Mode is useful for scenarios with rapid, repetitive requests, such as multiple users triggering the same job.

Debounce Mode

Debounce Mode delays a job and replaces it with newer versions during the delay period. Only the most recent job is kept and processed.
With debounce mode:
  • Each new job with the same deduplication ID replaces the previous job
  • The TTL is reset with each addition
  • Only the last job data is processed
Debounce Mode is useful when you need the latest data, such as saving user input where only the final state matters.
You must provide a deduplication ID that represents your job. You can hash your entire job data or a subset of attributes to create this identifier.
Manual deletion (e.g., calling job.remove()) will disable the deduplication.

The Deduplicated Event

The deduplicated event is emitted whenever a job is deduplicated (ignored or replaced) in any mode.
Event parameters:
  • jobId: The ID of the job retained in the queue
  • deduplicationId: The deduplication ID that caused the deduplication
  • deduplicatedJobId: The ID of the job that was deduplicated (ignored or replaced)

Get Deduplication Job Id

Retrieve the ID of the job that started the deduplicated state:

Remove Deduplication Key

Stop deduplication before TTL finishes or before a job completes:

Remove by Queue

Remove by Job

Only removes if this specific job caused the deduplication:
From src/classes/job.ts:1538:

Validation

From src/classes/job.ts:1607:
The deduplication ID is required when using deduplication options.

Comparison Table

Use Cases

Prevent duplicate password reset emails:
Prevent API spam by throttling requests:
Save only the final state of user edits:

Read More

Add Job API

View the Add Job API Reference

Queue Remove Key

Queue.removeDeduplicationKey API

Job Remove Key

Job.removeDeduplicationKey API

Deduplication Patterns

Deduplication Patterns Guide