What Is a Message Queue?
A message queue is a component that holds messages from producers until consumers are ready to process them, so services can communicate asynchronously. The sender does not wait for the receiver, which smooths traffic spikes and lets each side fail or scale independently.
How Message Queue Works
When a user uploads a video, don't process it in the request. Send a message to a queue: {userId, videoUrl, format}. A worker service picks up the message, transcodes the video, and updates the status. The user gets an instant response while processing happens in the background.
Kafka handles event streaming at massive scale — LinkedIn processes 7 trillion messages/day through Kafka. RabbitMQ is simpler for task queues. Amazon SQS is fully managed with zero infrastructure.
Why Developers Use Message Queue
Message queues are essential for microservices, background job processing, and handling traffic spikes. If your web request takes longer than 500ms, consider moving the slow part to a queue.
Key Concepts
- Producer/Consumer — Producers add messages to the queue; consumers pull and process them independently
- At-Least-Once Delivery — Guarantees every message is processed at least once — consumers must handle duplicates
- Dead Letter Queue — Messages that fail processing repeatedly are moved here for investigation
- Backpressure — When consumers can't keep up, messages queue up — the queue absorbs traffic spikes
Frequently Asked Questions
What is a message queue used for?
Message queues are used for background jobs such as sending email or resizing images, for buffering bursts of traffic, and for passing events between microservices. Common choices are RabbitMQ, Amazon SQS, Redis-based queues and Apache Kafka, which is technically a distributed log rather than a classic queue.
Kafka vs RabbitMQ?
Kafka for high-throughput event streaming and log aggregation. RabbitMQ for traditional task queues and request-reply patterns. Kafka retains messages; RabbitMQ deletes after consumption.
When do I need a message queue?
When operations are slow (video processing, email sending), when services need decoupling, or when you need to handle traffic spikes without dropping requests.