What is a Message Queue?
A message queue, told as a story about a snack counter that stacks order slips in a basket instead of handing them straight over.
Orders pile up all at once and the clerk can't keep up.Too many at once!
Why: if the sender must wait while the receiver is busy, both slow down.The sender and receiver get tied to each other's pace.
Put orders in a basket, and sender and receiver each move at their own pace.The sender moves to the next guest; the receiver works at its own speed.
Order placer → queued orders → one-at-a-time picker.A basket sits between the sender and the receiver.
Too long delays old orders, and dropping one loses it forever.Length is handled with backpressure; drops with a dead-letter queue.
A message queue: instead of handing orders straight over, they're stacked in a basket so the sender and receiver can each move at their own pace.
The sender side is called the producer, the receiver the consumer. Multiple consumers can watch the same basket (pub/sub), and items usually come out in the order they went in. Adding more consumers empties the basket faster.
When grown-ups say it
- Message Queue
- The basket that holds the order slips. It keeps the sender and receiver from having to wait on each other.
- Asynchronous Processing
- Sending something without waiting right away for a reply. Possible because the basket sits in between.
- Producer / Consumer
- The one who puts orders in, and the one who takes them out. They don't need to know each other — just share the same basket.
- Queue Length
- How many order slips are piled in the basket. Too long, and old orders get handled too late.
- Pub/Sub
- Several people watching the same basket together. Also called publish-subscribe.
- Ordering Guarantee
- The promise that things come out in the order they went in. Not every queue promises this.
- Backpressure
- Holding the entrance shut for a moment before the basket gets too long. → briefly closing the entrance
- Dead-letter Queue
- A separate box for order slips that keep failing to be handled. → the basket nobody came to claim