Decoupling producers and consumers
A message queue is a buffer between a producer that creates work and a consumer that processes it. Instead of calling the consumer directly, the producer drops a message onto the queue and moves on. Consumers pull messages when they are ready.
This buys you three things:
- Decoupling so producers and consumers can deploy and scale independently.
- Smoothing of bursts, since the queue absorbs spikes the consumer drains over time.
- Reliability because a message survives until it is acknowledged.
Delivery and acknowledgement
After processing, a consumer sends an acknowledgement so the queue can delete the message. If the consumer crashes first, the message becomes visible again and another worker retries it.
This gives at least once delivery, which means a message may be processed more than once, so consumers should be designed to handle duplicates safely.
Messages that repeatedly fail are moved to a dead letter queue for later inspection rather than blocking the line forever.
Key idea
A queue absorbs bursts and survives crashes by holding work until a consumer acknowledges it.