Q5 — AWS SAA-C03 Ch.1

Question 5 of 65 | ← Chapter 1

Q5. A company hosts an application on multiple Amazon EC2 instances. The application processes messages from an Amazon SQS queue writes to an Amazon RDS table and deletes the message from the queue Occasional duplicate records are found in the RDS table.The SQS queue does not contain any duplicate messages. What should a solutions archived do to ensure messages are being processed once only?

Correct Answer: D. Use the ChangeMessageVisibility API call to increase the visibility timeout

Explanation

Q5. Given that a company's application processes messages from an Amazon SQS queue, writes to an Amazon RDS table, and occasionally finds duplicate records in the RDS table despite no duplicates in the SQS queue, the key issue is ensuring that each message is processed only once.Let's analyze the options:A. Use the CreateQueue API call to create a new queue - This would simply create a new SQS queue, but it does not address the issue of duplicate message processing. Creating a new queue does not change how messages are processed or ensure that messages are processed only once.B. Use the AddPermission API call to add appropriate permissions - Adding permissions to the SQS queue controls who can send or receive messages from the queue. It does not affect how messages are processed or ensure message idempotency (the property of an operation that can be executed multiple times without changing the result beyond the initial execution).C. Use the ReceiveMessage API call to set an appropriate wait time - The ReceiveMessage API call allows you to retrieve messages from the queue, but setting the wait time does not ensure that messages are processed only once. The wait time controls how long the API call waits for a message to arrive before returning an empty result.D. Use the ChangeMessageVisibility API call to increase the visibility timeout - While increasing the visibility timeout (the time during which Amazon SQS prevents other consumers from receiving and processing the message) can help prevent other consumers from processing the same message concurrently, it's not the direct solution to the duplicate processing issue. However, in combination with a robust message processing strategy, it can be part of the solution.The key to ensuring that messages are processed only once is to implement a message processing strategy that involves:Idempotent operations: Ensure that the operations performed by the application (e.g., writing to the RDS table) are idempotent, meaning they can be executed multiple times without changing the result beyond the initial execution.Deduplication at the application level: Implement logic within the application to detect and handle duplicate messages. This can involve checking for the existence of a record in the RDS table before inserting a new one.Use of message attributes and message IDs: SQS messages have a unique MessageId that can be used to track which messages have been processed. Storing these IDs in the RDS table (or another storage solution) can help identify duplicates.Properly managing the visibility timeout: Increasing the visibility timeout can give the application more time to process the message and delete it from the queue before it becomes visible to other consumers. However, it's essential to ensure that the application deletes the message from the queue once processing is complete.Given the options provided, none directly addresses the root cause of duplicate processing. However, if we had to choose the most relevant step in a comprehensive solution, it would be to ensure that the application logic handles duplicates appropriately, potentially in conjunction with using the ChangeMessageVisibility API call to manage the visibility timeout. However, the question is asking for a direct action, and in this context, the closest option is:Ensuring that the application's message processing logic is robust enough to handle duplicates, which indirectly involves properly managing the message lifecycle, including the visibility timeout.Given the strictness of the question and the options provided, a more accurate response would be to explain the need for a combination of strategies, including idempotent operations, deduplication at the application level, and proper message lifecycle management. However, if we must choose one option, it's worth noting that none of the provided API calls directly solve the duplicate processing issue. Instead, focus on the application logic and process design.For the sake of the question's format, a close interpretation might be:D. Use the ChangeMessageVisibility API call to increase the visibility timeout - While not the complete solution, increasing the visibility timeout can be part of a strategy to give the application more time to process the message and ensure it's deleted from the queue, thereby reducing the chances of duplicate processing. However, it's essential to couple this with idempotent operations and deduplication logic within the application.