A developer is building a video translation system where upload events are published to an Amazon SNS topic. The events are fanned out to an Amazon SQS standard queue, which is polled by a fleet of containerized workers running on Amazon ECS. Each video transcription job takes between 2 to 5 minutes to complete, but occasionally takes up to 12 minutes for larger files. The default visibility timeout of the SQS queue is configured to 3 minutes. During peak traffic, the developer notices that some videos are transcribed multiple times, resulting in duplicate outputs and wasted compute resources.
Which of the following actions should the developer take to resolve this issue in a secure and efficient manner?
- ADecrease the default visibility timeout of the SQS queue to 1 minute to ensure that if a worker fails, another worker immediately picks up the message.
- BMigrate the transcription logic to an AWS Lambda function with the default timeout, relying on the reuse of the execution context to persist and complete the 12-minute transcription across separate invocations.
- Modify the ECS worker to call the ChangeMessageVisibility API to dynamically extend the message's visibility timeout during transcription, or increase the default visibility timeout of the SQS queue to 13 minutes.Answer
- DImplement a helper in the ECS worker to call the ChangeMessageVisibility API, initializing the SQS client by hardcoding an IAM User's access key and secret access key in the source code to ensure proper authentication.
Answer
Modify the ECS worker to call the ChangeMessageVisibility API to dynamically extend the message's visibility timeout during transcription, or increase the default visibility timeout of the SQS queue to 13 minutes.
The correct option addresses the duplicate processing issue by ensuring that the SQS message remains invisible to other consumers while it is actively being processed. By increasing the SQS queue's default visibility timeout to 13 minutes (which is greater than the maximum potential processing time of 12 minutes) or using the ChangeMessageVisibility API to dynamically extend the visibility of a message while work is in progress, the developer prevents other workers from picking up and processing the same message concurrently.
Step-by-Step Solution
Key Concept
Understanding and configuring SQS visibility timeouts to align with application processing times, and dynamically managing message visibility using the AWS SDK.