AI Hints
Home›System Design Tutorial›Async and Queues
System Design · Lesson 65 of 120

Message Queues

A to-do list for servers.

⏱ 2 min read▶ Video at 1:17:43🎓 Free
Watch this lesson in the System Design courseWatch on YouTube ↗Full System Design course

A message queue is a to do list that servers share. One part of the system adds jobs to the list. Other parts take jobs off, and do them, at their own pace.

Message Queues
From the video: Message Queues
  • A shared to-do list
  • Producers add jobs
  • Consumers do them

Producer, queue, consumer

The checkout service is the producer. It puts a message on the queue, like send receipt for order seven. The queue stores it safely. A worker, the consumer, takes the message, sends the email, and confirms it's done. Only then does the queue delete the message.

  1. Producer
  2. Queue stores
  3. Consumer takes
  4. Does the work
  5. Acknowledges
Producer, queue, consumer
From the video: Producer, queue, consumer

Why queues help

Queues give us a lot. The producer and consumer don't need to be up at the same time. Bursts of work are smoothed out, because the queue just gets longer for a while. We can add more workers to go faster. And if a worker crashes, its message goes back on the queue, for someone else.

Decouplednot up at the same time
Smooths burststhe queue absorbs them
Scale workersadd more consumers
Retry on crashmessage returns

Summary

A message queue lets producers hand off work, and consumers process it at their own pace. Popular queues include RabbitMQ and Amazon SQS. Next, sending one message to many listeners.

Key takeaways
  • Producers add
  • Consumers take
  • Acknowledge when done
Next up: Pub/Sub — one message, many listeners