You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
This final lesson covers DynamoDB's advanced features — Time to Live (TTL), DynamoDB Accelerator (DAX), Global Tables, and PartiQL — along with a comprehensive set of best practices for production workloads.
TTL automatically deletes expired items from a table at no cost (no WCU consumed):
ExpiresAt)REMOVE events with userIdentity.type = "Service")aws dynamodb update-time-to-live \
--table-name Sessions \
--time-to-live-specification \
Enabled=true,AttributeName=ExpiresAt
# Set expiry to 24 hours from now (Unix timestamp)
aws dynamodb put-item \
--table-name Sessions \
--item '{
"SessionId": {"S": "sess-abc123"},
"UserId": {"S": "user-001"},
"ExpiresAt": {"N": "1709654400"}
}'
| Use Case | TTL Attribute Value |
|---|---|
| Session management | Session creation time + session duration |
| Cache entries | Current time + cache TTL |
| Temporary tokens | Token issue time + validity period |
| Regulatory data retention | Data creation time + retention period |
| Event logs | Event time + retention window |
Tip: Expired items may still appear in reads for up to 48 hours after expiration. Filter them out in your application by checking the TTL attribute.
DAX is a fully managed, in-memory cache purpose-built for DynamoDB:
Application → DAX Cluster → DynamoDB Table
│
In-Memory Cache
(microsecond reads)
DAX is a write-through cache — reads check the cache first, and writes update both the cache and the table.
| Feature | Description |
|---|---|
| Latency | Microsecond response times (vs millisecond for DynamoDB) |
| Compatibility | Drop-in replacement — same API as DynamoDB |
| Managed | Fully managed — no cache invalidation logic needed |
| Write-through | Writes go to DynamoDB and update the cache |
| Cluster | Multi-node cluster with read replicas |
| Encryption | Supports encryption at rest and in transit |
aws dax create-cluster \
--cluster-name my-dax-cluster \
--node-type dax.r5.large \
--replication-factor 3 \
--iam-role-arn arn:aws:iam::123456789012:role/DAXRole \
--subnet-group-name my-subnet-group
| Good Fit | Poor Fit |
|---|---|
| Read-heavy workloads | Write-heavy workloads |
| Repeated reads of the same items | Mostly unique reads |
| Latency-sensitive applications | Applications tolerant of millisecond latency |
| Eventually consistent reads | Strongly consistent reads (DAX does not cache these) |
| Feature | DAX | ElastiCache (Redis/Memcached) |
|---|---|---|
| Purpose | DynamoDB-specific cache | General-purpose cache |
| API | DynamoDB-compatible | Redis/Memcached protocol |
| Cache invalidation | Automatic (write-through) | Manual |
| Data model | Items and queries | Key-value, data structures |
| Consistency | Eventually consistent | Application-managed |
Global Tables provide multi-Region, multi-active replication for DynamoDB:
Writes
│
┌─────────────┼─────────────┐
▼ ▼ ▼
eu-west-1 us-east-1 ap-southeast-1
┌──────────┐ ┌──────────┐ ┌──────────┐
│ Replica │ │ Replica │ │ Replica │
│ Table │←→│ Table │←→│ Table │
└──────────┘ └──────────┘ └──────────┘
Active Active Active
# First, create the table in the primary Region
aws dynamodb create-table \
--table-name GlobalUsers \
--billing-mode PAY_PER_REQUEST \
--attribute-definitions AttributeName=UserId,AttributeType=S \
--key-schema AttributeName=UserId,KeyType=HASH \
--stream-specification StreamEnabled=true,StreamViewType=NEW_AND_OLD_IMAGES
# Then add replicas
aws dynamodb update-table \
--table-name GlobalUsers \
--replica-updates '[
{"Create": {"RegionName": "us-east-1"}},
{"Create": {"RegionName": "ap-southeast-1"}}
]'
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.