A Lambda writes to DynamoDB using PutItem and sometimes duplicates writes when clients retry after timeouts. The table uses a composite primary key (orderId, eventTime). Which strategy provides end-to-end idempotency without requiring exactly-once execution?
Answer
Use a conditional expression on a deterministic attribute so only the first write succeeds, and retry uses the same deterministic condition
Explanation
Idempotency should be enforced with deterministic keys/conditions so retries converge to the same outcome. Conditional expressions (e.g., attribute_not_exists on a stable marker) prevent duplicates regardless of invocation multiplicity.
Last reviewed: October 2026
Reviewed by FirstInTest Editorial Team
Related questions
A developer uses API Gateway Lambda proxy integration and returns an application/json response. Some clients report intermittent 502 errors only under high concurrency. Which change most likely fixes the issue?
View question →
A developer uses a Step Functions workflow that calls two Lambdas in parallel, then writes results to DynamoDB. The workflow occasionally fails due to throttling and inconsistent partial writes. Which approach most reliably preserves correctness and retries safely?
View question →
A Step Functions workflow uses an activity worker that sometimes times out due to slow downstream processing. You want automatic recovery with minimal duplicate processing. What is the best tactic?
View question →
In the described API flow, which change best reduces cold-start latency for Lambda-integrated API Gateway without increasing idle cost significantly?
View question →
You are building a serverless backend that must stream large uploads to S3 while generating metadata via a Lambda trigger. When should you prefer S3 ObjectCreated events over API Gateway/Lambda polling?
View question →
A multi-tenant service uses DynamoDB with a single table design. Each request includes tenantId, and Lambda generates items with a partition key of tenantId. You notice a user from tenant A can infer patterns of tenant B by querying through a leaked GSI. Which prevention is most appropriate?
View question →