Message Queues Explained: What They Are and When to Use One
When you place an order, the confirmation page appears instantly and the email arrives a moment later. That gap is a message queue at work: the shop saved your order, put “send the receipt” in a queue, and answered you without waiting for the email to go out.
System design · 2026-11-25 · 7 min read
What is a message queue?
A message queue is a waiting line for jobs. One part of a system (the producer) drops a message in, like “send receipt for order 812”, and carries on. Another part (the consumer, or worker) takes messages out and does the work when it can. The queue holds messages safely in between.
That simple gap gives you three things: users don’t wait for slow work, a slow or broken service doesn’t break the request, and you can absorb spikes by letting the queue grow for a while.
When to use one
- The work is slow: sending email, resizing images, generating PDFs or reports.
- The work depends on another service that can be slow or down, such as a payment partner or a CRM.
- Traffic comes in bursts and the work can catch up a little later.
- Several systems need to react to the same event (an order placed → email, warehouse, analytics).
Don’t use a queue when the user needs the result right now, such as checking a password or showing search results.
Workers: scaling the work
When jobs arrive faster than one worker can handle them, the queue grows. The fix is to run more identical workers on the same queue (competing consumers): each message goes to exactly one worker, so two workers empty the queue about twice as fast. Many teams autoscale workers on queue length.
Retries and dead-letter queues
If a worker fails on a job, the message returns to the queue and is tried again, which fixes short glitches like a service blip. But some jobs will never succeed, for example an invalid email address. Without a limit, that poison message crashes workers forever and blocks the jobs behind it.
The fix is a dead-letter queue: after a set number of failures (say 3), the message is moved aside. Everything else keeps flowing, and someone inspects and replays the failed messages later.
At-least-once delivery and idempotency
Most queues guarantee at-least-once delivery: a message is never lost, but it can occasionally arrive twice, for example if a worker finished the job but crashed before confirming it. So make jobs idempotent: safe to run twice. Record a unique ID per job and skip ones already done.
Lesson: webhooks, retries and idempotency →
SQS, RabbitMQ or Kafka?
| Tool | Best for | Notes |
|---|---|---|
| Amazon SQS | Simple job queues on AWS | Fully managed, built-in dead-letter queues, no servers to run |
| RabbitMQ | Flexible routing between services | Rich routing rules; you run it (or use a hosted version) |
| Apache Kafka | Event streams many systems read | Keeps messages for days, can replay them, very high throughput |
For “do this job later”, a simple queue like SQS is usually enough. Reach for Kafka when many services need to read the same stream of events, or replay history.
See it happen
In the interactive lesson a web shop hits Black Friday. Checkout freezes, the queue overflows, and a poison message stalls everything. You pick the fix each time and watch what it does on a live diagram.
Play: message queues, step by step →
Frequently asked questions
What is a message queue in simple terms?
A waiting line for jobs. One part of a system adds a job and moves on; another part picks it up and does it later. It keeps slow or unreliable work away from users.
What is the difference between a queue and Kafka?
A classic queue hands each message to one worker and deletes it when done. Kafka keeps an ordered log of events that many consumers can read independently and replay.
What happens if a worker crashes?
The message wasn’t confirmed, so after a short timeout the queue makes it visible again and another worker takes it. That is why jobs should be safe to run twice.
What is a dead-letter queue?
A side queue for messages that failed a set number of times, so they stop blocking other work and can be inspected and replayed later.