Soru

Zorluk: ZorMessage-Based Integration using Amazon SQS and SNS

A developer is building a video transcoding application where upload events are published to an Amazon SNS topic and fanned out to an Amazon SQS standard queue. A fleet of worker instances running on Amazon EC2 polls this queue to retrieve and transcode the videos. The transcoding process takes between 22 to 88 minutes per video depending on its file size. The SQS queue has a default Visibility Timeout of 55 minutes. The developer notices that during peak usage, larger videos that require more than 55 minutes to process are being transcoded multiple times by different EC2 worker instances.

Which of the following actions will resolve this issue and prevent duplicate transcoding?

  1. A
    Configure the Amazon EC2 workers to poll the queue using long polling by setting the `WaitTimeSeconds` parameter of the `ReceiveMessage` API call to 2020 seconds to keep the connection open during transcoding.
  2. Configure the worker application to call the `ChangeMessageVisibility` API to extend the message visibility timeout during transcoding, or increase the queue's default Visibility Timeout to 1010 minutes.Cevap
  3. C
    Convert the SQS standard queue to an SQS FIFO queue and enable content-based deduplication to prevent duplicate message retrieval by other worker instances.
  4. D
    Decrease the default Visibility Timeout of the SQS queue to 11 minute so that if a worker fails, other worker instances can immediately pick up the message and restart the transcoding.

Cevap

Configure the worker application to call the `ChangeMessageVisibility` API to extend the message visibility timeout during transcoding, or increase the queue's default Visibility Timeout to 1010 minutes.
The correct answer is to extend the visibility timeout dynamically using the `ChangeMessageVisibility` API or increase the default Visibility Timeout to a value larger than the maximum processing time. This ensures that the message remains hidden from other workers until the transcoding process completes and the worker deletes the message.

Adım Adım Çözüm

1
Identify the mismatch between the maximum processing time (88 minutes) and the queue's default Visibility Timeout (55 minutes).
Realize that any message taking longer than 55 minutes will become visible again while still being processed.
This explains why other workers are picking up and reprocessing the same video messages.
2
Evaluate SQS mechanisms for managing message visibility during processing.
Determine that increasing the default Visibility Timeout to 1010 minutes (greater than the 8-minute8\text{-minute} maximum) or calling `ChangeMessageVisibility` dynamically will keep the message hidden.
Keeping the message hidden prevents other consumers from retrieving it concurrently.
3
Ensure the worker deletes the message from the queue only after successful processing.
The message is safely deleted from the queue upon completion, avoiding reprocessing.
If processing fails, the message will eventually become visible again after the visibility timeout expires.

Anahtar Kavram

SQS Visibility Timeout Management

Alternatif Yöntem

Instead of a static visibility timeout, you can run a background thread within the worker that periodically calls `ChangeMessageVisibility` to heartbeat and extend the timeout in increments as long as the process is alive.
Tahmini Süre:2m 0s
Bu soruyu puanla