Course contentsShow
← System Design
Lesson 683 of 1,91918. Message Queues and BrokersFree lesson

Consumer Acknowledgment Timing

Auto-ack vs manual-ack: when to confirm processing to prevent message loss or duplication.

Consumer Acknowledgment Timing

What you'll learn: When to confirm message processing—before or after handling—to prevent message loss or duplication in message queues.


The Core Decision

When a consumer pulls a message from a queue, it must eventually acknowledge (ack) receipt so the broker knows the message was handled. The critical choice is when that acknowledgment happens:

  • Auto-ack (pre-processing): The broker considers the message delivered as soon as it sends it to the consumer
  • Manual-ack (post-processing): The consumer explicitly confirms after successfully processing the message

This timing decision directly impacts whether you risk losing messages or duplicating work.


Auto-Ack: Fast but Risky

With auto-ack, the message is acknowledged immediately upon delivery, before your code processes it.

Risk: If your consumer crashes mid-processing, the message is already gone from the queue—message loss occurs.

When to use: High-throughput scenarios where occasional message loss is acceptable (analytics, logging, non-critical metrics).


Manual-Ack: Safe but Slower

With manual-ack, your consumer code explicitly sends an acknowledgment after successfully processing the message.

Benefit: If the consumer crashes before acking, the broker retains the message and redelivers it to another consumer—no message loss.

Risk: If you ack too early (before full processing), you're back to the auto-ack problem. If the consumer crashes after processing but before acking, you get duplicate delivery.

When to use: Critical workflows where losing messages is unacceptable (payments, orders, important state changes). Pair with idempotent operations to handle potential duplicates.


Key Takeaway:
Auto-ack trades safety for speed (risk of loss), while manual-ack prioritizes reliability by acknowledging only after processing (risk of duplication). Choose based on your tolerance for message loss vs duplicate handling complexity.