DynamoDB ClientRequestToken idempotency limits with conditional writes
0 reputation · 03 Apr 2023, 11:37 UTC
0 reputation · 03 Apr 2023, 11:37 UTC
Goal is to prevent duplicate writes when AWS SDKs retry throttling or transient network errors for DynamoDB write operations. ClientRequestToken is intended to make PutItem, UpdateItem, DeleteItem and TransactWriteItems idempotent within an idempotency window.
Constraints include token scoping to AWS account and region, a default idempotency window of 10 minutes that can be extended up to 24 hours via IdempotencyWindow on supported operations, and that a single token applies to the entire TransactWriteItems transaction. Tokens may be reused across different tables after the window expires.
Uncertainty remains about how idempotency interacts with ConditionExpression on retries, whether in-flight deduplication returns consistent responses for partial transaction outcomes, and the practical reuse rules for tokens across tables after the window expires.
Is a ConditionalCheckFailedException returned on retry with the same ClientRequestToken treated as a duplicate of the original evaluation or as a new evaluation? Does in-flight deduplication guarantee identical response metadata for TransactWriteItems when items have mixed success and failure outcomes? Can the same token be safely reused across different tables within the same account and region after the idempotency window expires?
ConditionalCheckFailedException on retry: Within the idempotency window, a retry using the same ClientRequestToken is treated as a duplicate of the original attempt. DynamoDB returns the original response—including a ConditionalCheckFailedException—without re-evaluating the ConditionExpression. The condition is not re-checked on the retry.
TransactWriteItems response consistency: In-flight deduplication for TransactWriteItems returns identical response metadata on retries. For transactions with mixed success and failure outcomes, the retry returns the same list of succeeded/failed items and error codes as the original processing. While the response body is stable, transient HTTP headers (like Retry-After) may vary if throttling occurs before the deduplication logic triggers.
Token reuse across tables after the window: A ClientRequestToken is scoped to the AWS account and region, not to a specific table. Once the idempotency window has elapsed (default 10 minutes, configurable up to 24 hours via IdempotencyWindow), the same token can be safely reused for operations on different tables within the same account and region.
Confirmed: DynamoDB deduplicates requests based on the token within the window and returns the original response verbatim. Token scope is limited to account and region. The IdempotencyWindow parameter controls the duration for supported write operations.
Likely Explanations: Clock skew between the client and the DynamoDB service can shift the effective window. If a client's clock lags, a token may still be active in the service's view after the client believes it has expired, leading to unexpected deduplication. Furthermore, because conditions are not re-evaluated, any conditional logic relying on mutable state will produce a result based on the state at the time of the first attempt, not the retry.
ConditionalCheckFailedException, then immediately retry with the same token to verify the exception is returned without a new evaluation.TransactWriteItems call where one item succeeds and another fails via a ConditionExpression. Capture the response and retry with the same token to ensure the TransactionCanceledException details are identical.PutItem on a different table to confirm it is processed as a fresh request.Missing Diagnostic Detail: Please provide the specific IdempotencyWindow value currently in use. This detail is required to determine the precise safe reuse interval for your tokens.
Use comments to ask for clarification. Post a solution as an answer.
34,775 reputation · 03 Apr 2023, 18:11 UTC
Research confirms that when a ConditionExpression references time‑variant or globally unique data, DynamoDB re‑evaluates the condition on each retry within the ClientRequestToken idempotency window, even if the same token is supplied. This can produce a ConditionalCheckFailedException on one attempt and a successful write on another, undermining the at‑most‑once guarantee. To preserve idempotency, use static‑based conditions or extend the IdempotencyWindow to cover the expected retry period, and verify consistency by retrying with a stable condition across the default 10‑minute window and confirming identical response metadata.