Message queue
Also called job queue, task queue.
A buffer that holds messages, such as tasks or events, until a worker is ready to process them, so the sender does not have to wait.
Last updated
What it is.
A producer puts a message on the queue, for example send this email or resize this image. One or more workers take messages off, do the work and confirm. If a worker fails, the message goes back on the queue or to a dead letter queue for review.
Queues are the plumbing behind event-driven architecture, background jobs and smoothing spikes: the queue grows during a rush and drains afterwards.
Why it matters
Slow or unreliable work, such as calling third-party APIs, generating reports or running AI tasks, should not make users wait or fail their request. A queue moves it to the background and retries it safely, and workers can scale on queue length.
In a product build
We use a managed queue, make every worker idempotent because messages can be delivered more than once, set retry limits with backoff, send poison messages to a dead letter queue and alert on queue age, not just length.
Common mistakes.
- 01
Assuming each message is delivered exactly once.
- 02
Retrying forever, so one bad message blocks the queue.
- 03
No alert when the queue backs up, so users wait hours before anyone notices.
Work it out with a tool.
Related terms.
- Event-driven architectureA way of designing software where parts of the system publish events about what happened, and other parts react to them on their own.
- IdempotencyThe property of an operation that has the same effect whether it runs once or several times, so it is safe to retry.
- WebhookAn HTTP request one system sends to a URL you choose as soon as an event happens, so you do not have to keep asking.
- AutoscalingAutomatically adding or removing computing capacity, such as servers or containers, as the load on a system goes up or down.
- Rate limitingCapping how many requests a user, API key or address can make in a given time, to protect a system and share capacity fairly.