First, the key terms.
- Acknowledgment
- A consumer’s signal that a message has been handled.
- Visibility timeout
- A period during which a delivered message may be hidden from other consumers.
The idea, explained
A queue can absorb bursts and let producers finish before downstream work completes. Delivery guarantees vary; consumers should often expect a message to arrive more than once. Acknowledgments, visibility timeouts and retry policies determine how unfinished work returns. Poison messages need bounded retries and a review path. Queue depth is useful, but the age of the oldest message often better reveals how long users are waiting.
Trace the crash window
A consumer can complete an external action and crash before acknowledging it. The queue cannot safely infer that the action succeeded, so redelivery may be necessary. “At least once” permits this duplication.
Make processing safe
Use a stable operation identifier and durable state to detect completed work. Bound retries, inspect repeated failures and consider dead-letter handling. Queue ordering and delivery guarantees vary across products.
Follow a worked example.
A morning newsletter creates one delivery job per confirmed subscriber. If a worker crashes after sending but before acknowledging its job, the queue may deliver it again. A separate deduplication key prevents a second email for the same reader and date.
Walk it through, one step at a time
- A worker sends the morning digest, then crashes before acknowledging the job.
- The queue redelivers it. A durable key combining subscriber and edition date shows it was already sent.
- The worker records or returns the existing result rather than sending a second message. The exact provider interaction also needs idempotency protection.
Where people get stuck
Receiving a message once during testing does not establish exactly-once processing in production.
Now try it yourself.
1. Check the core idea
Why should a consumer tolerate duplicate deliveries?
Reveal the answer & reasoning
Failures can occur between completing work and recording acknowledgment. A retry may be necessary even when the external action already happened.
2. Apply what you learned
Would a longer visibility timeout eliminate duplicates?
Reveal the answer & reasoning
No. It changes redelivery timing, but crashes and uncertain outcomes can still occur. The consumer’s side effects must be designed for safe repetition.