Skip to content

Lesson 4 of 9 · 27m

Publisher Confirms, Persistence, and What Durable Really Means

Make the write path explicit with persistent messages, durable topology, publisher confirms, mandatory returns, and honest latency tradeoffs.

Teams love to say "RabbitMQ is durable" as if durability were a single switch. It is not. There are three separate decisions: the exchange or queue survives broker restart, the message is written persistently, and the publisher knows the broker accepted responsibility for it. If any one of those is missing, your reliability story has a hole. The first time a node restarts, that hole becomes visible.

Durability is layered

A durable queue survives broker restart. A persistent message is written with disk intent. Publisher confirms tell the producer when RabbitMQ has accepted responsibility. The minimal production posture usually looks like this:

channel.exchange_declare(exchange="orders", exchange_type="topic", durable=True)
channel.queue_declare(queue="orders.invoice", durable=True)
channel.confirm_delivery()
channel.basic_publish(
    exchange="orders",
    routing_key="order.created.eu",
    body=body,
    properties=pika.BasicProperties(
        delivery_mode=2,
        content_type="application/json",
        message_id=message_id,
        timestamp=int(time.time()),
    ),
    mandatory=True,
)

delivery_mode=2 marks the message persistent. It does not turn a non-durable queue into durable storage. All three pieces must line up.

Confirms are not acknowledgements from consumers

Publisher confirms answer only one question: did the broker accept this publish? They say nothing about whether a consumer processed it correctly. This distinction sounds obvious and still causes design mistakes. A confirmed publish can sit in a queue forever, route to the wrong queue, expire, dead-letter, or be redelivered repeatedly.

publisher confirm = broker accepted responsibility
consumer ack       = application finished processing

Those are different contracts. You often need both.

Batching confirms is where throughput lives

Waiting for a confirm after every publish is correct but slow. Pipelining publishes and tracking outstanding sequence numbers gives much better throughput. Most mature client libraries expose confirm callbacks rather than making you implement raw bookkeeping.

slow simple mode: publish -> wait confirm -> publish
production mode:  publish many -> track outstanding -> retry or fail unconfirmed set

The hard part is the retry decision. If a connection drops before the confirm arrives, you do not know whether the broker stored the message. Retrying can duplicate it. Not retrying can lose it. This is one reason message IDs and idempotent consumers matter even when publishers are careful.

Mandatory and returns protect routing correctness

mandatory=True asks the broker to return messages that cannot be routed. Handle returned messages as errors. A returned message is not automatically retried or dead-lettered; it is handed back to the publisher because no queue matched. In client code, treat it like a schema or configuration incident:

publish returned -> stop assuming success -> alert -> inspect exchange/binding/routing key

Alternate exchanges are often easier operationally because unroutable messages land somewhere inspectable even if the publisher disappears.

Disk persistence is not an infinite safety blanket

Persistent messages reduce loss across restart, but they are not a backup, not cross-datacenter replication, and not protection from misconfigured queue types. Disk layout, fsync behavior, queue type, and cluster replication all matter. Quorum queues replicate data across nodes; classic non-mirrored durable queues are still local in the ways that hurt during node loss.

Field notes

  • Do not benchmark confirms on localhost and assume production network latency will feel the same.
  • Include a stable message_id at publish time; debugging duplicate or missing work without one is archaeology.
  • Confirm mode must be enabled per channel. Declaring durable topology does not enable it.
  • If the business cannot tolerate duplicates, RabbitMQ alone cannot save you; the consumer or downstream datastore must enforce idempotency.

Was this lesson helpful?

Sign in to rate