0 votes
in AWS by

You've been hired as a developer to work on an application.

This application is hosted on an EC2 Instance and interacts with an SQS queue.

It's been noticed that when the application is pulling messages, a lot of empty responses are being returned.

What change can you make to ensure that the application uses the SQS queue effectively?

1 Answer

0 votes
by

Answer - A.

Option B is invalid because this is valid only for the processing time for the Messages.

Option C is invalid because this would not be a cost-effective option.

Option D is invalid because this is not a practice for SQS queues.

The AWS Documentation mentions the following.

Long polling helps reduce the cost of using Amazon SQS by eliminating the number of empty responses (when there are no messages available for a ReceiveMessagerequest) and false empty responses (when messages are available but aren't included in a response).

For more information on long polling in SQS, please refer to the below link-

https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-long-polling.html

The best answer for this scenario is A. Use long polling.

Here's why:

When an application pulls messages from an SQS queue, it can either use short polling or long polling.

Short polling is the default behavior. In this approach, the application sends a request to the SQS queue, and if there is a message available, the queue returns it immediately. If there is no message available, the queue returns an empty response. Short polling is not the most efficient way to interact with an SQS queue because it can result in a lot of empty responses being returned, as the application is constantly checking the queue for new messages.

Long polling is an alternative approach to interacting with an SQS queue. In this approach, the application sends a request to the queue, but instead of immediately returning an empty response if there is no message available, the queue waits for a specified amount of time for a message to become available. If a message is available during that time, the queue immediately returns it to the application. If no message becomes available during that time, the queue returns an empty response.

By using long polling, the application can reduce the number of empty responses it receives from the SQS queue. This is because the queue is actively waiting for a message to become available before returning a response to the application. This approach can improve the performance of the application and reduce the load on the SQS queue.

Option B, "Set a custom visibility timeout," is not the best answer to this scenario because it does not address the issue of empty responses being returned from the SQS queue. Visibility timeout is the amount of time that a message is hidden from other consumers after it has been consumed. This option may be useful if the issue was related to messages being consumed too quickly, but it does not address the issue of empty responses.

Option C, "Use short polling," is not the best answer to this scenario because it is the default behavior and is the cause of the issue the application is experiencing. Using short polling would not solve the problem of empty responses being returned from the SQS queue.

Option D, "Implement exponential backoff," may be useful in some scenarios but does not address the issue of empty responses being returned from the SQS queue. Exponential backoff is a technique used to retry failed requests with progressively longer wait times between each attempt. This option may be useful if the application is experiencing errors or timeouts, but it does not address the issue of empty responses.

...