Soru

Zorluk: OrtaStream Processing and Event Routing with Amazon Kinesis and EventBridge

A retail company is developing a web analytics application to track user clickstream data in real time. The website events are sent to an Amazon Kinesis Data Stream. An AWS Lambda function is configured as the consumer to process these records and write aggregated metrics to a database. During peak traffic, the developer notices a high rate of ProvisionedThroughputExceededException errors on a single shard, even though the overall stream throughput is well below the limit. Additionally, the Lambda function occasionally terminates before completing the processing of its batch. Which action should the developer take to resolve these issues?

  1. A
    Modify the producer to use a static string as the partition key to consolidate records on a single shard, and configure the Lambda function to run inside a private VPC subnet without a NAT gateway.
  2. Modify the producer to use a high-entropy partition key such as session_id instead of a static value, and increase the Lambda function's timeout or decrease its batch size.Cevap
  3. C
    Keep the static partition key and increase the Kinesis retention period, while reducing the Lambda timeout to 3 seconds to force fast retries on timed-out batches.
  4. D
    Modify the producer to use session_id as the partition key, and configure the Lambda execution role's trust policy to grant write access to the target database.

Cevap

Modify the producer to use a high-entropy partition key such as session_id instead of a static value, and increase the Lambda function's timeout or decrease its batch size.
Using a high-entropy partition key such as session_id ensures that data is evenly distributed across all shards in the stream, preventing a single shard from becoming a bottleneck and throwing ProvisionedThroughputExceededException errors. Adjusting the Lambda function's timeout or decreasing the batch size ensures the function has sufficient time to complete processing before the execution is terminated.

Adım Adım Çözüm

1
Analyze the ProvisionedThroughputExceededException on Kinesis.
Identify that the exception occurs on a single shard despite low overall stream usage, indicating an uneven partition key distribution (a hot shard).
Kinesis uses partition keys to determine which shard receives a record. A low-entropy or static key concentrates data on one shard.
2
Select a high-entropy partition key.
Change the partition key to a unique identifier such as session_id on the producer side.
High-entropy keys ensure even hashing and distribution of records across all available shards.
3
Resolve the Lambda function premature termination.
Increase the Lambda execution timeout limit or decrease the batch size of the Kinesis event source mapping.
Lambda functions must be configured to accommodate the batch size processing time; otherwise, the execution terminates before the batch completes.

Anahtar Kavram

Even shard distribution using high-entropy partition keys in Amazon Kinesis Data Streams, combined with aligning Lambda batch size and timeout settings.
Bu soruyu puanla