Sending the email and telling the queue that the job is finished are two different events. If the first succeeds and the second never arrives, a retry can send an unwanted sequel. That little gap is where a visibility timeout stops being an obscure queue setting and starts affecting an actual customer.
In Amazon SQS, a visibility timeout is the period after a message is received when the service generally keeps it from being delivered to other consumers. It is a temporary processing window, not a permanent lock and not proof that the work succeeded. If the message is not deleted before the window expires, it can become available again. AWS’s visibility-timeout guide also makes an uncomfortable point for anyone who would like a single perfect setting: with at-least-once delivery, a duplicate can still occur within the window.
The operator’s problem is therefore bigger than choosing a timeout. The system must make a second attempt safe, know when to stop attempting, and give a person enough evidence to distinguish an unfinished job from a finished action whose acknowledgment was lost.
Follow one message past the successful action
Imagine a standard queue holding a request to create a report. A worker receives it at 10:00:00 with a 30-second visibility timeout. It creates the report at 10:00:12. Before it can delete the message, the process crashes. At roughly the end of the visibility period, another worker may receive that same request. A dashboard that says “message received twice” is accurate. So is a storage record showing the report was created once before the crash. Neither tells you whether a second report should be created.
Suppose the application has a durable job record keyed by an identifier that belongs to the request. The second worker can consult that record and see that the report is already complete. It can then follow a tested procedure for acknowledging the message without creating the report again. That is an application design, not an automatic property supplied by the timeout. The record needs its own careful handling: two workers can arrive close together, and a casual read-then-write check may allow both to conclude that no work exists.
A different operation may not be safely repeatable. Sending an email, issuing a refund, or calling an outside service can produce an effect beyond the worker’s database. An “already processed” flag written after the external call still leaves a gap if the worker dies between the call and the flag. The right recovery design depends on the systems involved: perhaps a provider supports an idempotency key, perhaps the application can reconcile a provider receipt, or perhaps a human must review an uncertain outcome. The queue cannot fill in evidence it never received.
Short and long windows fail differently
A short timeout makes a crashed or stalled task available for another attempt sooner. It also increases the chance that a legitimately slow worker is still processing when another worker receives the job. If a report normally takes 20 seconds but occasionally takes 75, a 30-second window creates a real overlap risk in that longer case. Increasing the window to two minutes reduces that specific timing problem, but it does not prove that duplicates are impossible.
A very long timeout makes premature reappearance less likely, while slowing ordinary recovery after a genuine failure. If a job dies one second after receiving a 30-minute window and no component adjusts visibility, the next attempt may wait close to the rest of that period. That may be fine for a nightly archive and unacceptable for a customer waiting for a time-sensitive report. Compare the timing with an actual service objective, not just an average processing duration.
Measure the distribution of processing times, the time required for the final delete call, and the behavior of upstream services under load. A quiet-day average can hide the tail that matters during a slowdown. Keep the measurements tied to a particular job type and revision: a worker that adds a large document conversion step may need a different budget than a worker that updates one small record.
Extension is a heartbeat, not an unlimited lease
SQS supports changing a message’s visibility while it is being processed. A worker handling variable-duration work can periodically extend the window when it is still making progress, rather than starting every job with the longest possible timeout. AWS discusses that approach in its processing-time guidance. The extension operation itself can fail, so the worker needs a plan for what happens if it can no longer confirm that the window has been extended.
A heartbeat should represent useful progress. A separate timer that keeps extending a message while the actual task is hung can postpone recovery indefinitely within the service’s limits. Consider recording a completed stage, a recent output checkpoint or another task-specific sign before extending. Also decide what the worker should do if its remaining visibility becomes too short to begin an irreversible external action. Guessing that it will finish in time is a fragile coordination mechanism.
AWS documents a maximum visibility interval measured from the original receive request; extensions do not reset that clock. Long-running work may need smaller resumable stages or a different orchestration approach. Check the current service documentation for limits and API behavior rather than treating an example timeout as a universal recommendation.
It is also worth examining what the queue calls an attempt. A worker may receive a message and fail before it can even read a dependency. If the receive count contributes to a dead-letter policy, repeated infrastructure failures can move a message aside without the business operation ever running. Record the stage reached on each attempt. A useful investigation distinguishes “never started,” “started but failed,” and “external result unknown” instead of treating every return to the queue as the same event.
Visibility changes can shorten a window as well as extend it. A worker that decides it cannot continue may be able to make a message available sooner, subject to the queue’s documented behavior and its own failure policy. That is a coordination decision: rapidly returning a poison message without addressing the cause can create a hot retry loop. A bounded delay, clear failure record and appropriate dead-letter policy give the next attempt a better chance of doing something different.
Ordering does not erase the completion problem
FIFO queues introduce message-group ordering. While one message in a group is in flight, later messages in that group are normally held until it is deleted or becomes visible again. This can protect a sequence such as “create account, then update account,” but a stuck first message can also delay the rest of that group. A group identifier is therefore an operational decision: one giant group may serialize work that could safely proceed independently; overly broad concurrency can break an intended sequence.
Ordering and deduplication features do not automatically make a downstream email, payment or database update happen exactly once. Examine the scope and duration of any service deduplication, the visibility window, and the application’s own durable record. A message that arrives again after a worker’s uncertain failure still needs an answer to “what already happened?”
A dead-letter queue can isolate messages that repeatedly fail according to a configured policy. It is a useful place to investigate, not a magic repair step. Our guide to dead-letter queues covers why the next action should begin with the failure and any completed side effects, rather than an indiscriminate replay.
Build an incident timeline that can answer the real question
For one disputed job, collect the stable job identifier, each receive time, the visibility settings or extensions, worker attempts, the business action’s own receipt and the message-deletion result. Restrict the log to identifiers and timing needed for investigation; it does not need customer content or credentials. If the provider’s receipt shows success but the worker log ends before deletion, “the job failed” is too broad a conclusion. The queue acknowledgment failed or is unknown; the external action may have succeeded.
Then decide what evidence makes a repeat safe. If a report already exists, does the second attempt find the same artifact or create a conflicting version? If an email provider returns an ambiguous timeout, can the team look up the request before retrying? If the system cannot tell, its recovery policy should preserve that uncertainty rather than pretend the operation did not occur. Our idempotency-key guide explores one way to connect repeated requests to a single intended operation.
Finally, test both sides of the boundary in a nonproduction environment: stop a worker before the side effect and again after the side effect but before deletion. The expected result should be written down before the test. The goal is not a reassuring “retry enabled” badge. It is a second attempt that either finishes the unfinished work or recognizes the work already done.
Explore Infinite Upside
For Vijay Sheth’s personal accounts, read Infinite Upside: Building Wealth With Room to Live, published by Sheth Capital, Inc.
Explore a related guide
What Is a Dead-Letter Queue?