Message queue
Play this lessonThis lesson comes with an interactive animation you can break, a live-code challenge and a chapter quiz.A message queue is a durable, in-memory buffer that lets parts of a system talk asynchronously: one side drops work into it, and the other side picks the work up whenever it's ready.
- Producers (publishers) post messages to the queue.
- Consumers (subscribers) connect to the queue and do the work in each message.
The big win is decoupling: the producer can publish even when no consumer is available, and a consumer can read messages even when the producer is offline. Each side can be scaled independently.
Example: photo processing (crop, sharpen, blur…) is slow. Web servers just publish "process photo #42" jobs. Photo-processing workers pick them up. When the queue grows, add workers; when it's empty, remove some.
Key takeaways
- Producers publish, consumers process, at their own pace.
- Queues decouple components and absorb traffic spikes.