Skip to content
BytePatterns

Message Queues

System Design: lesson 11 of 15

Hand off the work instead of waiting for it.

Lesson 11 of 15 · 5 min

Message Queues

Step 1 of 12

A queue sits between the side that makes work and the side that does it.

The Idea

A queue sits between a producer and a consumer. The producer writes a message and returns immediately; workers pull messages when they have capacity. Bursts pile up in the queue instead of timing out, and the two sides can be deployed, scaled and restarted independently of each other.

Real-World Example

A hospital lab. The ward drops a barcoded sample into the intake fridge and the nurse walks back to the ward; analysers take samples as machines free up. When the fridge fills, the backlog is visible to everyone, and nobody spent their morning standing beside a centrifuge.

The Tradeoff

You have added a component that can back up, lose ordering across parallel consumers, and deliver the same message twice — so consumers must be idempotent and failures need a dead-letter queue. If the caller genuinely needs the answer now, a queue only hides the waiting somewhere less visible.

Your turn

Put the steps in the right order.

  1. A worker pulls the message once it has spare capacity
  2. The producer publishes a message and returns to its caller
  3. The message is acknowledged and removed from the queue
  4. Repeated failures move the message to a dead-letter queue

Mini quiz

1 / 3

A queue's main gift to the producer is: