So far, we have satisfied the access patterns around creation and retrieval of core entities in our mobile application, such as Users and Photos. We have also learned how to use an inverted index to enable additional query patterns on our entities.
In this module, we will satisfy two access patterns:
- React to a photo (Write)
- Follow friend (Write)
Note that both of these access patterns are writing data to DynamoDB, in contrast to the read-heavy patterns we’ve done so far
To satisfy the both access patterns in the steps below, we’re going to use DynamoDB ACID transactions. DynamoDB transactions were released in November 2018. Let’s get a quick primer on how transactions in DynamoDB work.
Transactions are popular in relational systems for operations that affect multiple data elements at once. For example, imagine you are running a bank. One customer, Karen, transfers $100 to another customer, Sujith. When recording this transaction, you would use a transaction to make sure the changes are applied to the balances of both customers rather than just one.
The addition of transactions to DynamoDB makes it easier to build applications where you need to alter multiple items as part of a single operation. With DynamoDB transactions, you can operate on up to 10 items as part of a transaction request.
In a TransactWriteItem API call, you can use the following types of operations.
- Put: For inserting or overwriting an item;
- Update: For updating an existing item;
- Delete: For removing an item;
- ConditionCheck: For asserting a condition on an existing item without altering the item.
In the steps below, we will use a DynamoDB transactions in two ways to handle complex operations.
Time to Complete Module: 20 Minutes