Learn Labs
Reliability

Publisher Confirms

Knowing a message was accepted, persistence, and what fire-and-forget hides

Consumer acks protect messages on the way out. Publisher confirms protect them on the way in. Without confirms, basic_publish writes bytes to a socket and returns. The publisher has no idea whether the message was routed, stored, or refused.

Turning confirms on

ch.confirm_delivery()     # this channel is now in confirm mode
ch.basic_publish(...)     # the broker replies with basic.ack (stored) or basic.nack (refused)

For a quorum queue, the broker confirms after a majority of replicas have written the message. For a classic durable queue with a persistent message, after it's written to disk. A confirm is the broker's promise that it has taken responsibility for the message.

publisherqueue leaderfollowerfollowerbasic.publishappend (Raft)append (Raft)writtenbasic.ack: majority has itpublish to a full queuebasic.nack

What fire-and-forget hides

labs/reliability.py publishes 20 messages to a quorum queue limited to 10 (x-max-length: 10, x-overflow: reject-publish):

2. publishing 20 messages to a queue limited to 10 (overflow=reject-publish)
burst, no confirms:  queue holds 20  (quorum queues apply the limit asynchronously: a burst can overshoot)
steady, no confirms: queue holds 11; the publisher saw no error for the 9 it lost
with confirms:    9 publishes were nacked; the publisher knows exactly which

Three findings in one experiment:

  • Without confirms, refused messages vanish silently. At a steady rate the queue kept 11 and refused 9, and the publisher saw no error at all.
  • With confirms, each refusal is reported (a NackError in pika), so the publisher can retry, slow down, or alert.
  • Quorum-queue limits are approximate. A fast burst of 20 was all accepted, because the leader applies max-length asynchronously. Treat length limits as a safety net, not an exact cap.

The cost, and how to pay less

1. publishing 2000 persistent messages to a quorum queue
no confirms:                38,543 msg/s  (no idea if they arrived)
confirm each (sync):           833 msg/s  (every message acknowledged)

Waiting for each confirm before the next publish is about 45x slower here, because every message pays a full round trip plus Raft replication. That's a property of synchronous publishing, not of confirms: pika's BlockingChannel waits for each confirm. Clients that keep many publishes in flight and handle confirms asynchronously (aio-pika, the Java, Go, and .NET clients) get close to the no-confirm rate with full safety:

publish, publish, publish ...don't wait between themon_ack(delivery_tag, multiple)mark confirmed (multiple=True confirms everything up to the tag)on_nack(delivery_tag, multiple)retry or reportbound the in-flight windowe.g. 1000 unconfirmed messages, then wait

Persistence

delivery_mode=2 (Persistent)the message is written to diskdurable=True on the queuethe queue itself survives a restart

Both are needed for a classic queue's messages to survive a broker restart. Quorum queues and streams are always durable and always persist messages. Persistence alone isn't enough: without confirms, a message can be lost between the socket and the disk.

mandatory: routed, not just accepted

A confirm says the exchange accepted the message, which is true even if it matched no binding and was dropped. Add mandatory=True so unroutable messages are returned instead (see Exchange Types). Confirms plus mandatory together mean "stored in at least one queue."

End-to-end at-least-once

Lab

  1. Run reliability.py.
  2. Publish to the pre-loaded orders exchange with an unmatched routing key, with confirms but without mandatory. It's confirmed. Add mandatory and see the UnroutableError.
  3. Write an async publisher with aio-pika (or Java) that keeps 500 messages in flight, and compare its confirmed throughput with the sync numbers.
  4. Stop two of three nodes, then publish with confirms to a quorum queue. What happens without a majority?

On this page