RabbitMQ competing consumers: share queue work across workers
Competing consumers are multiple workers consuming one queue and dividing tasks. RabbitMQ normally dispatches messages in round-robin order, which can raise parallel throughput. This default does not account for task duration or each worker’s current capacity. For variable-duration tasks, combine manual acknowledgements with a suitable prefetch limit.
Competing consumers are multiple workers consuming one queue and dividing tasks. RabbitMQ normally dispatches messages in round-robin order, which can raise parallel throughput. This default does not account for task duration or each worker’s current capacity. For variable-duration tasks, combine manual acknowledgements with a suitable prefetch limit.
When several consumers use the same queue, RabbitMQ delivers each message to one of them. This is different from publish/subscribe, where separate queues can give each subscriber a copy. Round-robin roughly balances delivery counts, not completion times. If long and short jobs alternate, a busy worker may receive another task before finishing its current one.
Use manual ACK. The worker acknowledges on the same channel after finishing. If it disconnects first, RabbitMQ can requeue the unacknowledged delivery. Work can repeat, so handlers should be idempotent.
Choose prefetch. The RabbitMQ tutorial demonstrates prefetch_count=1, limiting each worker to one unacknowledged message. A worker receives another only after acknowledging the previous one, so a less-busy worker may get the next task.
Measure the trade-off. Low prefetch can improve fairness but reduce throughput. A larger value may keep the pipeline full but can leave many messages in flight on a slow worker.
Monitor ready and unacknowledged messages, processing time, and worker errors. More workers may only move the bottleneck to a downstream database or API.
Plan clean shutdown and redelivery. Queue durability and message persistence are separate settings if tasks must survive broker restarts.
| Situation | Starting point | Check |
|---|---|---|
| Similar task durations | Round-robin, bounded manual ACK | Completion and latency per worker |
| Highly variable durations | Manual ACK and low prefetch first | Fairness and throughput |
| Recover after worker failure | Manual ACK and redelivery handling | Idempotency against duplicate effects |
| Every consumer needs every message | Publish/subscribe with separate queues | Competing consumers do not fan out copies |
The RabbitMQ Work Queues example assumes Pika Python 1.0.0 and a local broker. Confirm consumer API, ACK behavior, and prefetch scope for your deployed version and client. Observe per-worker in-flight work and queue depth with mixed task durations. These are suggested checks; no broker was run for this article.
Sources and scope
[RabbitMQ Work Queues tutorial](https://www.rabbitmq.com/tutorials/tutorial-two-python) — round-robin, manual ACK, redelivery, and prefetch 1.
[RabbitMQ Consumers guide](https://www.rabbitmq.com/docs/consumers) — queue consumers and acknowledgement modes.
[RabbitMQ Consumer Acknowledgements and Publisher Confirms](https://www.rabbitmq.com/docs/confirms) — ACK purpose, channel-scoped delivery tags, and automatic ACK trade-offs.
This covers RabbitMQ AMQP 0-9-1 work queues. Competing consumers enable parallel work but do not guarantee global ordering or exactly-once business effects.