Messagingack deadlinemessage leaseinvisibility timeout

Visibility timeout

Definition

A visibility timeout is the period after a consumer receives a message during which the broker hides it from other consumers. Acknowledging deletes it; letting the timeout expire returns it to the queue.

In practice

The timeout is how a queue survives consumer crashes without losing work: a worker that dies mid-task never acks, the timeout runs out, and another worker picks the message up. SQS calls it the visibility timeout; Pub/Sub uses ack deadlines and other systems speak of leases, but the idea is the same.

Set it longer than the slowest normal processing time. Too short and healthy jobs are redelivered while still running, so two workers do the same job; too long and real failures take ages to retry. Long tasks should extend the timeout periodically as a heartbeat, and the receive count should send poison messages to a dead letter queue.

Example

With a 30-second visibility timeout, a report job that takes 45 seconds is picked up by a second worker at 30 seconds; raising it to 120 seconds and extending it every 60 seconds stops the duplicates.