Question

Difficulty: MediumMessage-Based Integration using Amazon SQS and SNS

A developer is writing a Node.js ingestion service that runs on AWS Fargate to receive telemetry events from IoT devices and write them to an Amazon SQS standard queue. Currently, the service invokes the SendMessage API for each event immediately. During peak hours, the service experiences high latency and increased costs due to the volume of API calls. The developer wants to optimize the application to minimize both API costs and network overhead when publishing messages. How should the developer configure the SDK client or application logic to achieve this?

  1. Implement client-side buffering to group events and write them to the queue using the SendMessageBatch API with a maximum batch size of 10 messages.Answer
  2. B
    Enable SQS Long Polling on the queue by setting ReceiveMessageWaitTimeSeconds to 20 to allow the producer SDK client to automatically aggregate messages before transmission.
  3. C
    Increase the VisibilityTimeout configuration of the SQS queue to provide additional time for the producer client to batch messages.
  4. D
    Re-initialize the SQS client inside the request handler function context for each incoming event to ensure clean TCP connection pooling.

Answer

Implement client-side buffering to group events and write them to the queue using the SendMessageBatch API with a maximum batch size of 10 messages.
The correct answer is to implement client-side buffering and use the SendMessageBatch API. This API allows writing up to 10 messages (or up to 256 KB total size) in a single request, directly reducing the API costs (which are charged per request) and minimizing HTTP/HTTPS connection overhead on the producer side.

Step-by-Step Solution

1
Analyze the bottleneck of the producer application.
The application sends individual requests per message, leading to high SQS write request costs and HTTP connection overhead.
Before implementing changes, we must identify that the high latency and cost are due to the frequency of SQS write APIs rather than consumer processing times.
2
Identify the appropriate Amazon SQS producer optimization API.
The SendMessageBatch API accepts up to 10 messages or 256 KB of total payload.
This allows aggregating multiple messages into a single HTTP request to optimize cost and network usage.
3
Differentiate between producer-side and consumer-side configurations.
ReceiveMessageWaitTimeSeconds and VisibilityTimeout are eliminated since they configure consumer read operations.
To ensure the correct choice, the developer must recognize that long polling and visibility timeout have no impact on writing messages.

Key Concept

Amazon SQS Producer Batching and SDK Client Best Practices
Estimated Time:1m 30s
Rate this question