Question

Difficulty: HardMessage-Based Integration using Amazon SQS and SNS

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 4545 seconds. Most updates are processed within 1515 seconds; however, updates requiring complex database transactions can take up to 120120 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?

  1. 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
  2. B
    Increase the default visibility timeout of the SQS queue to 150150 seconds to accommodate the longest possible database transaction.
  3. C
    Convert the standard SQS queue to an SQS FIFO queue and enable content-based deduplication to prevent other consumers from receiving the same update.
  4. D
    Modify 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 4545 seconds ensures that if other consumers fail during standard 1515-second updates, those messages will quickly become available for retry.

Step-by-Step Solution

1
Analyze the cause of duplicate processing.
Since complex updates take 120120 seconds and the SQS default visibility timeout is only 4545 seconds, the visibility timeout expires before the task completes and deletes the message. This makes the message visible to other ECS tasks, which retrieve and process it, leading to duplicates.
Understanding the mismatch between default visibility timeout and processing time is critical to selecting the correct resolution.
2
Evaluate the trade-offs of modifying queue configurations vs client-side changes.
Increasing the default visibility timeout statically to 150150 seconds resolves the duplicates but slows down recovery for failed 1515-second tasks. Converting to FIFO doesn't solve consumption timeout issues.
Resolving the issue in a resilient and efficient manner requires avoiding configurations that negatively impact standard processing latency.
3
Apply dynamic visibility timeout management.
The application can monitor processing time and call ChangeMessageVisibility on demand using the message's receipt handle to extend visibility only for the specific complex tasks.
This is the AWS-recommended best practice for SQS queues with highly variable processing times.

Key Concept

Amazon SQS Visibility Timeout and ChangeMessageVisibility API
Rate this question