What is a message queue and why is it used in Node.js applications?
Why Interviewers Ask This
This question targets practical, hands-on experience with Node.js. Interviewers want to see if you've worked with these concepts in real projects, not just read about them. Strong answers include concrete examples.
Answer
A message queue is a communication mechanism where producers add messages to a queue and consumers process them asynchronously, decoupling the sender from the receiver in time and space. Benefits: (1) Async processing — handle heavy work (email sending, PDF generation, payment processing) in background workers without blocking the HTTP request; (2) Reliability — if a worker fails, the message stays in the queue for retry; (3) Load leveling — absorb traffic spikes by queuing excess work; (4) Decoupling — services don't need to know about each other directly. Node.js solutions: BullMQ (Redis-based, most popular for Node.js — reliable, feature-rich with delayed jobs, priority, repeatable jobs); RabbitMQ with amqplib (AMQP protocol, advanced routing); Apache Kafka with kafkajs (high-throughput event streaming). Example: user registers → API immediately returns 200 → background job sends welcome email. This prevents slow email sending from delaying the API response.
Pro Tip
Demonstrate both theoretical understanding and practical experience. Say what it is, then give an example of how you actually used it in a Node.js codebase.
Previous
What is the difference between monolithic and microservices architecture in Node.js?
Next
What is Prisma and how is it used in Node.js?