To get started, I wanted to figure out exactly how to use DynamoDB. My primary use would be to run several nodejs processes (when my website scales) and have them read and write entries. It's important to know that DynamoDB uses JSON to store objects. As I found out, the REALLY COOL way you can manage write control/locking in DynamoDB is to use conditional put operations. As described in the docs, when you call put, you can specify a condition that must be true for the commit.
For example, say I have a "users logged in" entry with a lastmodified time. Two nodejs apps want to update this entry. So they both read the entry, then they both do a put with the condition of the lastmodified time being what they read initially. One app would succeed and the other would fail, so that app would get the entry again, modify it, and try to commit again.
That's all you need to know to do what essentially boils down to a row lock on the database.
No comments:
Post a Comment