Skip to main content
PreparationZone Logo
PrepZone

DynamoDB Production Patterns

TTL cleanup, on-demand scaling, and a social-stories-style access pattern walkthrough.

Pass checkpoint below

Why this matters

  • VaultCommerce purges expired session tokens and idempotency keys with TTL — no scheduled Scan jobs deleting rows one page at a time.
  • Throttled requests (ProvisionedThroughputExceededException) mean keys or capacity misconfigured — not "DynamoDB is down."
  • The Instagram-stories pattern — high write volume, time-ordered reads, automatic expiry — maps directly to VaultCommerce flash-sale countdown banners.
Partition key: USER#42Routes to shard
Items in partition
ORDER#2026-001Sort key
ORDER#2026-002Sort key
PROFILESort key
Partition key routes to a shard. Sort key orders items within that partition.

TTL automatic cleanup

Java
aws dynamodb update-time-to-live \
  --table-name VaultCommerce \
  --time-to-live-specification "Enabled=true, AttributeName=expiresAt"
Java
import time

table.put_item(Item={
    "PK": f"IDEM#{token}",
    "SK": "TOKEN",
    "expiresAt": int(time.time()) + 86400,  # epoch seconds
})

DynamoDB deletes expired items within ~48 hours at no WCU charge — do not rely on instant deletion for security-critical expiry; enforce TTL plus application checks.

Production knobs

  • On-demand billing — default for unknown traffic; watch for cost spikes on scans.
  • Point-in-time recovery — continuous backups for accidental deletes.
  • CloudWatch — ConsumedReadCapacityUnits, UserErrors, throttled requests.
  • PartiQL / BatchGet — batch reads up to 100 items per call for BFF layers.

The rest of this guide is part of Pro

Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.

Still to come · 2 sections

  • Stories-style time-ordered pattern
  • Monitoring and alarms

Test yourself

Answer these before moving on — recall is what makes it stick.