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
- What are DynamoDB Streams, and how are they used?
- Query or Scan: what is the difference, and why avoid Scan?
- What is DynamoDB, and what workloads is it a good fit for?
- What is a hot partition, and how do you avoid one?
- How do you approach data modelling in DynamoDB, and how is it different from relational design?
- Explain partition keys, sort keys and the two kinds of primary key.
- Global secondary index or local secondary index: what is the difference?
- How do conditional writes work, and how do you implement optimistic locking in DynamoDB?