Back to results for “SQL/Sequelize)”
Node.js › Background Jobs & Queues

What is job de-duplication in a queue system, and how would you prevent the same logical job from being enqueued multiple times?

Advanced

Answer

Job de-duplication prevents redundant, functionally identical jobs from being processed multiple times when they're enqueued more than once -- for example, if a webhook fires twice for the same event due to a retry from the sender. This is typically implemented by assigning each job a deterministic, unique identifier (like a hash of its relevant input data, or an externally provided idempotency key) and having the queue reject or ignore an add() call for a job ID that already exists and hasn't yet completed.
// BullMQ: using jobId to naturally deduplicate
await webhookQueue.add('process-webhook', payload, {
  jobId: `webhook-${payload.eventId}`, // adding the same eventId again is a no-op if still pending
});
Real-world example A webhook-processing service receives duplicate delivery attempts from a flaky third-party provider for the same event, but because each job is added with a jobId derived from the provider's unique event ID, BullMQ automatically ignores the duplicate enqueue attempt rather than processing the same webhook payload twice.

Common follow-ups: What happens if a duplicate job is enqueued after the original with the same ID has already completed, rather than while still pending?;How does this queue-level deduplication relate to and differ from job idempotency handled inside the job handler itself?