Skip to content

DynamoDB Transactions Exam Tips

DynamoDB Transactions are to support mission-critical applications which need an all or nothing approach to database transactions.

  • ACID Transactions: Describes ideal properties of a database transaction
    1. Atomic - Guarantees that a transaction is treated as a single unit. Basically, all or nothing; can't be partially completed.
    2. Consistent - Valid transaction; must leave DB in a valid state. Prevents any database corruption or data integrity issues.
    3. Isolated - No dependency between different transactions. They can be completed in parallel or sequentially; the effect of the transaction is going to be the same.
    4. Durable - Once a transaction is committed, it stays commited regardless of power failure or the like. Basically, it's fully written to disk and not in-memory.
  • Essentially, transactions should be treated as a single operation that's durable i.e. available regardless of a catistrophic event such as a power failure.
    • E.g. financial transaction
  • Read or write multiple items across multiple tables as an all or nothing operation.
  • Check for a pre-requisite condition before writing to a table

For example, imagine you are coding a game and you want to ensure that when a player purchases an item from another player you might perform the following steps:

  1. Check that the current owner actually owns the item.
  2. Check that the buyer has enough currency.
  3. Add the currency to the seller's account.
  4. Remove the currency from the buy's account.
  5. Add the item to the buyer's account.
  6. Remove the item from the seller's account.

As you would imagine, we would need this as a single atomic and durable transaction or we could have bugs, like the currency transferring but not the item.

You can use DynamoDB transactions to achieve this. Think T-SQL Transactions with ROLLBACK and COMMIT