Monitoring, Performance Tuning, and Cost Optimization
A healthy DynamoDB table is one where throttling is rare, latency is flat, and the bill matches the workload.
Introduction
A healthy DynamoDB table is one where throttling is rare, latency is flat, and the bill matches the workload. CloudWatch metrics, Contributor Insights, and a few design habits cover most of that.
Purpose of this lesson
You will set up the core alarms, choose a capacity mode, and apply the main cost levers: capacity mode, table class, item size, projections, TTL, and caching.
Understanding the topic
Metrics to alarm on:
ThrottledRequests,ReadThrottleEvents,WriteThrottleEvents(table and each GSI).SuccessfulRequestLatencyby operation.SystemErrors(service-side) andUserErrors(validation and condition failures from your code).ConsumedReadCapacityUnits/ConsumedWriteCapacityUnitsversus provisioned capacity.- Lambda
IteratorAgefor stream consumers andReplicationLatencyfor global tables. - Contributor Insights to find the hottest and most-throttled keys.
Informative example
Alarm on write throttling (CloudFormation snippet):
ShopTableWriteThrottleAlarm:Type: AWS::CloudWatch::AlarmProperties:AlarmName: shoptable-write-throttlesNamespace: AWS/DynamoDBMetricName: WriteThrottleEventsDimensions:- Name: TableNameValue: ShopTableStatistic: SumPeriod: 60EvaluationPeriods: 5Threshold: 1ComparisonOperator: GreaterThanOrEqualToThresholdTreatMissingData: notBreachingAlarmActions:- !Ref OnCallTopic
Cost analysis
Cost levers:
- On-demand for spiky, unpredictable, or new workloads; provisioned with auto scaling (and reserved capacity) for steady, predictable traffic.
- Standard-Infrequent Access table class lowers storage cost and raises request cost — use it when storage dominates the bill.
- Item size: capacity is billed per 1 KB written and 4 KB read, and attribute names count toward size. Keep large blobs in S3 and store a pointer.
- Projections:
KEYS_ONLYorINCLUDEGSIs cost less thanALL. - TTL deletes old data without write cost.
- Eventually consistent reads cost half of strongly consistent reads.
- DAX or an application cache for read-heavy hot items, with microsecond reads from cache.
Best practices
- Alarm on throttling for the table and every GSI.
- Use
ReturnConsumedCapacityin load tests to estimate cost per request. - Review the top cost driver monthly (storage, reads, writes, replication, backups).
Common mistakes
- Provisioning for peak with no auto scaling.
- Storing images or documents in items instead of S3.
- Paying for ALL projections on rarely used GSIs.
Advanced interview questions
Interview Prep
Practice concise answers, then expand each card for the explanation.
1IntermediateQuestionHow do you choose between on-demand and provisioned capacity?+
Answer
2BeginnerQuestionHow many RCUs does a strongly consistent read of a 9 KB item use?+
Answer
Hands-on exercise
Hands-on: using ReturnConsumedCapacity: "TOTAL", measure the RCU of reading one order with strongly consistent and eventually consistent reads, and the WCU of writing a 3.5 KB item versus a 900-byte item. Explain the numbers using the 4 KB / 1 KB rounding rules.
Summary
Monitor throttling, latency, errors, iterator age, and replication latency. Control cost with the right capacity mode, table class, small items, lean projections, TTL, and caching.