DynamoDB interview question · Most asked

How do DynamoDB transactions work, and what are their limits?

Summary

TransactWriteItems and TransactGetItems apply up to 100 actions across items and tables (in one account and Region) atomically: all succeed or none do, with conditions checked as part of the transaction. They cost twice the normal capacity and fail on conflicts with other in-flight transactions.

Longer Answer

Use them for multi-item invariants: transferring a balance between two items, creating an order and decrementing stock together, or enforcing uniqueness of a secondary attribute by writing a separate EMAIL#... item with attribute_not_exists in the same transaction.

Limits: 100 items and 4 MB per transaction, no two actions on the same item, and TransactionCanceledException with per-item reasons when a condition fails or a conflict occurs. Pass a ClientRequestToken to make a retried transaction idempotent (for 10 minutes). Keep most operations single-item where possible; transactions are a tool, not the default.

Key Points

  • All-or-nothing across up to 100 items.
  • Double capacity cost.
  • Uniqueness via extra items.
  • ClientRequestToken for idempotent retries.

More most-asked DynamoDB questions

← All DynamoDB questions