Lesson 2 of 18
22. Message Queues

22.1 What are producers and consumers?

3 min read+10 XP

The basics

At the bank: You (the customer) create the work by taking a token. The clerks do the work. You never talk to a specific clerk, and they never need to know who's coming next. The board sits between you.

In the system:

  • A producer sends messages to a queue: "order 881 placed, send the SMS".
  • A consumer (also called a worker) receives messages from the queue, does the work, and acknowledges each one when it's done.
  • The broker is the queue software: Amazon SQS, RabbitMQ, Apache Kafka, Google Pub/Sub, Redis streams and others.
python

The key property is decoupling: the producer doesn't know or care who handles the message, how many workers there are, or whether they're running right now. The queue holds messages until someone is ready.

Memory code: "Leave the job on the board; whoever's free picks it up."