An order-processing workflow must decrement an inventory item's stock count and create a new order record in the same DynamoDB table as a single all-or-nothing operation, so that a failure partway through never leaves stock decremented without a corresponding order, or vice versa. Which DynamoDB capability provides this, and what is the cost implication of using it?
- BatchWriteItem, which guarantees that either every action in the batch succeeds or none of them do
- TransactWriteItems, which groups the actions into a single all-or-nothing operation with atomicity, consistency, isolation and durability guarantees, at roughly double the write capacity of the equivalent non-transactional writes
- DynamoDB Streams combined with a Lambda function that rolls back the stock decrement if the order record fails to write
- Global tables, which apply writes across regions atomically so that either both actions succeed everywhere or neither does
Why B? And why not the others?
Correct answer: B. TransactWriteItems, which groups the actions into a single all-or-nothing operation with atomicity, consistency, isolation and durability guarantees, at roughly double the write capacity of the equivalent non-transactional writes
TransactWriteItems groups multiple actions into a single all-or-nothing operation with full ACID guarantees, so either both the stock decrement and the order creation succeed or neither does, and DynamoDB performs two underlying writes per item, one to prepare and one to commit, which is why the effective write capacity consumed is roughly double that of the same writes done non-transactionally. The option describing BatchWriteItem is wrong because it explicitly does not guarantee all-or-nothing behavior; individual actions within a batch can succeed or fail independently of one another, which is the opposite of what an atomic inventory-and-order update needs. The option describing Streams plus a Lambda rollback is wrong because that is an eventually consistent, custom-built compensating action rather than a true atomic guarantee, leaving a window where a partially completed state is visible to other readers before the rollback runs. The option describing global tables is wrong because they replicate already-committed writes across regions for availability and low-latency access; they provide no mechanism for grouping multiple actions into one atomic, all-or-nothing unit within a single write.
Source: AWS DynamoDB documentation: DynamoDB Transactions - how it works (capacity management for transactions)