DOP-C02 Question 176
Single answerYour company is developing an event-driven serverless application for processing high volumes of real-time data. The architecture involves an Amazon API Gateway, AWS Lambda, Amazon SQS, and Amazon DynamoDB. During testing, you discover that some Lambda functions are being invoked multiple times for the same event, leading to duplicate entries in DynamoDB. What is the most effective way to ensure idempotency and prevent duplicate data in DynamoDB?
- A
Use a DynamoDB conditional expression to check for the existence of an item before inserting it.
- B
Enable Lambda event source mapping with a batching window to aggregate events.
- C
Configure SQS with a FIFO queue to ensure exactly-once delivery to the Lambda function.
- D
Implement a unique identifier in the payload and perform a check within the Lambda function before writing to DynamoDB.
Show answer and explanation
Correct answer: A
Explanation
DynamoDB conditional expressions are specifically designed to handle idempotency by enforcing conditions on writes. This ensures that duplicate entries are not created even if a Lambda function is invoked multiple times due to retries or event processing delays. While other options may improve the architecture's reliability or deduplication at the messaging layer, they do not solve the core problem of preventing duplicate writes to DynamoDB at the database layer.
- A. Correct.
Correct. A DynamoDB conditional expression allows you to enforce idempotency by ensuring that an item is only inserted if certain conditions are met, such as the absence of a primary key.
- B. Incorrect.
Incorrect. Lambda event source mapping with a batching window can help optimize performance but does not address the issue of duplicate invocations or idempotency in DynamoDB writes.
- C. Incorrect.
Incorrect. SQS FIFO queues ensure message ordering and deduplication within a specific time window but do not prevent duplicate data writes to DynamoDB caused by retries or multiple Lambda invocations.
- D. Incorrect.
Incorrect. Implementing a unique identifier in the payload is a good practice, but performing a check within the Lambda function alone does not guarantee idempotency at the DynamoDB level, especially under concurrent execution.