Why put a queue between a producer and a consumer instead of calling the consumer directly?
Sketch your own answer first, then compare it with the one below.
A strong answer
A queue decouples the two in time and in speed. The producer hands over the message and moves on. The consumer takes it when it is ready. Bursts that would overwhelm a direct call turn into a short wait.
It also lets the two sides fail and scale on their own. A consumer that is down for a minute does not stop the producer, as long as the queue has room.
The cost is delay, one more component to run, and a decision about what happens when the queue is full. Keep one limit in mind: a queue smooths bursts, and it never creates capacity.
Sources
- Martin Kleppmann (2017). Designing Data-Intensive Applications.
- Mor Harchol-Balter (2013). Performance Modeling and Design of Computer Systems.