Mike
Mike

Reputation: 59

AWS Lambda NodeJS - How to update item in dynamo DB thread safe

I have an application that receive several post request at the same time and it seems my field in database are rewritten due to concurrent actions of request

How can I update fields and avoid race conditions ?

Thanks

Upvotes: 1

Views: 763

Answers (1)

Auskennfuchs
Auskennfuchs

Reputation: 1737

What you are looking for is optimistic locking. You need one field (e.g. "Version") which gets updated everytime with an increasing number or timestamp. On request side you have to provide this version to the client so he can send you his version back. The database system can than check for equality. If so nobody else has changed the entry. If not an error is raised. Maybe this page helps you further: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBMapper.OptimisticLocking.html

Upvotes: 1

Related Questions