Problem
A single consumer cannot keep up with bursts of messages, and one slow message blocks everything behind it. Scaling by running more consumers risks double processing unless the queue arbitrates.
Also known as: work queue, worker pool
Scale message processing by letting multiple consumers pull from the same queue so each message is handled by exactly one of them.
A single consumer cannot keep up with bursts of messages, and one slow message blocks everything behind it. Scaling by running more consumers risks double processing unless the queue arbitrates.
Competing consumers is the classic work-queue pattern. Many identical workers compete for messages on one queue, and the broker guarantees each message goes to a single worker at a time.
It turns a throughput problem into a deployment problem: add workers until the backlog drains.
It pairs naturally with autoscaling. Queue depth shows how much work waits, but the age of the oldest message shows whether you are meeting your latency target, so scale on both. Keep consumers stateless so any instance can take any message and instances can be replaced freely during deploys.
A worker receives a message, which becomes invisible to others for a lease period. On success it acknowledges; on crash or timeout the lease lapses and the message reappears.
queue --> worker A (msg 1, leased 30s)
--> worker B (msg 2, leased 30s)
--> worker C (idle)
ack(msg 1) -> deleted
A crashes -> msg 2 reappears after lease
Tune the lease carefully. If a task takes up to two minutes, a thirty second lease causes duplicates, while an hour-long lease delays recovery after a crash. Long tasks should extend the lease with a heartbeat. Limit prefetch so one worker does not hoard messages while others sit idle, and cap retries before routing to a dead-letter queue.
Low - queue plus worker pool
Medium - autoscaling and backlog alerts
Low - simple model
Visibility timeout shorter than processing time causes duplicate work
Poison message crash-loops all workers
Autoscaling lag lets backlog age past SLA