Context
Receiving an SQS message makes it temporarily invisible to other consumers. The message still exists until a consumer successfully deletes it. Visibility is therefore a processing lease, not proof of completion. If work outlasts that lease, another consumer can receive the message while the first worker is still active.
Establish the worker timeline
Record the queue URL, queue type, default visibility timeout, consumer configuration, processing-duration distribution and deletion behavior. Identify the durable business effect produced by a message and the idempotency key used to recognize repeat attempts. Use a test queue with representative processing delays.
Capture receive time, operation identifier, commit time and deletion result in telemetry without logging message secrets or receipt handles. A message ID can help correlate delivery, but it is not the handle required for deletion.
1. Compare visibility with actual processing
Measure the full interval from receipt to durable business completion and deletion. Include time spent waiting for worker slots or downstream systems. A batch consumer that receives many messages before it can process them may consume visibility time before useful work begins.
Inspect long-tail duration rather than only the average. Choose a baseline that allows normal completion without delaying recovery unnecessarily when a worker crashes. Avoid selecting a very long timeout merely to hide duplicates; a failed worker then leaves work unavailable for longer.
2. Implement a bounded extension policy
For variable-duration work, use the supported ChangeMessageVisibility operation while the worker still owns the current receipt. Schedule the heartbeat before the existing lease expires, handle extension failures explicitly, and stop extending when the business operation is complete or abandoned.
AWS limits total visibility to twelve hours from the receive request; extensions do not reset that boundary. Break very long jobs into durable stages or choose an orchestration design suitable for their duration. Keep duplicate protection even with heartbeats because the delivery model does not promise that visibility eliminates every repeat.
3. Investigate receipt and deletion evidence
| Evidence | Explanation to test | Corrective direction |
|---|---|---|
| Repeat arrives before first commit | Work outlasts visibility | Adjust processing or extension policy |
| Delete uses message ID | Wrong identifier | Use the current receipt handle |
| Old receipt used after another receive | Delivery ownership changed | Track latest receipt per attempt |
| Consumers receive nothing with high in-flight count | Capacity tied up by leases | Inspect active work and deletion |
An explicitly illustrative scenario: a document worker usually finishes quickly but waits several minutes when a conversion service is busy. A second worker receives the same message after visibility expires and starts another conversion. The team adds a bounded heartbeat and records completion by document-operation ID. A duplicate delivery then observes the completed operation rather than generating another output.
Correct and verify recovery behavior
Test normal completion, slow completion, worker crash and extension failure in the controlled queue. Verify that successful work is deleted only after its durable effect is recorded. When a worker dies, confirm that another worker can recover after the intended delay and that repeat processing does not duplicate the business effect.
The SOP should define lease ownership, heartbeat timing, processing deadlines, idempotency storage and incident handling for high in-flight counts. Monitor oldest-message age, visible and not-visible messages, processing latency and deletion errors together. Revisit visibility after changes to batch size or downstream latency, because the lease covers the entire consumer timeline.
Explore Clouvenix managed infrastructure for implementation and operational handover.
Technical reference
SQS visibility behavior, receipt handles, and visibility changes define lease management.