Solving AWS Certified Solutions Architect - Associate Exam Question

Common Mistakes in Using Amazon SQS for Message Queuing

Prev Question Next Question

Question

Company ABC has an AWS setup and planning to use Amazon SQS for queuing messages.

The design is such that two applications will receive the same message in the queue and process it.

Once applications would have read the message, it should be deleted.

However, when the 2nd application makes the ReceiveMessage API call, the message is not getting returned.

Which of the following could be reasons? (Choose 2 options)

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

Answer: A, C.

Option A is correct.

Immediately after a message is received, it remains in the queue.

To prevent other consumers from processing the message again, Amazon SQS sets a visibility timeout, a period of time during which Amazon SQS prevents other consumers from receiving and processing the message.

The default visibility timeout for a message in 30 seconds.

The minimum is 0 seconds.

The maximum is 12 hours.

https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-visibility-timeout.html

Option B is not correct.

https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-visibility-timeout.html

Option C is correct.

Once the message is deleted from Amazon SQS Queue, it will not be available anymore.

Option D is not correct.

Permission exists on the Queue level, not on the message level.

For more information on SQS actions, refer to documentation here.

https://docs.aws.amazon.com/IAM/latest/UserGuide/list_amazonsqs.html
When a consumer receives and processes a message from a queue, the message remains in the queue. Amazon SQS doesn't automatically delete the message.
Because Amazon SQS is a distributed system, there's no guarantee that the consumer actually receives the message (for example, due to a connectivity issue, or due to
an issue in the consumer application). Thus, the consumer must delete the message from the queue after receiving and processing it.

The correct answers are A and C.

Explanation:

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 multiple applications to read messages from a single queue, but the following two issues may occur:

A. Application 2 is making a call before Visibility Timeout elapsed which was set by application 1 ReceiveMessage call.

When an application receives a message from an SQS queue using the ReceiveMessage API call, it sets a visibility timeout for that message. The visibility timeout is the amount of time that the message remains hidden from other applications after an application receives it. This timeout gives the first application time to process the message without the second application receiving it.

If the second application tries to receive the message before the visibility timeout has expired, it will not be able to receive the message, and the message will not be returned to the queue. In this case, the second application should wait until the visibility timeout has expired before attempting to receive the message.

B. Amazon SQS deletes the message once it has been responded via the ReceiveMessage call from Application 1.

Amazon SQS does not automatically delete a message when an application receives it. Instead, the application must explicitly delete the message from the queue after it has processed it. Therefore, this answer is incorrect.

C. Application 1 had deleted the message after it had been processed before Visibility Timeout elapsed.

If the first application deletes the message before the visibility timeout has expired, the message will not be visible to the second application, and the second application will not be able to receive the message. In this case, the second application should wait until the visibility timeout has expired before attempting to receive the message.

D. Application 2 does not have access to the message it is trying to receive.

If the second application does not have access to the message it is trying to receive, it will not be able to receive the message. However, this situation can occur due to permission issues, and it is not relevant to the scenario described in the question. Therefore, this answer is incorrect.

In summary, both options A and C could be reasons why the second application is not receiving the message, and the correct answers are A and C.