Question

Difficulty: HardMessage-Based Integration using Amazon SQS and SNS

A developer is designing a real-time multiplayer gaming application where match event messages must be processed by different backend microservices. The match events must be processed in the exact order they occur per match, and duplicate messages must be avoided. The developer publishes the events to an Amazon SNS FIFO topic, which fans out to multiple Amazon SQS FIFO queues subscribed to the topic. During testing, the developer observes that the player achievements service, which runs on AWS Lambda and takes up to 4545 seconds to process certain messages, occasionally receives and processes duplicate match events. The SQS FIFO queue's visibility timeout is currently configured to 3030 seconds. Which modification should the developer make to resolve this issue?

  1. Increase the visibility timeout of the Amazon SQS FIFO queue to 60 seconds to ensure it exceeds the maximum processing time of the Lambda function.Answer
  2. B
    Decrease the Lambda function's timeout to 25 seconds to force it to complete before the queue's visibility timeout is reached.
  3. C
    Convert the Amazon SQS FIFO queue to a standard queue and configure long polling with a ReceiveMessageWaitTimeSeconds parameter set to 20 seconds.
  4. D
    Reconfigure the publisher to send messages to an Amazon Kinesis Data Stream instead, using a static partition key for all match events.

Answer

Increase the visibility timeout of the Amazon SQS FIFO queue to 60 seconds to ensure it exceeds the maximum processing time of the Lambda function.
Increasing the SQS visibility timeout to 60 seconds is the correct solution. Since the Lambda function takes up to 45 seconds to process a message, a 30-second visibility timeout results in the message returning to the queue before the processing is complete. A 60-second visibility window ensures the message is successfully deleted from the queue before it becomes visible again.

Step-by-Step Solution

1
Analyze the relationship between the consumer processing duration and the SQS visibility timeout.
The Lambda function takes up to 4545 seconds to process messages, but the SQS visibility timeout is only 3030 seconds.
If the processing time exceeds the visibility timeout, SQS assumes the consumer failed and makes the message visible to other pollers, resulting in duplicate processing.
2
Identify the target visibility timeout configuration.
The visibility timeout must be set to a value greater than the maximum expected processing time (e.g., 6060 seconds).
This guarantees that the message remains hidden until the current Lambda execution completes and deletes the message from the queue.
3
Evaluate the architectural constraints of FIFO queues.
FIFO ordering is maintained, and duplicate processing is prevented by aligning the visibility timeout with the worker runtime.
Unlike standard queues, FIFO queues guarantee exactly-once processing and strict ordering, which would be compromised if converted to standard queues.

Key Concept

SQS Visibility Timeout vs. Consumer Processing Time
Rate this question