In this lecture, we explore an essential concept in Amazon Simple Queue Service (SQS): Message Visibility Timeout. This mechanism controls how messages are temporarily hidden from other consumers while being processed.
🔹 What is Message Visibility Timeout?
When a consumer retrieves a message from an SQS queue using the ReceiveMessage API, that message becomes temporarily invisible to other consumers. This is called the visibility timeout.
📌 Key Behavior:
- The default visibility timeout is 30 seconds.
- During this period, other consumers cannot retrieve the same message.
- If the message is not deleted before the timeout expires, it reappears in the queue, making it available to other consumers.
🛠Example: Message Visibility in Action
Step 1: Message Retrieval
- A consumer (A) polls the SQS queue and receives a message.
- The visibility timeout begins (e.g., 30 seconds).
Step 2: Message Processing
- If consumer A processes and deletes the message within 30 seconds, the message is permanently removed.
- If consumer A fails to delete the message, it becomes visible again after 30 seconds and another consumer (B) can retrieve it.
Step 3: Duplicate Processing Scenario
- If consumer A is slow and does not complete processing within 30 seconds, the message may be picked up again by another consumer (B).
- This can lead to duplicate message processing, which is often undesirable.