Message queue
In short: A message queue accepts messages from one program and passes them on to another later. That way neither has to run at the same time or at the same speed.
In more detail: The sender (producer) puts a task into the queue, a receiver (consumer) processes it. If the receiver fails or is overloaded, the messages are kept. Examples: RabbitMQ, Apache Kafka, Amazon SQS, Redis Streams.
In Depth
- Decoupling: The web server answers immediately; heavy work (sending mail, shrinking images) is done by a worker in the background.
- Retry: If a task fails, it is tried again. Tasks should therefore be idempotent (idempotence).
- Dead-letter queue: collects messages that keep failing.
- Pub/sub: One message goes to many subscribers.
- Order and duplicates: Not every system guarantees both. This must be taken into account.
See also: Microservices, Webhooks