Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Amazon DynamoDB Conditional Writes and Atomic Counters

The application im working on currently requires me to increment an attribute belonging to an item in DynamoDB many times in a 20 to 30 minute period. I've been doing some additional reading about DynamoDBs conditional writes and atomic counters

Atomic Counters in dynamo seems like a logical choice for what I need but I do worry about the consistency of the data especially across a distributed database like dynamo and issues accuracy of my data. I'm expecting the API to get hammered at peak times but I want to avoid the performance issues related to conditional updates. I guess I want to know how reliable the Atomic Counters are with DynamoDB and how to implement them correctly using dynamo. Other suggestions are also welcome.

like image 835
john Avatar asked Mar 24 '14 16:03

john


1 Answers

Yes, these are the features you would want to use. Using them via Dynamo API is the way.

Now, between these two features, use conditional write if the counter you need to modify if very critical to business (you tell the API to update the value to say x + 10 "IF and only IF" the existing value is x)

The same document which you referred explains Atomic Counter:

"You might retry this operation if you suspect that a previous request was unsuccessful. However, you would risk applying the same update twice. This might be acceptable for a web site counter, because you can tolerate with slightly over- or under-counting the visitors. However, in a banking application, it would be safer to use a conditional update."

So if it is business critical operation use Conditional write, otherwise atomic counter. Hope it clarifies.

like image 102
Sony Kadavan Avatar answered Sep 26 '22 13:09

Sony Kadavan