Design message acknowledgements: reduce loss and duplicates with the right timing
A message acknowledgement (ACK) is a signal that a consumer has finished processing a message or reached a particular progress point. ACK too early and the message may disappear before its result is stored; ACK too late and a failure can cause redelivery and duplicate work. A sound default is to acknowledge after the business effect is durably recoverable, but the exact boundary depends on the broker model.
A message acknowledgement (ACK) is a signal that a consumer has finished processing a message or reached a particular progress point. ACK too early and the message may disappear before its result is stored; ACK too late and a failure can cause redelivery and duplicate work. A sound default is to acknowledge after the business effect is durably recoverable, but the exact boundary depends on the broker model.
Three acknowledgement models
| Example broker behavior | What the acknowledgement means | If it is not sent |
|---|---|---|
| RabbitMQ manual consumer ACK | Tell the broker that one delivery or a range of delivery tags is complete | Unacknowledged deliveries can be requeued when the channel/connection closes |
| Amazon SQS DeleteMessage | Remove the message using the current receipt handle | It may become visible again after the visibility timeout; a later receive yields a new receipt handle |
| Kafka consumer offset commit | Store the consumer group’s next partition position | A restart may reread from an earlier commit or skip work, depending on when automatic commits occur |
These are not the same ACK API. RabbitMQ delivery tags identify deliveries on a channel. SQS deletion uses the receipt handle from the latest receive, not the message ID. Kafka commits do not delete individual messages; they record where a consumer should resume in the partition log. Check client-library defaults for automatic acknowledgement or commit.
Order processing and acknowledgement
**Receive and process the message.** Validate the input and establish any idempotency key or business operation ID needed before an external action.
**Persist the business effect in a recoverable way.** If writing a local database, commit the business change and deduplication marker in one transaction. If calling an external API, record enough state to identify the operation and its retry status, or use the external system’s idempotency key.
**Acknowledge only after success is durable.** Do not ACK, delete, or commit an offset before the database commit or durable processing result. With Kafka, do not commit a later offset while an earlier record in the ordered partition is unfinished, or a restart can skip that record.
**Route failures deliberately.** Use bounded delayed retries for transient errors and dead-letter isolation for permanent input failures. Immediate negative acknowledgement/requeue can help recovery, but if every consumer repeats the same failure it can create a redelivery loop and extra load.
**Bound the in-flight window.** Tune prefetch, batch size, visibility timeout, and poll/commit interval for the selected product so too many unacknowledged messages do not overwhelm memory or downstream systems.
What failures at each point can mean
**ACK/commit before processing:** The broker may treat the message as complete even though no result exists; work can be lost.
**Process, then crash before ACK/commit:** The message may be redelivered or reread from the previous position, duplicating the business effect. Idempotent handling or an atomic deduplication marker is needed.
**Uncertain response between processing and ACK:** For example, the database commit succeeded but the ACK response did not reach the consumer. The consumer may mistake success for failure, so duplicate delivery must be a safe path.
**ACK/commit succeeds but an external effect fails:** The broker may not redeliver. A separate recovery/compensation or outbox workflow is needed.
Therefore, “send one ACK and get exactly-once” is not a safe assumption. Check whether the broker’s guarantee boundary matches the application database and external-service transaction boundaries.
Broker-specific notes
**RabbitMQ:** In manual-ack mode, acknowledge after successful processing. Be careful when acknowledging a range of delivery tags. Unacknowledged deliveries can be requeued after connection closure. If requeueing happens immediately, consider a negative-ack policy or delayed retry.
**Amazon SQS:** Call `DeleteMessage` after processing with the receipt handle from the latest receive. If work outlasts the visibility timeout, the message can become visible again; set the timeout for expected maximum processing time and extend it when needed. At-least-once delivery means duplicates cannot be ruled out completely, even during the timeout.
**Kafka:** An offset is the next read position for a partition. Committing before processing is closer to at-most-once and can lose work; processing before commit yields at-least-once because a restart may repeat the work. Kafka transactions alone may not cover effects in external systems; coordinate the sink result and offset when exactly-once behavior is required.
Verification checklist
In a test environment, reproduce normal processing, process termination just before/after ACK, slow work and timeout, lost responses, duplicate delivery, transient and permanent errors, consumer restart, and rebalance. For each case, record whether the message disappears, is redelivered, duplicates a result, or goes to failure isolation. Monitor unacknowledged count, redelivery count, processing time, timeouts, commit failures, and consumer lag. No real broker or consumer was run or tested for this article.
Sources
[RabbitMQ: Consumer acknowledgements and publisher confirms](https://www.rabbitmq.com/docs/confirms)
[Amazon SQS: Visibility timeout](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-visibility-timeout.html)
[Amazon SQS: Queue and message identifiers](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-queue-message-identifiers.html)
[Apache Kafka: Message delivery semantics](https://kafka.apache.org/44/design/design/)
[Apache Kafka Consumer API](https://kafka.apache.org/44/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html)