Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DynamoDB ConditionalCheckFailedException thrown but succeeds

I think that have seen in many occasions that a DynamoDB conditional put throws ConditionalCheckFailedException but succeeds. Usually in this scenario, the request takes quite long (~10s) to finish, but I can see that the request is updated despite the fact that a ConditionalCheckFailedException is thrown (and the it took few seconds).

By the way I don't force any timeout on the DDB request.

Is this a bug, or some DDB conditional put contract that I misunderstand? Has anyone experienced this issue?

like image 899
Yichao Zhao Avatar asked Mar 16 '26 00:03

Yichao Zhao


1 Answers

Answering this late to inform others:

ConditionCheckFailedException but item is persisted:

This typically happens when you save an item to DynamoDB, DynamoDB acknowledges the write request but the response gets lost on the return path which can happen for multiple reasons, keeping in mind that DynamoDB is one of the largest distributed systems in the cloud.

This causes the SDK timeout to exceed while awaiting a response, which then triggers an SDK retry. When the write request is retried, the condition now evaluates to False as the item already exists, which in turn throws a ConditionCheckFailedException, which can cause confusion.

On your write requests set the ReturnValuesOnConditionCheckFailureparameter which will return the value of the item the condition failed against for free, then you can assert the item is already persisted.

like image 84
Lee Hannigan Avatar answered Mar 17 '26 23:03

Lee Hannigan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!