Engineering Analysis · Global
Test your SQS worker when its message becomes visible again
A queue visibility timeout buys time, not sole ownership. Test a slow job and a crash after the work is committed.
By Launchr Space ·
A customer requests a report. The worker starts rendering, the job takes longer than usual, and then a second worker picks up the same message. Raising the visibility timeout may lower the odds of that particular race. It does not tell either worker whether the other already uploaded or announced the report.
An Amazon SQS message stays in the queue while it is hidden after receipt. Unless a worker deletes it, the message can become visible again once that period expires. A consumer can extend the timeout for an in-flight message. AWS also documents a maximum of twelve hours from first receipt, not a new twelve-hour window every time the consumer extends it.
Choose a time range from observed jobs
Measure how long a typical job takes from receipt to the point where both the work and its durable record are complete. Look separately at large jobs, transient storage failures, and dependencies with known throttling. Use a reasonable initial timeout; for genuinely variable work, renew it while the worker still has evidence it is making progress. A very long timeout delays pickup when the worker dies. A very short one can set off a wave of duplicate work.
Design for two workers, even if you run one today
Give each logical job a stable business identifier. Keep one durable record of whether it has committed its result. Make an upload safe to repeat, or use a guarded commit so two workers cannot both publish completion. Delete the queue message only after the result is durable. A crash after the commit but before deletion should be a repeat delivery that does no new customer-visible work. Use a dead-letter queue for repeated failures and define how operators inspect and replay them.
Prove the failure path
In staging, let one worker miss a renewal and have a second worker receive the same job. Then stop a worker after it has committed the report but before it acknowledges the queue. Each test should leave one final result and one customer notification. Watch the oldest waiting messages and repeated receives. If a single phase routinely needs hours, split the workflow into durable stages instead of stretching one receipt indefinitely.