How do you implement async processing in Node with a message queue?

Topic: microservices, Node Side. Level: Intermediate.

Answer

Offload slow/side-effect work to a broker so the request returns fast. With Redis-backed **BullMQ** you enqueue a job and a separate worker process consumes it with retries, backoff, and a dead-letter equivalent (failed set). For event streaming use **KafkaJS** with consumer groups. Keep handlers idempotent since delivery is at-least-once. ```js import { Queue, Worker } from 'bullmq' const emails = new Queue('emails', { connection }) // producer: return immediately, process later await emails.add('welcome', { userId }, { attempts: 5, backoff: { type: 'exponential', delay: 1000 }, }) // worker: separate process, retried with backoff, idempotent new Worker('emails', async job => { if (await alreadySent(job.data.userId)) return // dedupe await sendWelcome(job.data.userId) }, { connection }) ```