Correct Answer - C.
Visibility Timeout is a period during which Amazon SQS prevents other consumers from receiving and processing the message.
In the above requirement, the application takes 45 secs to process each message.
So Visibility Timeout should be greater than 45 seconds.
Hence, setting visibility timeout as 60 seconds is the correct option.
Option A is incorrect.
Even though setting Amazon SQS Visibility timeout to 43200 seconds will work, it will add delay as it must wait for 12 hours if initial message processing fails.
Option B is incorrect since message processing takes 45 secs.
Setting a visibility timeout of 0 seconds will increase duplicate messages as other consumers will start processing the same message when the first consumer is processing it.
Option D is incorrect since message processing takes 45 secs.
Setting a visibility timeout of 30 seconds will increase duplicate messages as other consumers will start processing the same message when the first consumer is processing it.
For more information on visibility timeout on Amazon SQS, refer to the following URL-
https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/working-with-messages.html#processing-messages-timely-manner
To answer this question, we need to understand the role of Amazon SQS and visibility timeout in processing messages.
Amazon Simple Queue Service (SQS) is a fully managed message queuing service that enables you to decouple and scale microservices, distributed systems, and serverless applications. It allows you to send, store, and receive messages between software components at any volume, without losing messages or requiring other services to be available.
When you send a message to an SQS queue, it is stored in the queue until a consumer retrieves it. When a consumer retrieves a message from a queue, the message becomes invisible to other consumers for a configurable period known as the visibility timeout. During this time, the consumer processes the message and then either deletes it from the queue or returns it to the queue if processing fails. If the message is not deleted or returned before the visibility timeout expires, it becomes visible to other consumers again.
In this scenario, the decoupled application uses Amazon SQS to store messages before being processed by another application on an EC2 instance. However, there is a surge in the number of messages being processed, and most of them are duplicates. If the application takes approximately 45 seconds to process each message, we need to adjust the visibility timeout to avoid processing duplicate messages.
Option A: Configure Amazon SQS Visibility timeout to 43200 seconds. Setting the visibility timeout to 43200 seconds (12 hours) is not a good option because it is too long. If a consumer takes more than 12 hours to process a message, it will become visible again, and other consumers will try to process it, resulting in duplicate processing. This option would not address the problem of duplicate messages being processed.
Option B: Configure Amazon SQS Visibility timeout to 0 seconds. Setting the visibility timeout to 0 seconds is also not a good option because it would make the messages immediately visible to all consumers, resulting in multiple consumers processing the same message at the same time, which would lead to concurrency issues and data inconsistency.
Option C: Configure Amazon SQS Visibility timeout to 60 seconds. Setting the visibility timeout to 60 seconds is a better option because it gives the consumer enough time to process the message without making it visible to other consumers. This way, if a consumer fails to process the message within the timeout period, the message will become visible again, and another consumer can try to process it. This option would reduce the number of duplicate messages being processed.
Option D: Configure Amazon SQS Visibility timeout to default to 30 seconds. The default visibility timeout for SQS is 30 seconds, which means that if we do not explicitly set the visibility timeout, messages will become visible again after 30 seconds. This option would be similar to Option C, but with a shorter visibility timeout period. It could be used if the application can process messages within 30 seconds, but in this scenario, the application takes 45 seconds to process each message.
Therefore, Option C would be the best option to configure the Amazon SQS visibility timeout to 60 seconds to reduce the number of duplicate messages being processed while giving the consumer enough time to process the message.