Amazon DynamoDB Conditional Writes and Atomic Coun

2020-03-01 16:55发布

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.

1条回答
做自己的国王
2楼-- · 2020-03-01 17:29

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.

查看更多
登录 后发表回答