Scaling and Protecting Data in Amazon DynamoDB
Amazon DynamoDB is a serverless key-value and document database that is replicated across three Availability Zones automatically. This lesson explains how DynamoDB tables scale through capacity modes and auto scaling, how global tables provide multi-Region, multi-active replication, and how point-in-time recovery and backups protect against data corruption and deletion.
Learning outcomes
After completing this lesson, you will be able to:
- Compare on-demand and provisioned capacity modes and explain how DynamoDB auto scaling adjusts provisioned capacity.
- Explain the causes of throttling, including hot partitions, and how they are diagnosed and remediated.
- Describe DynamoDB global tables, their consistency options and conflict resolution.
- Explain point-in-time recovery, on-demand backups and deletion protection.
Built-in Resilience
Every DynamoDB table is replicated synchronously across three AZs in its Region, so no configuration is needed for AZ resilience, and the service has a 99.99% availability SLA for standard tables (99.999% for global tables). The design decisions therefore concern capacity, multi-Region replication and protection against logical errors such as accidental deletes, which replication does not prevent because deletes replicate too.
Capacity Modes and Auto Scaling
DynamoDB has two capacity modes. In on-demand mode, the table serves whatever traffic arrives and charges per request; it accommodates sudden spikes, scaling up to double its previous peak instantly, and needs no capacity planning. It suits unpredictable workloads and new applications. In provisioned mode, the table has a specified number of read capacity units (RCUs) and write capacity units (WCUs) and is cheaper for steady, predictable traffic. A table can switch between modes, with limits on how often.
Provisioned tables should use DynamoDB auto scaling, which uses Application Auto Scaling with a target tracking policy. The administrator sets a minimum, a maximum and a target utilisation, such as 70%; CloudWatch alarms on consumed capacity trigger increases or decreases to keep utilisation near the target. Global secondary indexes have their own capacity and need their own scaling settings, because an under-provisioned index throttles writes to the base table. Auto scaling reacts within minutes, not seconds, so short spikes are absorbed by burst capacity, which retains up to five minutes of unused capacity, and sharp, predictable peaks are better handled by scheduled scaling or on-demand mode.
aws application-autoscaling register-scalable-target --service-namespace dynamodb \
--resource-id table/Orders --scalable-dimension dynamodb:table:WriteCapacityUnits \
--min-capacity 50 --max-capacity 2000
aws application-autoscaling put-scaling-policy --service-namespace dynamodb \
--resource-id table/Orders --scalable-dimension dynamodb:table:WriteCapacityUnits \
--policy-name orders-wcu-70 --policy-type TargetTrackingScaling \
--target-tracking-scaling-policy-configuration \
'{"TargetValue":70.0,"PredefinedMetricSpecification":{"PredefinedMetricType":"DynamoDBWriteCapacityUtilization"}}'Diagnosing Throttling
Throttled requests fail with ProvisionedThroughputExceededException (or a throttling error in on-demand mode), and the SDKs retry them with backoff. Throttling has three common causes. The table's overall capacity is too low, visible as consumed capacity near provisioned capacity in CloudWatch; the remedy is higher capacity, a higher auto scaling maximum or on-demand mode. A global secondary index is under-provisioned, which throttles base-table writes; the remedy is index capacity. Or traffic is concentrated on a few partition key values, a hot partition: each partition supports up to 3,000 RCUs and 1,000 WCUs, so a single popular key is throttled even when the table has spare capacity. DynamoDB's adaptive capacity redistributes capacity to hot partitions automatically, but a single key above the per-partition limit still throttles, and the remedy is a key design with higher cardinality, such as write sharding with a suffix. CloudWatch Contributor Insights for DynamoDB identifies the most accessed and most throttled keys, which pinpoints hot partitions.
For read-heavy workloads, DynamoDB Accelerator (DAX) is an in-memory cache in front of a table that reduces read latency to microseconds and offloads repeated reads, as discussed in the caching lesson.
Keep DynamoDB available
Global Tables
Global tables replicate a table to replicas in several Regions. Every replica accepts reads and writes (multi-active), so applications in each Region read and write locally. By default, replication is asynchronous with multi-Region eventual consistency, typically within a second, and concurrent writes to the same item in different Regions are resolved by last writer wins based on timestamps. An application that cannot tolerate this either routes writes for an item to one Region or uses multi-Region strong consistency, an option in which writes are replicated synchronously to at least one other Region before they are acknowledged, giving an RPO of zero at the cost of higher write latency; it requires a specific configuration of three Regions (replicas or a witness).
Global tables give near-zero RTO for Regional failures, because the other Regions are already serving traffic, and they are the standard DynamoDB answer for multi-Region active/active designs. All replicas should have the same capacity settings, because each replica receives every write. Streams must be enabled, and replicas can be added to an existing table.
Backups and Recovery
Replication protects against infrastructure failure but not against application bugs or accidental deletion, which replicate instantly. Three features address logical errors.
- Point-in-time recovery (PITR): continuous backups that allow restoring the table to any second in the recovery period, configurable from 1 to 35 days, with no performance impact. Restores create a new table.
- On-demand backups: full backups kept until deleted, created manually, on a schedule or through AWS Backup, which adds cross-Region and cross-account copies and vault lock.
- Deletion protection: a table setting that prevents the table from being deleted until the setting is turned off.
Restored tables do not keep some settings, such as auto scaling policies, IAM policies, CloudWatch alarms, tags, TTL settings and stream settings, which must be reapplied, ideally by IaC. Data can also be exported from PITR to S3 for analysis without consuming table capacity.
| Risk | Protection |
|---|---|
| AZ failure | Built in: three-AZ replication |
| Regional failure | Global tables |
| Accidental overwrite or corruption | PITR restore to a moment before the error |
| Accidental table deletion | Deletion protection; PITR and backups |
| Long-term retention or isolation from the account | AWS Backup with cross-account copies and vault lock |
A Global Session Store
A gaming company stores player sessions in DynamoDB and serves players from three Regions. Writes for a player always come from the Region the player connects to, traffic doubles unpredictably during events, and a bug once overwrote thousands of items.
The table becomes a global table with replicas in the three Regions in on-demand mode, which absorbs event spikes without capacity planning. Because each player writes from one Region at a time, last writer wins is acceptable. PITR is enabled with 35 days of recovery, so a future bug can be reversed by restoring to a new table and copying back the affected items, and deletion protection guards the table. AWS Backup copies weekly backups to a separate backup account.
A provisioned table has plenty of unused capacity, but one product's items are throttled during promotions. What is the likely cause and how is it confirmed?
Show answer
A hot partition: traffic to one partition key exceeds the per-partition limit. CloudWatch Contributor Insights shows the most throttled keys; the fix is a higher-cardinality key design or caching with DAX.
Exam Tips
Remember for the exam
- DynamoDB replicates across three AZs automatically; global tables add multi-Region, multi-active replication with last writer wins (or multi-Region strong consistency for RPO zero).
- On-demand mode handles unpredictable spikes; provisioned mode with Application Auto Scaling target tracking suits steady traffic; GSIs need their own capacity.
- Diagnose hot partitions with CloudWatch Contributor Insights; each partition supports 3,000 RCUs and 1,000 WCUs.
- PITR (1 to 35 days) and backups protect against logical errors; restores create a new table without auto scaling, alarms or TTL settings.
- Deletion protection prevents table deletion.