How does RabbitMQ handle high availability with mirrored and quorum queues?
See how RabbitMQ achieves high availability with mirrored and quorum queues, how Raft consensus prevents message loss, plus code and interview tips.
Expected Interview Answer
RabbitMQ achieves high availability by replicating a queue's contents across multiple broker nodes so it survives a node failure — historically with classic mirrored queues, and today with quorum queues, which use the Raft consensus algorithm for safer, more predictable replication.
Mirrored queues designate one master and several mirrors; the master handles operations and synchronously copies messages to mirrors, promoting a mirror if the master dies. This approach could lose messages during network partitions and was hard to reason about. Quorum queues replace it with a Raft-based log replicated to a majority (quorum) of nodes: a write is confirmed only once a majority has persisted it, so the queue tolerates the loss of a minority of nodes without data loss. Quorum queues are now the recommended default for HA.
- Queue data survives individual node failures
- Quorum queues avoid message loss via majority consensus
- Automatic leader election on failure
- More predictable behaviour during network partitions
- Recommended modern default over classic mirroring
AI Mentor Explanation
High availability is like a team keeping several capable wicketkeepers ready. Mirrored queues are one keeper doing the job while substitutes shadow every ball, and if the keeper is injured a substitute steps in — but a mix-up could drop a catch. Quorum queues are stricter: a run is only recorded once a majority of scorers agree, so no dismissal is ever lost even if one scorer fails.
Step-by-Step Explanation
Step 1
Understand the risk
A queue living on a single node is lost if that node fails, so its messages must be replicated.
Step 2
Classic mirrored queues
A master node replicates messages to mirror nodes; on master failure a mirror is promoted.
Step 3
Recognise mirroring's weakness
Mirrored queues could lose messages during network partitions and were hard to reason about.
Step 4
Quorum queues with Raft
Messages are written to a replicated log and confirmed only when a majority of nodes persist them.
Step 5
Leader election
If the leader fails, Raft elects a new leader from the remaining majority with no data loss.
Step 6
Choose the default
Prefer quorum queues for HA; classic mirroring is deprecated in favour of them.
What Interviewer Expects
- Explaining replication across nodes for HA
- Master/mirror model of classic mirrored queues
- Raft consensus and majority confirmation in quorum queues
- Why quorum queues are safer during partitions
- Knowing quorum queues are the modern recommendation
Common Mistakes
- Thinking a single durable queue is highly available
- Confusing durability (disk) with replication (nodes)
- Believing mirrored queues never lose messages
- Not knowing quorum queues use Raft consensus
- Recommending classic mirroring for new systems
Best Answer (HR Friendly)
“RabbitMQ stays available by copying a queue's messages onto several servers so the queue survives if one server dies. The older way was mirrored queues with a main copy and backups; the modern, safer way is quorum queues, which only confirm a message once most servers agree, preventing data loss.”
Code Example
const ch = await conn.createChannel()
await ch.assertQueue('orders', {
durable: true,
arguments: { 'x-queue-type': 'quorum' },
})
console.log('Quorum queue ready and replicated')# Set an HA policy so classic queues mirror to all nodes
rabbitmqctl set_policy ha-all "^orders\." \
'{"ha-mode":"all","ha-sync-mode":"automatic"}'Follow-up Questions
- Why are quorum queues preferred over classic mirrored queues?
- How does the Raft algorithm decide when a write is committed?
- What happens to a quorum queue if a majority of nodes are lost?
- How is durability different from replication in RabbitMQ?
- How many nodes should a quorum queue span and why odd numbers?
MCQ Practice
1. Which consensus algorithm underpins RabbitMQ quorum queues?
Quorum queues replicate a log using the Raft consensus algorithm, committing writes once a majority persists them.
2. When is a write to a quorum queue confirmed?
Raft commits an entry only after a quorum (majority) of nodes has persisted it, preventing loss if a minority fails.
3. What is the main weakness of classic mirrored queues?
Classic mirroring could lose messages and behaved unpredictably under partitions, which is why quorum queues replaced them.
Flash Cards
What algorithm do quorum queues use? — Raft consensus — writes commit once a majority of nodes persist them.
How do classic mirrored queues work? — A master replicates to mirrors; a mirror is promoted if the master fails.
Why prefer quorum over mirrored queues? — Safer under partitions, no majority-safe message loss, and the modern default.
Durability vs replication? — Durability persists to disk on a node; replication copies across nodes for HA.