A logistics company uses a fleet of Amazon ECS tasks to process shipment tracking updates. The tasks poll messages from an Amazon SQS standard queue, retrieve the payload, and update an Amazon RDS database. The queue's default visibility timeout is configured to seconds. Most updates are processed within seconds; however, updates requiring complex database transactions can take up to seconds. During peak hours, the developer notices that complex updates are processed multiple times, causing duplicate entries in the database. Which solution will resolve this issue in the most efficient and resilient manner?
- Modify the ECS task application to call the ChangeMessageVisibility API action using the message's receipt handle to extend the visibility timeout when processing exceeds the threshold.Answer
- BIncrease the default visibility timeout of the SQS queue to seconds to accommodate the longest possible database transaction.
- CConvert the standard SQS queue to an SQS FIFO queue and enable content-based deduplication to prevent other consumers from receiving the same update.
- DModify the ECS task application to delete the message from the queue immediately after retrieval, then process the database transaction.
Answer
Modify the ECS task application to call the ChangeMessageVisibility API action using the message's receipt handle to extend the visibility timeout when processing exceeds the threshold.
The correct answer is to modify the application code to call the ChangeMessageVisibility API action. When a consumer needs more time to process a message than the queue's default visibility timeout, calling ChangeMessageVisibility dynamically extends the timeout for that specific message using its receipt handle. This prevents other consumers from receiving it while it is actively being processed, without affecting the default visibility timeout of the queue. Keeping the default timeout at seconds ensures that if other consumers fail during standard -second updates, those messages will quickly become available for retry.
Step-by-Step Solution
Key Concept
Amazon SQS Visibility Timeout and ChangeMessageVisibility API