Transactions

When to use DynamoDB transactions and how to minimize their 2x cost premium.

What are Transactions?

DynamoDB transactions let you perform all-or-nothing operations across multiple items and tables.1 Either all writes succeed together, or they all fail and roll back—no partial updates.

Key capabilities:

  • Group up to 100 items across one or more tables in a single transaction
  • Read or write items atomically with ACID guarantees
  • Prevent race conditions with automatic conflict detection

Example: Transfer $100 between accounts—debit Account A and credit Account B must both succeed or both fail.

The Cost

DynamoDB transactions cost 2x normal read/write operations.1

  • Standard write: 1 WCU per KB
  • Transactional write: 2 WCUs per KB
  • Standard read: 1 RCU per 4 KB (eventual) or 2 RCUs (strong)
  • Transactional read: 4 RCUs per 4 KB (always strong consistency)

Note: Transactions are not recommended for single-item operations. Use standard PutItem, UpdateItem, or DeleteItem with conditional expressions instead—they provide atomicity for a single item at half the cost.

When to Use Transactions

Use transactions ONLY when you need:

  1. ACID guarantees across multiple items/tables

    • Transfer funds between two accounts (debit one, credit another)
    • Update inventory count AND create order record atomically
    • Prevent double-booking of resources (hotel rooms, appointments)
  2. Coordinated updates

    • Update multiple denormalized copies that must stay in sync
    • Maintain aggregates (update item + increment counter atomically)
  3. Check-and-set operations across items

    • “Only update if both Item A and Item B meet conditions”
    • Prevent race conditions in distributed workflows

Important: If you use GSIs, remember they are eventually consistent and should not be included in transactions. For transaction-critical reads, always try to query the base table directly using the primary key—never rely on a GSI that might have stale data.

Footnotes

  1. Amazon DynamoDB Transactions 2