advanced
DynamoDB
Use managed key-value and document storage with partition keys, access patterns, capacity modes, streams, and single-table trade-offs.
DynamoDB is a managed key-value and document store tuned for predictable access patterns at scale. Partition key (and optional sort key) define item placement; hot partitions throttle throughput regardless of table capacity.
| Mode | When | |------|------| | On-demand | Spiky or unknown traffic | | Provisioned + auto scaling | Steady, cost-predictable workloads | | GSI / LSI | Alternate query paths on the same table |
Model queries first, then keys — not the reverse. DynamoDB Streams can trigger Lambda for change data capture. Single-table design reduces round trips but raises modeling complexity for relational minds.
On interviews: partition key choice, hot keys, conditional writes for optimistic locking, TTL, and when DynamoDB beats RDS for a JavaScript API.
Common pitfalls: scanning large tables; GSIs on every ad-hoc filter; treating it like Mongo with arbitrary queries; ignoring eventually consistent reads on GSIs.
The trade-off is horizontal scale and single-digit millisecond latency versus rigid access patterns and higher cognitive load in data modeling.
Checklist:
- Design partition keys around known query shapes.
- Use condition expressions for concurrency control.
- Pick on-demand or provisioned capacity with alarms.
- Prefer batch APIs and projection expressions to trim payload size.