How it works
Workers commonly provide at-least-once processing: a message may be handled more than once, but it is not silently dropped. Amazon SQS standard queues behave this way, redelivering a message that was not deleted before its visibility timeout ends. If a worker crashes after a provider accepts a request but before it stores the result, the queue delivers the attempt again. Use a stable delivery-attempt key, a uniqueness constraint on logical intent, and a provider idempotency key, which makes a repeated request count once, where supported. These reduce duplicates, but a provider that lacks idempotency can leave an unavoidable ambiguity.
Classify failures before retrying. A timeout or provider 5xx may be transient; use exponential backoff with jitter, a retry limit, and a circuit breaker that pauses calls while the provider is broadly unhealthy. With waits of 1, 2, 4, 8, and 16 seconds, five retries span about 31 seconds, and jitter, a small random change to each wait, stops 10,000 attempts from returning at once. Invalid tokens, malformed addresses, and denied consent are permanent outcomes and should not be retried. After the bounded retry budget, move the attempt to a dead-letter queue, a holding area with context for inspection and controlled replay.
Persist attempt state and audit transitions so a crash cannot erase the work; that costs one more write per attempt. When replaying a dead-letter item, retain its original notification identity. Do not claim exactly-once delivery across independent services; state the actual guarantee and the residual duplicate risk.
A worker times out after sending an SMS; the provider may have accepted it. What is the safest next step?
Check the provider using the request or idempotency key if its API supports that. Otherwise mark the attempt ambiguous and follow a policy that weighs duplicate SMS cost against missed delivery; blindly retrying cannot guarantee exactly one message.
Use this as a guide for self review; written answers are not graded.Keep in mind
- At-least-once work requires idempotency and explicit duplicate handling.
- Retry transient failures; quarantine permanent or exhausted attempts with a replay path.