Joey Yi Zhao
Joey Yi Zhao

Reputation: 42474

How can I avoid overwriting dynamodb from two lambdas?

I am updating dynamodb table from a lambda function. In a high throughput case, there could be multiple lambda instances running at the same time to update the same table. Is there a way to safe guard the table? Whether I can lock the table?

Upvotes: 3

Views: 2413

Answers (1)

Marcin
Marcin

Reputation: 238139

There is no build-in mechanism to lock DynamoDB table to safeguard from concurrent overwriting. But there are design patterns which you can implement yourself, or depending on your programing language, find an existing implementation ready to be used, even provided by AWS.

In AWS docs you can find information how to implement Optimistic locking:

Optimistic locking is a strategy to ensure that the client-side item that you are updating (or deleting) is the same as the item in Amazon DynamoDB. If you use this strategy, your database writes are protected from being overwritten by the writes of others, and vice versa.

AWS also provides Amazon DynamoDB Lock Client for java:

The DynamoDB Lock Client implements a protocol allowing similar applications to take advisory locks on any part of your problem domain, big or small. This protocol ensures your players “stay in possession of the ball” for a certain period of time.

And the end of the day, its up to you to design a solution "to safe guard the table" which meets your needs.

Upvotes: 4

Related Questions