Skip to content
Tutorials Center
My learning

Topics

Lesson 24 of 37 ยท Clustering and High Availability

Quorum Queues

Learn RabbitMQ quorum queues: Raft replication, leaders and followers, declaring x-queue-type quorum, delivery limit, differences from classic queues and a runnable majority-commit simulation.

For years the way to make a RabbitMQ queue survive a node failure was classic mirrored queues: a leader copied its messages to mirrors. They had weak guarantees, slow recovery and confusing synchronization. In RabbitMQ 4.0 mirroring was removed, and the replacement is the quorum queue, a durable, replicated queue built on the Raft consensus algorithm. Quorum queues are the default choice when messages matter.

The real broker cannot run on this page. The pika and rabbitmqctl snippets are read-only, and the runnable blocks are plain Python stand-ins that model commit-by-majority; real Raft also has terms, log matching and elections that are simplified here.

How a quorum queue works

A quorum queue has a leader and several followers (usually three replicas, one per node). The rules:

  1. Every publish goes to the leader, which appends it to its log and sends it to the followers.
  2. The message is committed when a majority of replicas has written it to disk. Only then does the leader send the publisher confirm.
  3. If the leader's node fails, the remaining replicas elect a new leader among themselves, as long as a majority is alive. Committed messages are never lost.
  4. A returning replica catches up from the leader's log.
sequenceDiagram
    participant P as Publisher
    participant L as Leader (node1)
    participant F1 as Follower (node2)
    participant F2 as Follower (node3)
    P->>L: publish M
    par replicate
        L->>F1: append M
        L->>F2: append M
    end
    F1-->>L: written
    Note over L: majority (2 of 3) reached
    L-->>P: confirm ack
    F2-->>L: written (later)
Python Stand-in: commit when a majority has the entry

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Declaring a quorum queue

The queue type is chosen at declaration with x-queue-type and cannot be changed afterwards (you declare a new queue and migrate). A quorum queue must be durable, not exclusive and not auto-delete:

Python
channel.queue_declare(
    queue="payments",
    durable=True,
    arguments={
        "x-queue-type": "quorum",
        "x-quorum-initial-group-size": 3,   # number of replicas
        "x-delivery-limit": 5,              # poison message protection
    },
)

Messages are always written to disk, so delivery_mode does not matter. Publisher confirms and consumer acks work exactly as in the earlier lessons.

Manage the replica set with rabbitmq-queues:

Text
rabbitmq-queues add_member payments rabbit@node4
rabbitmq-queues delete_member payments rabbit@node1
rabbitmq-queues grow rabbit@node4 all
rabbitmq-queues rebalance quorum
rabbitmq-queues quorum_status payments

You can make quorum the default for a virtual host with rabbitmqctl add_vhost shop --default-queue-type quorum.

What differs from classic queues

Topic Classic queue Quorum queue
Replication None in 4.x (single node) Raft, usually 3 replicas
Durability Your choice Always durable
Poison messages You build retries x-delivery-limit built in (default 20)
Exclusive / transient Supported Not supported
Priorities 255 levels Two levels (normal and high) in 4.x
Global QoS prefetch Supported Not supported (per consumer only)
Memory Optional page-out Log kept on disk, small in-memory index
Lazy / non-durable use Fine for temporary data Wrong tool

Use a classic queue for transient, high-throughput or exclusive work (per-connection reply queues, throwaway data). Use a quorum queue for anything you would be unhappy to lose.

Poison messages and the delivery limit

A message that crashes its consumer on every attempt is a poison message. A classic queue redelivers it forever. A quorum queue counts returns in the header x-delivery-count and, when the count exceeds x-delivery-limit, drops the message or dead-letters it (see Dead Letter Exchanges and Retries). Always pair the limit with a dead letter exchange so you keep evidence.

Python Stand-in: delivery limit for a poison message

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Failure behavior and sizing

  • One node down (3 replicas): the queue stays available; a new leader is elected within moments and clients reconnect.
  • Two nodes down: there is no majority, so the queue stops accepting publishes and deliveries rather than risk divergence. Consistency beats availability here. When a node returns it recovers automatically.
  • Disk speed matters: every message is fsynced before it is confirmed, so use fast disks (NVMe) and batch publishes with asynchronous confirms.
  • Consumer scale: a quorum queue is one Raft group with one leader, so one queue still serializes through one node. For more throughput, spread work over several queues (or use streams with partitions).
  • Three replicas are enough for most cases; five give more fault tolerance at the cost of more write traffic.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. When does a quorum queue confirm a publish?

    Raft commits an entry once a majority has stored it; the leader then confirms to the publisher.
  2. 2. A 3-replica quorum queue loses two nodes. What happens?

    Without a majority the queue stops serving requests so that committed data cannot diverge.
  3. 3. How do you choose the quorum queue type?

    The type is fixed at declaration time; changing it means declaring a new queue and migrating messages.
  4. 4. Which use case still fits a classic queue better?

    Exclusive, transient, non-replicated queues are not supported by quorum queues and do not need to be.

Summary

  • Quorum queues replicate with Raft and confirm after a majority has written the message; they replace mirrored classic queues.
  • Declare with x-queue-type: quorum (durable, non-exclusive); manage members with rabbitmq-queues.
  • x-delivery-limit plus a dead letter exchange handles poison messages.
  • With a lost majority the queue pauses; plan for 3 or 5 replicas and fast disks.

Next: Streams