What is a message queue and why is it used in system design?
Why Interviewers Ask This
Interviewers use this question to quickly assess whether a candidate has the foundational knowledge required for System Design development. It reveals whether you understand the building blocks that more complex concepts rely on.
Answer
A message queue is an asynchronous communication mechanism where producers publish messages to a queue, and consumers process them independently, decoupling the two in time. Core benefits: (1) Decoupling: producers don't know about consumers — add consumers without changing producers; (2) Async processing: accept user requests immediately, process heavy work in background — faster perceived response time; (3) Load leveling: absorb traffic spikes — if 10,000 orders arrive in one second, the queue buffers them and workers process at their natural rate; (4) Reliability: messages persist until consumed — if a worker crashes, the message is redelivered; (5) Fan-out: one message can be consumed by multiple services simultaneously (pub-sub). Use cases: email/notification sending, video transcoding, order processing, image resizing, payment processing, logging pipelines, real-time analytics. Message queue systems: RabbitMQ: AMQP protocol, flexible routing (exchanges and queues), good for task queues; Apache Kafka: distributed log, very high throughput, message retention (consumers can re-read), event streaming; AWS SQS: managed, simple, at-least-once delivery; Redis (BullMQ): lightweight queue on Redis; Google Cloud Pub/Sub. Delivery guarantees: at-most-once (may lose), at-least-once (may duplicate — consumers must be idempotent), exactly-once (harder, requires transactional producers/consumers).
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 System Design codebase.