Articles
NestJSBullMQRedisArchitectureOct 2025 · 6 min read

High-throughput Job Queues with BullMQ & Redis in NestJS

How to design fault-tolerant asynchronous worker queues for bulk PDF processing, email dispatch, and idempotency in NestJS.

When building scalable backend systems, long-running operations like document generation and notifications should never block incoming HTTP requests. Using BullMQ with Redis provides robust distributed queue management in NestJS.

1. Setting up BullMQ Processor in NestJS

NestJS provides first-class support for BullMQ via @nestjs/bullmq. Workers consume jobs from a Redis instance and support concurrency limits, job retries, and backoff strategies.

typescriptsnippet
@Processor('invoice-generation')
export class InvoiceProcessor extends WorkerHost {
  @Process()
  async handleGeneration(job: Job<{ invoiceId: string; template: string }>) {
    const { invoiceId, template } = job.data;
    // Generate PDF asynchronously via Puppeteer
    const pdfBuffer = await this.pdfService.render(template);
    await this.s3Service.uploadInvoice(invoiceId, pdfBuffer);
    return { success: true, invoiceId };
  }
}

2. Ensuring Idempotency & Avoiding Duplicate Jobs

By passing a deterministic jobId based on invoice number or timestamp hash, BullMQ guarantees that duplicate webhook events or retry calls will not enqueue duplicate jobs.