Amazon DynamoDB
NoSQL database. Single-digit millisecond latency at any scale.
What is DynamoDB?
Key-value and document database. No servers to manage. Scales automatically. Single-digit millisecond response times. Handles millions of requests per second.
Think of it like a massive key-value filing cabinet
You give each item a unique key (partition key), optionally with a sort key for organization. DynamoDB instantly finds any item without searching through everything.
Key Features
Key-Value & Document
Flexible data model. Store JSON documents or simple key-value pairs.
Auto Scaling
On-demand mode scales automatically. No capacity planning needed.
Global Tables
Multi-region replication. Active-active across regions.
DynamoDB Streams
Capture changes in real-time. Trigger Lambda functions.
DAX Cache
In-memory cache. Microsecond latency for reads.
Transactions
ACID transactions across multiple items and tables.
When to Use
- Need single-digit ms latency
- Serverless applications
- Session storage
- Gaming leaderboards
- IoT data ingestion
- Shopping carts
When Not to Use
- Complex SQL queries → RDS/Aurora
- Need joins → RDS
- Data warehouse → Redshift
- Graph relationships → Neptune
- Full-text search → OpenSearch
- Items over 400KB → S3
Prerequisites
- An AWS account (free tier: 25GB storage, 25 RCU, 25 WCU)
- AWS CLI configured (optional)
- Basic understanding of NoSQL concepts
AWS Console Steps
Open DynamoDB Dashboard
Navigate to DynamoDB in the AWS Console
Create Table
Click 'Create table' and enter a table name
Define Partition Key
Enter partition key name and type (String, Number, Binary)
Optional: Add Sort Key
Add sort key for range queries and hierarchical data
Choose Capacity Mode
Select On-demand (pay per request) or Provisioned
Create and Use
Click Create and start adding items via console or SDK
Pro Tips8
Partition key design
Use high-cardinality keys like userId or orderId. Avoid timestamps or status codes as partition keys.
GSI vs LSI
LSI: same partition key, strongly consistent, created at table creation. GSI: any key, eventually consistent, add anytime.
On-demand vs provisioned
Start with on-demand for new workloads. Switch to provisioned for stable traffic and 77% savings.
TTL for auto-cleanup
Enable TTL to delete expired items at no cost. Perfect for sessions and temporary data.
DynamoDB Streams
Trigger Lambda on changes. Records retained for 24 hours.
Transactions
Cost 2x normal operations. Use only when you need atomicity across items.
Single-table design
Store multiple entity types in one table. Reduces costs and enables atomic transactions.
DAX caching
Use for read-heavy workloads needing microsecond latency. Not for writes or strong consistency.
Key Facts8
Max item size: 400KB
GSI limit: 20 per table
LSI limit: 5 per table (created at table creation only)
Partition throughput: 1,000 WCU and 3,000 RCU per partition
Transaction limit: 100 items or 4MB per transaction
Batch write: 25 items max per request
Batch get: 100 items max per request
Query/Scan: 1MB per operation (paginate for more)