I am taking an AWS course and trying to understand how the AWS SQS (Simple Queue Service) works. I am a little bit confused by the visibility timeout. I know that visibility timeout is the duration for a message to be processed within.
This is the model
As you can see in the diagram, the consumer will pull the message or the messages and process the message or the messages within the visibility timeout. If the message or the messages are not processed within the visibility timeout, the consumer will not receive or process the message or the messages and the messages will remain in the queue.
The followings are my confusions:
Is the visibility timeout valid for all the messages together in one poll? Or the timeout is applied to each message separately? For example, the consumer polls 5 messages at a time. If 2 of them are not processed within the timeout, 2 of them are sent back to the queue and the other three are deleted. Or all the 5 messages are processed within a timeout and if any of them failed, all of them get sent back to the queue.
This is my second confusion. How is the visibility timeout valid? Is that for the time the consumer starts polling messages and receive the messages? Or is that valid for the time the consumer starts polling messages and finish processing messages on the consumer end (for example, saving messages into the database)?