DynamoDB Indexes, Capacity Modes, Throttling, TTL, Streams and DAX

AWS Developer Associate 55 min min read Updated: Nov 17, 2026 Intermediate
DynamoDB Indexes, Capacity Modes, Throttling, TTL, Streams and DAX
Intermediate Topic 2 of 3

Secondary Indexes

A table supports queries on its primary key. To query another way (for example orders by status), add an index.

Global Secondary Index (GSI)Local Secondary Index (LSI)
KeysDifferent partition key and optional sort keySame partition key as the table, different sort key
CreateAny timeOnly when creating the table
CapacityHas its own RCU/WCU (or on-demand)Shares the table capacity
ConsistencyEventually consistent onlyStrong or eventual
Size limitNone special10 GB per partition key value (item collection limit)
CountUp to 20 by default per tableUp to 5
bash aws dynamodb update-table --table-name Orders \ --attribute-definitions AttributeName=status,AttributeType=S AttributeName=createdAt,AttributeType=S \ --global-secondary-index-updates '[{"Create":{"IndexName":"status-createdAt-index", "KeySchema":[{"AttributeName":"status","KeyType":"HASH"},{"AttributeName":"createdAt","KeyType":"RANGE"}], "Projection":{"ProjectionType":"INCLUDE","NonKeyAttributes":["total","customerId"]}}}]'
python r = table.query(IndexName="status-createdAt-index", KeyConditionExpression=Key("status").eq("PENDING") & Key("createdAt").gt("2026-11-01"))
ProjectionContains
KEYS_ONLYIndex and table keys only
INCLUDEKeys plus chosen attributes
ALLEverything (largest and costliest)
  • A GSI is a copy of data, so writes to the table also write to the index and use index write capacity. If a GSI is under-provisioned it can throttle the base table writes
  • Only items that have the index key attributes appear in the index (a sparse index is a useful trick: put the attribute only on items you want to find)
  • Querying attributes not projected into an LSI fetches from the table; a GSI cannot fetch them

Capacity Modes

ModeHow it worksChoose when
On-demandPay per request. Scales instantly to previous peaks and beyond (it can double the previous peak quickly)New or unpredictable traffic, spiky load, no planning
ProvisionedYou set read and write capacity units. Can use auto scaling. Cheaper for steady, predictable load. Reserved capacity gives extra discountsStable traffic you can forecast

RCU and WCU Calculations (Exam Favorite)

UnitMeaning
1 WCUOne write per second of an item up to 1 KB (round up)
1 RCUOne strongly consistent read per second of up to 4 KB (round up). Eventually consistent = half. Transactional read = double
1 WRU / RRUOn-demand write and read request units follow the same sizes
text Example 1: 10 writes/second of 2.5 KB items size 2.5 KB -> round up to 3 KB -> 3 WCU per write 10 x 3 = 30 WCU Example 2: 80 strongly consistent reads/second of 6 KB items 6 KB / 4 KB = 1.5 -> round up to 2 RCU per read 80 x 2 = 160 RCU Example 3: same reads but eventually consistent 160 / 2 = 80 RCU Example 4: 50 transactional writes/second of 1 KB items transactional write costs double: 50 x 1 x 2 = 100 WCU

Throttling and Hot Partitions

  • When you exceed capacity DynamoDB returns **ProvisionedThroughputExceededException (HTTP 400). The SDK retries with backoff**. Persistent throttling means you need more capacity, better key design or caching
  • Data and traffic are spread across partitions by key hash. A partition handles up to about 3,000 RCU and 1,000 WCU. A hot key (one celebrity user, one status value) overloads a single partition even if the table total looks fine
  • DynamoDB provides burst capacity and adaptive capacity to help, but good keys matter most
Fix for hot keysHow
High-cardinality partition keyUse userId or orderId instead of status or date
Write shardingAdd a random suffix status#0..9 and query all shards (scatter-gather)
CachingDAX or ElastiCache for read-heavy hot items
Queue writesSQS to smooth bursts
Use exponential backoffAlready built in to SDKs

Time to Live (TTL)

  • Pick a numeric attribute holding an epoch time in seconds. Items past that time are deleted in the background (usually within a few days, often much sooner) at no write cost
  • Expired items may still appear in reads until deleted. Filter them in queries if exactness matters
  • Deletions appear in Streams so you can archive them to S3
  • Use for sessions, temporary tokens, caches and old logs
python import time table.put_item(Item={"pk": "session#abc", "user": "C-100", "expiresAt": int(time.time()) + 3600}) # enable once: # aws dynamodb update-time-to-live --table-name Sessions --time-to-live-specification Enabled=true,AttributeName=expiresAt

DynamoDB Streams

  • An ordered, 24-hour log of item changes: KEYS_ONLY, NEW_IMAGE, OLD_IMAGE or NEW_AND_OLD_IMAGES
  • Order is guaranteed per item (per key)
  • Process with Lambda (event source mapping), Kinesis adapter or EventBridge Pipes
  • Uses: audit trail, sync to OpenSearch, send notifications, update aggregates, replicate, cache invalidation
python from boto3.dynamodb.types import TypeDeserializer td = TypeDeserializer() def handler(event, context): for rec in event["Records"]: if rec["eventName"] == "INSERT": new = {k: td.deserialize(v) for k, v in rec["dynamodb"]["NewImage"].items()} print("new order", new["orderId"])
Failure behavior: If your Lambda throws an error for a stream batch, Lambda retries the same batch and blocks that shard until success or the data expires. Set max retry attempts, bisect on error and an on-failure destination.

DynamoDB Accelerator (DAX)

  • A fully managed in-memory cache for DynamoDB giving microsecond reads, in your VPC. You use the DAX client with almost the same API
  • Best for read-heavy, repeated reads of the same items (eventually consistent). Not for strongly consistent reads (they pass through) or write-heavy loads
  • Has an item cache (GetItem/BatchGetItem) and a query cache (Query/Scan results). Default TTL 5 minutes
  • Compare with ElastiCache: use ElastiCache when you cache computed results or non-DynamoDB data, DAX when you want a drop-in cache for DynamoDB

Other Useful Features

FeaturePurpose
Point-in-time recovery (PITR)Restore to any second in the last 35 days
On-demand backups / AWS BackupFull backups without affecting performance
Global tablesMulti-Region, multi-active replication
Export to S3 / import from S3Move data without using table capacity
Standard-IA table classCheaper storage for rarely accessed tables
EncryptionAlways on at rest (AWS owned, AWS managed or customer managed KMS key)

Practice Tasks

  1. Add a GSI on status and createdAt and query pending orders
  2. Calculate RCU and WCU for three workloads using the formulas
  3. Create a provisioned table with 1 WCU and trigger throttling with a loop
  4. Enable TTL on a session table and watch an expired item disappear
  5. Enable a stream and print every INSERT from a Lambda function

Conclusion

Use GSIs for new query patterns (any time, own capacity, eventual reads) and LSIs only at table creation. Pick on-demand for unpredictable load and provisioned for steady load, calculate RCU/WCU by rounding item size up, design keys to avoid hot partitions, use TTL for expiry, Streams for change events and DAX for microsecond reads.

Quick Summary: GSI vs LSI; capacity modes; RCU/WCU math; throttling and hot keys; TTL; Streams; DAX; other features.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators