Through the earlier modules in this lab, you have satisfied the access patterns for the creation and retrieval of core entities in the gaming application, such as
Games. You also used a sparse GSI to find open games that users can join.
In this module, you satisfy two access patterns:
Note that both of these access patterns are writing data to DynamoDB, in contrast to the read-heavy patterns you have done so far in this lab.
To satisfy the “Join game for a user” access pattern in this module’s steps, you are going to use DynamoDB transactions. 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 transfers $100 to another customer. 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.
DynamoDB transactions make it easier to build applications that alter multiple items as part of a single operation. With transactions, you can operate on up to 25 items as part of a single transaction request. In a TransactWriteItems API call, you can use the following operations:
In the following steps, you use a DynamoDB transaction when adding new users to a game while preventing the game from becoming overfilled.