A Web-application uses Amazon SQS to buffer messages processed by another application deployed in a fleet of Amazon EC2 instances.
Application deployed on Amazon EC2 instances sends message confirmation to end-users.
Due to the heavy load on Amazon EC2 instances, it takes a long time to process messages & users are receiving multiple messages.
Which of the following changes can be done on the Amazon SQS queue to ensure users receive only a single message?
Click on the arrows to vote for the correct answer
A. B. C. D.Correct Answer - A.
Visibility Timeout is used to hide messages from other consumers when one of the consumers is processing the message.
In the above case, when one of the Amazon EC2 instances is processing messages from the Amazon SQS queue, it takes time to process messages due to load on the instance.
Within that time period, visibility timeout is expired & another EC2 instance is processing the same message & sending updates to users.
To avoid multiple processing of the same message, the Visibility timeout can be increased so that Amazon EC2 processes the message before the visibility timeout expires.
Option B & D are incorrect as UpdateMessageVisibility is an invalid option to change the visibility timeout.
Option C is incorrect as decreasing visibility timeout will not resolve the issue.
For more information on visibility timeout with Amazon SQS, refer to the following URL-
https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-visibility-timeout.htmlThe scenario described involves a web application that uses Amazon SQS to buffer messages that are processed by an application deployed on a fleet of EC2 instances. The application deployed on EC2 instances sends message confirmation to end-users. However, due to the heavy load on the EC2 instances, it takes a long time to process messages, and end-users are receiving multiple messages.
To ensure that end-users receive only a single message, we need to modify the behavior of the Amazon SQS queue. Specifically, we need to adjust the visibility timeout of the queue. The visibility timeout is the amount of time that a message remains hidden from other consumers after it has been retrieved by a consumer. During this time, the message is processed by the consumer, and if the processing is successful, the message is deleted from the queue.
If multiple consumers retrieve the same message from the queue simultaneously, they will attempt to process it independently, resulting in multiple messages being sent to the end-users. By increasing the visibility timeout, we can prevent other consumers from retrieving the same message while it is being processed.
Option A and B suggest increasing the visibility timeout to 5 minutes, which would allow more time for the messages to be processed before they become visible to other consumers. Both ChangeMessageVisibility and UpdateMessageVisibility APIs can be used to modify the visibility timeout. However, ChangeMessageVisibility is used to change the visibility timeout of a single message, whereas UpdateMessageVisibility is used to change the visibility timeout of multiple messages or all messages in a queue.
Option C and D suggest decreasing the visibility timeout to 2 minutes. However, this would not necessarily prevent end-users from receiving multiple messages, as it would allow messages to become visible to other consumers sooner, potentially resulting in multiple consumers processing the same message.
Therefore, the correct answer is either A or B, depending on the specific requirement of the scenario. If the processing time of messages is expected to be longer than 5 minutes, increasing the visibility timeout to 5 minutes using either ChangeMessageVisibility or UpdateMessageVisibility would be an appropriate solution to prevent end-users from receiving multiple messages.