Soru

Zorluk: ZorMessage-Based Integration using Amazon SQS and SNS

A developer is building an order processing system. A frontend application publishes order events to an Amazon SNS FIFO topic. An Amazon SQS FIFO queue is subscribed to the topic. An AWS Lambda function is configured to process messages from the queue. The Lambda function has a timeout of 4545 seconds.

During testing under heavy load, the developer notices two issues:
1. Some orders are processed multiple times by different Lambda invocations even though the Lambda function executes successfully without errors.
2. Multiple distinct orders submitted by the same customer in rapid succession are being discarded by the SQS FIFO queue.

Which TWO actions should the developer take to resolve these issues?

  1. Modify the publisher application to construct the MessageDeduplicationId using a combination of the customer ID and a unique order ID, rather than using only the customer ID.Cevap
  2. Set the Amazon SQS queue's visibility timeout to a value that is at least 66 times the Lambda function timeout, such as 270270 seconds.Cevap
  3. C
    Increase the Lambda function's execution timeout to 9090 seconds to give it more time to process batches without changing the SQS queue settings.
  4. D
    Configure a unique partition key for each customer on the SQS FIFO queue to distribute the processing load across multiple consumers.
  5. E
    Hardcode the AWS Access Key ID and Secret Access Key of a policy-restricted IAM user in the Lambda function initialization code to initialize the SQS client.

Cevap

Modify the publisher application to construct the MessageDeduplicationId using a combination of the customer ID and a unique order ID, and set the Amazon SQS queue's visibility timeout to a value that is at least 66 times the Lambda function timeout.
To resolve the duplicate processing issue, the SQS visibility timeout must be at least 66 times the Lambda function timeout (270270 seconds) so that active executions have ample time to finish and delete messages before they are made visible to other consumers. To resolve the discarded orders issue, the MessageDeduplicationId must be uniquely constructed using a combination of customer ID and order ID rather than just the customer ID, ensuring distinct messages are not incorrectly filtered out during the 55-minute deduplication window.

Adım Adım Çözüm

1
Address the duplicate processing issue.
Identify that if the SQS visibility timeout is not long enough compared to the Lambda function timeout, messages can become visible again while being processed. Under AWS integration best practices, the queue's visibility timeout must be set to at least 66 times the timeout of the Lambda function (which is 6×45=2706 \times 45 = 270 seconds) to prevent duplicate processing.
This guarantees that the Lambda function has sufficient time to process the messages and delete them from the queue before they become visible to other consumers.
2
Address the discarded orders issue.
Identify that SQS FIFO queues use the MessageDeduplicationId to deduplicate messages within a sliding 55-minute window. Since multiple distinct orders from the same customer used only the customer ID as the deduplication ID, they were discarded as duplicates.
Constructing the deduplication ID using a combination of the customer ID and a unique order ID makes each transaction event unique, ensuring that legitimate orders are not discarded.

Anahtar Kavram

Managing SQS visibility timeout relative to Lambda timeouts and configuring proper MessageDeduplicationId for SQS FIFO queues.
Bu soruyu puanla