AWS DynamoDB Provisioned Throughput Exceeded Fix
In this tutorial, you'll learn about AWS DynamoDB Provisioned Throughput Exceeded Fix. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.
Your DynamoDB query returns ProvisionedThroughputExceededException — you have exceeded the provisioned read or write capacity for the table or global secondary index.
Step-by-Step Fix
1. Check current consumed capacity
aws dynamodb describe-table --table-name my-table --query 'Table.{ReadCapacity:ProvisionedThroughput.ReadCapacityUnits,WriteCapacity:ProvisionedThroughput.WriteCapacityUnits}'
Expected output:
{
"ReadCapacity": 5,
"WriteCapacity": 5
}
2. Increase provisioned capacity
# Wrong: no capacity increase
# Your table stays at 5 RCU / 5 WCU and keeps throttling
# Right: increase capacity for the workload
aws dynamodb update-table \
--table-name my-table \
--provisioned-throughput ReadCapacityUnits=50,WriteCapacityUnits=50
Expected output:
{
"TableDescription": {
"TableStatus": "UPDATING"
}
}
3. Implement exponential backoff in application code
import boto3
import time
import random
dynamodb = boto3.client('dynamodb')
def put_item_with_retry(table_name, item, max_retries=5):
for attempt in range(max_retries):
try:
response = dynamodb.put_item(
TableName=table_name,
Item=item
)
return response
except dynamodb.exceptions.ProvisionedThroughputExceededException:
if attempt == max_retries - 1:
raise
wait_time = (2 ** attempt) + random.uniform(0, 1)
print(f"Throttled. Waiting {wait_time:.2f}s (attempt {attempt + 1})")
time.sleep(wait_time)
# Use the retry function
item = {
'pk': {'S': 'user_123'},
'sk': {'S': 'order_456'},
'status': {'S': 'pending'}
}
put_item_with_retry('my-table', item)
4. Switch to On-Demand capacity
# Switch from provisioned to on-demand for bursty traffic
aws dynamodb update-table \
--table-name my-table \
--billing-mode PAY_PER_REQUEST
5. Use DynamoDB Accelerator (DAX) for reads
# Create a DAX cluster for read-heavy workloads
aws dax create-cluster \
--cluster-name my-dax \
--node-type dax.r5.large \
--replication-factor 3 \
--iam-role-arn arn:aws:iam::123456789012:role/dax-role \
--subnet-group-name my-subnet-group
from amazon.dax import AmazonDaxClient
import boto3
# Use DAX client for cached reads
dax_client = AmazonDaxClient(session=boto3.Session(), endpoints=['my-dax.cluster:8111'])
response = dax_client.get_item(TableName='my-table', Key={'pk': {'S': 'user_123'}})
Prevention
- Monitor DynamoDB throttling metrics in CloudWatch with alarms.
- Use auto-scaling to adjust capacity automatically.
- Implement exponential backoff with jitter in all SDK calls.
- Use DAX for read-heavy workloads to reduce read capacity consumption.
- Design partition keys that distribute traffic evenly across partitions.
Common Mistakes with DynamoDB capacity
- Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch errors
- Non-exhaustive pattern matches that compile with warnings then crash at runtime
- Misunderstanding that
Stringis[Char]with poor performance for large text operations
These mistakes appear frequently in real-world AWS code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro