Scheduling Delayed Message Delivery in Amazon SQS

Scheduling Delayed Message Delivery

Prev Question Next Question

Question

Your team needs to develop an application that needs to make use of SQS queues.

There is a requirement that when a message is added to the queue, the message is not visible for 5 minutes to consumers.

How can you achieve this? Choose 2 answers from the options given below.

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

Answer - C and D.

The AWS Documentation mentions the following.

Delay queues let you postpone the delivery of new messages to a queue for several seconds.

If you create a delay queue, any messages you send to the queue remain invisible to consumers for the duration of the delay period.

The default (minimum) delay for a queue is 0 seconds.

The maximum is 15 minutes.

To set delay seconds on individual messages, rather than on an entire queue, use message timers to allow Amazon SQS to use the message timer's DelaySeconds value instead of the delay queue's DelaySeconds value.

Option A is invalid since this can only make the message invisible after the message has been read and not in the beginning.

Option B is invalid since this is used to reduce the cost of using Amazon SQS by eliminating the number of empty responses from SQS queues.

For more information on SQS delay queues, please refer to the below URL-

https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-delay-queues.html

To achieve the requirement of delaying visibility of messages for 5 minutes in SQS queues, we can make use of the following two options:

A. Increase the visibility timeout of the queue: The visibility timeout of an SQS message is the time period during which the message is invisible to consumers after being retrieved from the queue by a consumer. By default, the visibility timeout is set to 30 seconds, which means that after a consumer retrieves a message from the queue, the message is invisible to other consumers for the next 30 seconds. If the consumer doesn't delete the message within this period, it will become visible to other consumers after the timeout period expires.

To achieve the requirement, we can increase the visibility timeout of the SQS queue to 5 minutes (300 seconds). This will ensure that the messages added to the queue are not visible to consumers for the next 5 minutes.

B. Implement delay queues in AWS: Delay queues are a feature of Amazon SQS that enables you to postpone the delivery of new messages to a queue for a specified number of seconds. This means that messages sent to a delay queue aren't immediately available to consumers. Instead, they're held for the specified delay period, after which they become available to consumers.

To achieve the requirement, we can create a delay queue in SQS and set the delay period to 5 minutes. When messages are sent to this queue, they will not be visible to consumers for the next 5 minutes. Once the delay period is over, the messages will become visible to consumers.

Note: Option D is not a valid solution as changing the message timer value for each individual message would be cumbersome and error-prone, especially if the number of messages is large. Similarly, option B (Implement long polling for the SQS queue) is not directly related to delaying the visibility of messages, although it can help reduce the number of requests to the queue and improve efficiency.