RECAP
What to remember
- A lease (visibility timeout) hides a job instead of deleting it, so a crashed worker's job comes back.
- A lost acknowledgement after the side effect turns into a second run of that side effect.
- At-least-once delivery is the normal case; the side effect is the operation that must be safe to retry.
- Write a dedupe record in the same transaction as the effect, or use a conditional write, so the retry changes nothing.
- Use a key tied to the business action, set by the producer, and pass it to any external service that performs the effect.
NOW CLOSE THE GUIDE AND REDRAW IT
Without looking, draw the queue, two workers and the database. Mark where the acknowledgement is lost, then draw where duplicate work is prevented. Next to it, write which operation must be safe to retry and why the queue cannot do it for you.
Check your drawing against this list afterwards, not before:
- The lease or visibility timeout on the queue, with the job hidden rather than deleted.
- The lost acknowledgement after the side effect, and the redelivery to a second worker.
- An idempotency key tied to the business action, not to the delivery attempt.
- The dedupe record and the effect inside one transaction (or a conditional write).
- The retry acknowledged as a no-op instead of failing forever.
- A note on external effects: pass the key to the provider.
APPLY IT
Sketch a message broker with per-message acknowledgement
GO DEEPER WITH OUR GUIDES
OFF-SITE SOURCES · NOT WRITTEN BY US
Sources and further reading
- Making retries safe with idempotent APIs
How a caller-supplied request token turns a retry into a safe repeat, including what to return when the same token arrives with different parameters.
- Designing robust and predictable APIs with idempotency
Why network failures make retries unavoidable for payments, and how idempotency keys let clients retry without double charging.
- Amazon SQS visibility timeout
The reference description of leasing a message by hiding it, what happens when the timeout expires, and how to extend it for long jobs.
- Consumer acknowledgements and publisher confirms
How acknowledgements work in a broker, when messages are redelivered, and why consumers should expect duplicates.
- Timeouts, retries, and backoff with jitter
Why retries are needed, how they can overload a system, and why a retried operation must be idempotent.