
BullMQ Job Queues: Background Processing in Node.js Done Right
Your API endpoint sends an email, generates a PDF, and resizes an image. Response time: 8 seconds. Users rage-quit. Move heavy work to a background queue. Basic Queue Setup import { Queue , Worker } from " bullmq " ; import IORedis from " ioredis " ; const connection = new IORedis ({ maxRetriesPerRequest : null }); // Producer: add jobs to the queue const emailQueue = new Queue ( " email " , { connection }); await emailQueue . add ( " welcome " , { to : " user@example.com " , subject : " Welcome \ ! " , template : " welcome " }); // Consumer: process jobs const worker = new Worker ( " email " , async ( job ) => { await sendEmail ( job . data ); }, { connection , concurrency : 5 }); worker . on ( " completed " , ( job ) => console . log ( job . id , " done " )); worker . on ( " failed " , ( job , err ) => console . error ( job . id , err . message )); Job Options That Matter await emailQueue . add ( " password-reset " , { to , token }, { priority : 1 , // Lower number = higher priority
Continue reading on Dev.to Tutorial
Opens in a new tab



