Quorum queues

RabbitMQ · Advanced · 14 min

Quorum queues are RabbitMQ's answer to losing a node without losing messages, and the default choice for important data.

A quorum queue (x-queue-type: quorum) is replicated across several cluster nodes (three by default) using the Raft consensus algorithm. One replica is the leader; publishes are confirmed only after a majority of replicas have written the message to disk. If the leader's node fails, a follower with all committed data takes over in seconds. Classic mirrored queues, the older replication mechanism, were removed in RabbitMQ 4.0; quorum queues replace them.

Characteristics:

  • Always durable; all messages are persisted.
  • Available while a majority of replicas is up: 2 of 3, or 3 of 5. Use an odd replica count.
  • Poison message handling: each message's delivery count is tracked, and since 4.0 a default delivery limit of 20 applies; beyond it the message is dropped or dead-lettered. x-delivery-limit or a policy changes it.
  • Supports dead-lettering with an at-least-once strategy (dead-letter-strategy: at-least-once) that guarantees the DLX copy is safely stored.
  • Supports consumer priorities and, since 4.0, message priorities in a simple high/normal form.
  • Not designed for huge backlogs of millions of messages kept long term, for transient or exclusive queues, or for very short-lived queues.

Quorum queues trade some throughput and latency for safety. Use them for anything you can't afford to lose; set default_queue_type on a vhost to make them the default.

Example

import pika
ch = pika.BlockingConnection(pika.ConnectionParameters("localhost")).channel()
ch.queue_declare("payments", durable=True, arguments={
    "x-queue-type": "quorum",          # Raft-replicated
    "x-delivery-limit": 5,             # poison messages stop after 5 deliveries
    "x-dead-letter-exchange": "dlx",
    "x-dead-letter-strategy": "at-least-once",
    "x-overflow": "reject-publish",    # required by at-least-once dead-lettering
})
ch.confirm_delivery()                  # confirm = written by a majority
ch.basic_publish("", "payments", b'{"amount": 42}')
print("stored on a quorum of replicas")

# Inspect replicas and the leader:
#   rabbitmq-queues quorum_status payments
#   rabbitmqctl list_queues name type leader members

Remember

  • Quorum queues replicate with Raft and confirm after a majority writes
  • They stay available while a majority of replicas is up
  • A delivery limit (default 20 since 4.0) stops poison messages

Watch out for

  • Running quorum queues on a two-node cluster: losing either node loses the majority.

Check yourself

  1. A quorum queue has 3 replicas. One node goes down. What happens?

Sign in to answer, see the explanations, and get this lesson back as a quick review later.

Official docs: www.rabbitmq.com/docs/quorum-queues