Menu

Retrying background jobs safely with BullMQ and Redis
📰

Retrying background jobs safely with BullMQ and Redis

DEV Community: redis·Deepak Chauhan·about 6 hours ago
#NI7M6oR0
#devtoredis#devto#dev#worker#bullmq
Long article (665 words) — no AI summary yet.
Reading 0:00
15s threshold

A worker generates a report and saves it to the database. It then crashes before BullMQ records the job as complete. A second worker may process the job again. How do you guarantee at-most-once output under at-least-once delivery?

Key Takeaway: Pair a deterministic BullMQ jobId in Redis with a UNIQUE database constraint and INSERT ... ON CONFLICT DO NOTHING in PostgreSQL. Queue deduplication stops overlapping enqueues while active, and the database constraint prevents duplicates after job retention expires or a worker crashes mid-ack.

Enforce the request ID at both the queue and database boundaries

Assign a stable requestId when the HTTP API accepts work.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.