Soru

Zorluk: Çok zorMessage-Based Integration using Amazon SQS and SNS

A developer is designing a real-time ticketing system for high-demand concert sales. The booking requests are published to an Amazon SNS FIFO topic, which fans out to an Amazon SQS FIFO queue. An AWS Lambda function processes messages from the SQS FIFO queue in batches of up to 1010 messages.

During high-traffic events, some payments fail temporarily due to external payment provider rate limits, causing the Lambda function to return an error. The developer notices that when a single booking message fails in a batch, the entire batch of 1010 messages is retried. This leads to redundant processing of successfully authorized bookings in the same batch and blocks messages belonging to other users' sessions from being processed.

Which combination of configuration changes should the developer implement to resolve this issue, ensuring that only failed messages are retried while maintaining strict message ordering for each user?

  1. Configure the SQS FIFO queue as a Lambda trigger with `ReportBatchItemFailures` enabled in the event source mapping. Modify the Lambda function to catch exceptions during processing, accumulate failed message IDs, and return them in a `batchItemFailures` array. Set the `MessageGroupId` to the user's session ID when publishing to the SNS FIFO topic.Cevap
  2. B
    Increase the Visibility Timeout of the SQS FIFO queue to at least 66 times the Lambda function timeout. Change the Lambda function trigger concurrency limit to 11 to prevent overlapping executions, and configure the SQS FIFO queue to use the user's session ID as the `MessageDeduplicationId`.
  3. C
    Configure the SQS FIFO queue to send failed messages to a standard SQS Dead Letter Queue (DLQ) after a `maxReceiveCount` of 33. Modify the Lambda function to run with a reserved concurrency of 11, and ensure the message payload does not exceed the SQS maximum size limit.
  4. D
    Migrate the integration to use an Amazon Kinesis Data Stream instead of SQS FIFO. Publish the booking events to the stream using a static string constant as the partition key to guarantee ordering. Configure the Lambda function to process the stream with a custom retry policy.

Cevap

Configure the SQS FIFO queue as a Lambda trigger with `ReportBatchItemFailures` enabled, catch processing exceptions to return failed message IDs in `batchItemFailures`, and use the user's session ID as the `MessageGroupId` when publishing to the SNS FIFO topic.
The correct configuration combining `ReportBatchItemFailures` with a session-based `MessageGroupId` resolves both the batch retry issue and the head-of-line blocking problem. By returning the failed message IDs in `batchItemFailures`, AWS Lambda deletes the successfully processed messages from the SQS FIFO queue and only retries the failed messages. Using the user's session ID as the `MessageGroupId` preserves strict message ordering within each session while allowing different sessions to be processed concurrently across multiple Lambda scaling instances.

Adım Adım Çözüm

1
Enable partial batch response support for SQS in AWS Lambda.
The Lambda event source mapping configuration is updated with `FunctionResponseTypes` set to `ReportBatchItemFailures`.
This allows Lambda to recognize custom responses indicating partial batch success/failure instead of treating the entire batch as a failure.
2
Modify the Lambda function code to catch errors at the individual message level.
The code wraps message processing in a try-catch block. Successfully processed messages are handled, and failed message IDs are collected into a `batchItemFailures` JSON structure.
This prevents a single failed message from throwing an unhandled exception that would fail the entire Lambda execution and force a retry of all 1010 messages.
3
Use the user's session ID as the Message Group ID on SNS FIFO.
Messages are grouped by session ID, ensuring that order is strictly preserved within each user session while enabling independent user sessions to run in parallel.
This avoids head-of-line blocking across different users while maintaining sequential processing of booking events per individual user.

Anahtar Kavram

Handling partial batch failures in SQS FIFO queues triggered by AWS Lambda while maintaining per-session message ordering.
Bu soruyu puanla