Quorum Queues
Replicated queues on Raft: leaders, members, failover, and their limits
A classic queue lives on one node. If that node dies, the queue is
unavailable, and if its disk is lost, the messages are gone. A quorum
queue is replicated across several nodes using the Raft consensus
algorithm, the same family of protocol as Kafka's KRaft and Redis
Cluster's failover. It's the default queue type in this cluster
(default_queue_type = quorum).
How it works
Each quorum queue has a leader replica and followers on other nodes. Every operation (enqueue, ack) is an entry in a Raft log, committed once a majority of members have written it.
docker exec rabbit-1 rabbitmqctl -q list_queues -p shop name type leader members
orders.billing quorum rabbit@rabbit-2 [rabbit@rabbit-2, rabbit@rabbit-1, rabbit@rabbit-3]
docker exec rabbit-1 rabbitmq-queues quorum_status orders.billing --vhost shop
Node Name Raft State Membership Last Log Index Last Written ...
rabbit@rabbit-1 follower voter 4 4
rabbit@rabbit-2 leader voter 4 4
rabbit@rabbit-3 follower voter 4 4- A publish is confirmed when a majority (2 of 3) has it.
- Consumers can connect to any node; the cluster forwards to the leader.
- With 3 members, the queue tolerates one node failure; with 5, two.
Failover under load
labs/quorum_failover.py publishes with confirms in a loop. Stopping the
leader's node mid-run:
docker compose -f compose_prod.yaml run --rm labs python quorum_failover.py
# in another terminal: find and stop the leader of lab.ha
docker stop rabbit-1
connected to rabbit-1
connection lost (ConnectionClosedByBroker); reconnecting...
connected to rabbit-2
confirmed 3246, queue holds 3248 (count >= confirmed: nothing confirmed was lost)A follower was elected leader within seconds; the publisher reconnected to another node and carried on. Every confirmed message survived. The queue holds 2 more than were confirmed: messages that reached the broker but whose confirms were lost with the connection, so the publisher can't know they arrived. If it retried them, they'd be duplicates. At-least-once again.
The client helper in this module originally passed all three node URLs to
pika and let it fail over. When rabbit-1 was stopped, its hostname no
longer resolved in Docker, pika raised a DNS error (socket.gaierror)
instead of trying the next node, and the script crashed.
labs/common.py now tries each node itself and catches OSError as
well as AMQP errors. Test your clients' failover against a node that's
really gone, not only one that refuses connections.
Membership
The number of replicas is the queue's membership. It's set when the
queue is declared (x-quorum-initial-group-size, default: up to 3 nodes)
and can be changed:
This cluster sets quorum_queue.continuous_membership_reconciliation so
membership is restored automatically, after the
one-member surprise during setup.
What quorum queues don't do
| Feature | Classic | Quorum |
|---|---|---|
| Replication | No (single node) | Yes, Raft |
| Non-durable / exclusive | Yes | No: always durable |
| Message priorities | Yes | Two levels (normal and high) since 4.0 |
| Per-message TTL | Yes | Yes (since 3.10) |
| Poison message handling | Manual | Built-in delivery limit |
| Memory use | Lower | Higher: keeps a Raft log, snapshots |
| Throughput per queue | Higher | Lower: every write goes to a majority |
Use classic queues for temporary, non-critical, or exclusive queues (RPC replies, a live dashboard's feed), and quorum queues for anything that must survive a node failure.
Quorum queues are designed for queues that drain. A quorum queue that grows to millions of messages keeps them all in its Raft log until they're acked, uses a lot of disk and memory, and slows down every operation. If you need a large, long-lived backlog that's read more than once, that's a stream.
Lab
- Run
quorum_failover.pyand stop the leader's node as shown. Note how long publishing paused. - Run
rabbitmq-queues quorum_status lab.ha --vhost shopbefore and after. - Stop two nodes. Can you still publish to
lab.ha? Consume? Start them again and watch it recover. - Run
rabbitmq-queues rebalance quorumand check the leaders withlist_queues name leader.