Salatiques
Salatiques

Reputation: 1

DynamoDB concurrent writes

I have the following table structure which describe user access to the tables:

primary-key; attribute

table-id     users
1            user1, user2, user3
2            user4, user1

And I have lambda which can handle access requests (grant/revoke). For example, I can invoke lambda to get access to table-id=1 to user5 and revoke it for user2. So, I have two invocations:

grant  table-id=1 user5 
revoke table-id=1 user2

In lambda I select all users with corresponding table-id using Table.getItem(), merging with users in lambda event and doing Table.updateItem(). Everything works OK, but when concurrent lambda execution occurs, one of the concurrent run overwrite the result of a parallel run.

It's called something like "last write win". In the example above, it can happen when lambda return success result for both invocations, but, in fact only one persist. But I want them to be applied both, no matter in ordering. How can I manage such situation correctly?

Upvotes: 0

Views: 2334

Answers (1)

Ervin Szilagyi
Ervin Szilagyi

Reputation: 16775

DynamoDB supports conditional writes, which means the write operations will only succeed if a certain condition is met. They were designed for situations where multiple writes happen in the same time, which is exactly what you encounter.

Upvotes: 3

Related Questions