Reputation: 3
I have a situation where 8-10 lambdas are constantly reading and writing in same DynamoDB table and often same record. How to avoid race condition in this situation ?
The scale of operation is in millions and there is high chance that lambda will try to update same row.
Upvotes: 0
Views: 60
Reputation: 19883
That's totally dependent on what you're trying to protect against, a "race-condition" means many different things.
Single item Puts/Updates/Deletes are atomic and strongly serialized meaning the items final state will be as if all updates succeeded, and each subsequent update will see the update of the operation that succeeded before it.
One way that you can protect concurrent systems from corrupting data is to use Optimistic Locking in the means of a version number and conditional check. While that document defines how it is done in Java, you can easily include the update and condition in any SDK language.
DynamoDB Transactions is another way to protect against multiple resources updating the same item, as it locks the item while the execution is in process allowing no other thread to update that same item.
Upvotes: 1