Amazon DynamoDB: Tables, Keys, Capacity Modes, Indexes, DAX, Global Tables and Streams

AWS Solutions Architect 50 min min read Updated: Nov 17, 2026 Intermediate
Amazon DynamoDB: Tables, Keys, Capacity Modes, Indexes, DAX, Global Tables and Streams
Intermediate Topic 2 of 3

What Is DynamoDB?

DynamoDB is a fully managed, serverless NoSQL key-value and document database. It gives single-digit millisecond latency at any scale, multi-AZ replication automatically, and no servers to patch. You design tables around how you read the data.

ConceptMeaning
TableCollection of items. No fixed schema except the key
ItemOne record (up to 400 KB)
AttributeA field. Types: string, number, binary, boolean, null, list, map, sets
Primary keyPartition key alone, or partition key + sort key. Required and unique per item
Partition keyHashed to decide which partition stores the item. Needs high cardinality to spread load
Sort keyOrders items with the same partition key and allows range queries

Capacity Modes

ModeHow it worksBest for
On-demandPay per request. Scales instantly with no planningNew tables, unpredictable or spiky traffic
ProvisionedYou set RCUs and WCUs (can use auto scaling). Cheaper for steady traffic. Reserved capacity can discount furtherPredictable, steady load
UnitEquals
1 RCUOne strongly consistent read per second of an item up to 4 KB (or two eventually consistent reads)
1 WCUOne write per second of an item up to 1 KB
Transactional read/write2x the RCU/WCU
text Example: 100 strongly consistent reads/sec of 8 KB items 8 KB / 4 KB = 2 RCU per read → 100 x 2 = 200 RCU eventually consistent: 200 / 2 = 100 RCU Example: 50 writes/sec of 3 KB items 3 KB → 3 WCU per write → 50 x 3 = 150 WCU
  • Throttling (ProvisionedThroughputExceededException) happens when you exceed capacity or hit a hot partition. SDKs retry with backoff
  • Adaptive capacity shifts capacity to busy partitions, but a bad key design is still the main cause of trouble

Read Consistency

TypeBehavior
Eventually consistent (default)May return slightly old data, half the cost, higher availability
Strongly consistentReturns the latest write. Costs more and only in the same Region. Not supported on global secondary indexes
TransactionalACID across up to 100 items (TransactWriteItems, TransactGetItems)

Create and Use a Table

bash aws dynamodb create-table --table-name Orders \ --attribute-definitions AttributeName=customerId,AttributeType=S AttributeName=orderDate,AttributeType=S \ --key-schema AttributeName=customerId,KeyType=HASH AttributeName=orderDate,KeyType=RANGE \ --billing-mode PAY_PER_REQUEST \ --sse-specification Enabled=true,SSEType=KMS --deletion-protection-enabled aws dynamodb put-item --table-name Orders --item '{"customerId":{"S":"C100"},"orderDate":{"S":"2026-11-17T10:00:00Z"},"total":{"N":"499.5"},"status":{"S":"NEW"}}' aws dynamodb query --table-name Orders --key-condition-expression "customerId = :c AND orderDate BETWEEN :a AND :b" \ --expression-attribute-values '{":c":{"S":"C100"},":a":{"S":"2026-11-01"},":b":{"S":"2026-11-30"}}'
python import boto3 from boto3.dynamodb.conditions import Key table = boto3.resource("dynamodb").Table("Orders") table.put_item(Item={"customerId": "C100", "orderDate": "2026-11-18T09:00:00Z", "total": 120, "status": "NEW"}) resp = table.query(KeyConditionExpression=Key("customerId").eq("C100") & Key("orderDate").begins_with("2026-11")) for item in resp["Items"]: print(item)

Query vs Scan

QueryScan
ReadsItems with a given partition key (and optional sort key condition)Every item in the table or index
Speed and costFast and cheapSlow and expensive on big tables
UseNormal accessRare tasks, small tables, exports (prefer export to S3)

Indexes

Local Secondary Index (LSI)Global Secondary Index (GSI)
KeysSame partition key, different sort keyDifferent partition key and optional sort key
When createdOnly at table creationAny time
CapacityShares the table's capacityHas its own capacity
ConsistencyStrong or eventualEventual only
Limit5 per table, 10 GB limit per partition key value20 per table by default
  • Use a GSI to query by another attribute, for example orderId or status
  • Use sparse indexes (only items with the attribute appear) to keep them small

TTL, Streams, Backups

  • TTL: set an attribute with an epoch time; DynamoDB deletes expired items for free in the background (often within hours). Great for sessions and temporary data
  • DynamoDB Streams: ordered, 24-hour change log of item changes. Trigger Lambda for audits, search indexing, replication. Also Kinesis Data Streams integration
  • Point-in-time recovery (PITR): restore to any second in the last 35 days, to a new table
  • On-demand backups and AWS Backup, export to S3 and import from S3 without using table capacity

DAX: DynamoDB Accelerator

  • A managed in-memory cache cluster in your VPC, API-compatible with DynamoDB
  • Microsecond reads for read-heavy or hot-key workloads
  • Item cache and query cache. Write-through
  • Not for strongly consistent reads (those pass through) or write-heavy tables
  • Alternatives: ElastiCache for general caching of computed results

Global Tables

  • Multi-Region, multi-active replication: write in any Region, changes replicate in about a second
  • Gives low-latency local access and multi-Region resilience
  • Conflict resolution: last writer wins
  • Requires DynamoDB Streams (new and old images). Use with Route 53 or Global Accelerator for routing

Data Modeling Rules

  1. Start from access patterns (list every query), not entities
  2. Choose a high-cardinality partition key (user ID, order ID), not status or date alone
  3. Use sort keys to group related items (ORDER#2026-11-17) and enable range queries
  4. Use the single-table design carefully for related data, or separate tables if simpler
  5. Use GSIs for extra access patterns
  6. Keep items small. Store big objects in S3 and keep the pointer
  7. No joins: denormalize and duplicate where needed
DynamoDB is a good fitPrefer something else when
Shopping carts, sessions, user profiles, game state, IoT, leaderboardsYou need complex joins, ad hoc SQL, or heavy analytics (use Aurora, Redshift, Athena)
Very high scale with predictable latency, serverless appsYou cannot define access patterns up front

Practice Tasks

  1. Create a table with partition key customerId and sort key orderDate, insert items and query by date range
  2. Add a GSI on status and query it
  3. Turn on TTL with an expiresAt attribute
  4. Enable a stream and trigger a Lambda that logs changes
  5. Calculate RCUs for 200 eventually consistent reads per second of 6 KB items

Conclusion

DynamoDB is a serverless key-value database with partition and sort keys, on-demand or provisioned capacity, GSIs for new access patterns, TTL, streams, PITR, DAX for microsecond reads and global tables for multi-Region active-active. Design tables from access patterns and avoid scans.

Quick Summary: keys; capacity modes + RCU/WCU math; consistency; CLI + boto3; query vs scan; LSI vs GSI; TTL/streams/PITR; DAX; global tables; modeling rules.

Get Newsletter

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