最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

node.js - How to support transactions in dynamoDB with javascript aws-sdk? - Stack Overflow

programmeradmin3浏览0评论

We have a microservice written in node.js & we use dynamoDB for data storage. Value is stored in json format against key. In update service call, we fetch value for a key, update the json & save it.

Recently, we came across a condition where 2 calls wanted to update the value of the same key. So first call read the value, then second call read the value, first call updated & saved, then second updated & saved the value (usual case of race condition), so in this case update by first call did not get reflected in DB.

To handle this, I researched a bit & came to know about the transaction library of dynamoDB. But it seems that it is not yet in node-js sdk.

Also, I searched about versioning & optimistic locking but again I did not find a support for this in node-js sdk.

Is there any update with this? If it's support is not going to come in near future in node-js sdk, what are the other options? What could be the best way to handle this issue?

We have a microservice written in node.js & we use dynamoDB for data storage. Value is stored in json format against key. In update service call, we fetch value for a key, update the json & save it.

Recently, we came across a condition where 2 calls wanted to update the value of the same key. So first call read the value, then second call read the value, first call updated & saved, then second updated & saved the value (usual case of race condition), so in this case update by first call did not get reflected in DB.

To handle this, I researched a bit & came to know about the transaction library of dynamoDB. But it seems that it is not yet in node-js sdk.

Also, I searched about versioning & optimistic locking but again I did not find a support for this in node-js sdk.

Is there any update with this? If it's support is not going to come in near future in node-js sdk, what are the other options? What could be the best way to handle this issue?

Share Improve this question asked Feb 4, 2016 at 9:44 ameykpatilameykpatil 6011 gold badge8 silver badges21 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 14
  1. You can do atomic updates such as incrementing a number straight on Dynamo without reading, incrementing, updating. For more information see this

  2. Are both updates updating the same field? If so you can add a condition to the update that the old value equal what you read. That way if you try to save the 2nd new value, this condition will fail and it won't perform the 2nd update. See this

Just released at 2018 re:invent, see the native transaction support in javascript sdk usage here: https://aws.amazon.com/blogs/aws/new-amazon-dynamodb-transactions/

Recently there is an npm package that provides implementation of DynamoDb optimistic locking. See Dynameh. You can check that out.

发布评论

评论列表(0)

  1. 暂无评论