Try
↑ ↓ move↵ openesc close
In this lesson · topic 1 of 7
  1. 1. The ack point
  2. 2. Three orders, and what exactly-once means
  3. 3. Crash a consumer around the ack
  4. 4. Slow is not dead: duplicates without a crash
  5. 5. Retry limits and the dead-letter queue
  6. 6. Publishing without losing the event
  7. 7. Duplicates, timeouts and exactly once: three checks

Topic 1

The ack point

4 min read

A message is a promise

A broker holds a message until a consumer says it is finished. That signal is the acknowledgement, or ack. Until it arrives, the broker keeps the message. After it arrives, the broker deletes it.

The consumer does two things with each message. It does the work, which has an effect on the world: charge a card, write a row, send an email. And it sends the ack. The order of those two steps decides what a crash costs.

A consumer can die at any moment. A process can be killed, a machine can lose power, a deploy can restart a pod. The broker cannot see inside the consumer. All it knows is whether an ack has arrived.

Two ways to be wrong

Ack first, then do the work. If the consumer dies after the ack and before the work, the broker has already deleted the message. Nobody will try again. The message is lost.

Do the work first, then ack. If the consumer dies after the work and before the ack, the broker sees no ack. After a timeout it hands the message to another consumer. The work happens a second time.

There is no ordering that avoids both. The broker cannot tell “died before the work” from “died after the work, before the ack”. From its side the two look the same.

Predict first

A consumer acks each message the moment it receives it, then does the work. It crashes right after sending one ack, before starting the work. What happens to that message?

What it costs

Take a fleet where 15 percent of delivery attempts end in a crash, and half of those crashes land in the gap between the two steps. The other half happen before anything was done. This is rough, and meant to show the shape of the problem.

Acking first, 8.3%measured of the messages were lost and each message caused 0.00measured extra side effects. Acking last, 0%measured were lost, but each message caused 0.09measured extra side effects on average. Read that as repeated charges, rows or emails per message.

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms