How to Fix Provisioned Throughput Exceeded Error in DynamoDB
The
ProvisionedThroughputExceededException in DynamoDB happens when your requests exceed the set read or write capacity. To fix it, increase your table's provisioned capacity or switch to on-demand mode, and implement retries with exponential backoff in your code.Why This Happens
This error occurs because your application is sending more read or write requests than the capacity you set for your DynamoDB table. DynamoDB limits how many operations can happen per second based on your provisioned throughput settings. If you exceed these limits, DynamoDB returns the ProvisionedThroughputExceededException error.
javascript
const AWS = require('aws-sdk'); const dynamodb = new AWS.DynamoDB.DocumentClient(); const params = { TableName: 'MyTable', Item: { id: '123', data: 'example' } }; // This code writes many items quickly without handling throughput limits for (let i = 0; i < 1000; i++) { dynamodb.put(params, (err, data) => { if (err) console.log('Error:', err.code); }); }
Output
Error: ProvisionedThroughputExceededException
The Fix
To fix this, increase your table's provisioned read/write capacity or switch to on-demand mode to let DynamoDB handle scaling automatically. Also, add retry logic with exponential backoff in your code to handle temporary throttling gracefully.
javascript
const AWS = require('aws-sdk'); const dynamodb = new AWS.DynamoDB.DocumentClient(); const params = { TableName: 'MyTable', Item: { id: '123', data: 'example' } }; function putItemWithRetry(params, retries = 5) { dynamodb.put(params, (err, data) => { if (err && err.code === 'ProvisionedThroughputExceededException' && retries > 0) { const delay = Math.pow(2, 5 - retries) * 100; // exponential backoff setTimeout(() => putItemWithRetry(params, retries - 1), delay); } else if (err) { console.error('Failed:', err); } else { console.log('Success'); } }); } for (let i = 0; i < 1000; i++) { putItemWithRetry(params); }
Output
Success (for each item without throughput errors)
Prevention
To avoid this error in the future, consider these best practices:
- Use on-demand capacity mode if your traffic is unpredictable.
- Monitor your table's consumed capacity with CloudWatch and adjust provisioned capacity accordingly.
- Implement exponential backoff retries in your application to handle throttling smoothly.
- Use batch operations to reduce the number of requests.
- Design your data model to distribute traffic evenly across partition keys.
Related Errors
Other errors related to throughput limits include:
ThrottlingException: Happens when API request rate exceeds limits; fix by adding retries.RequestLimitExceeded: Too many requests in a short time; reduce request rate or use exponential backoff.InternalServerError: Temporary server issues; retry after delay.
Key Takeaways
ProvisionedThroughputExceededException means your requests exceed your table's capacity limits.
Increase provisioned capacity or switch to on-demand mode to fix throughput errors.
Add retry logic with exponential backoff to handle temporary throttling gracefully.
Monitor usage with CloudWatch and adjust capacity proactively.
Design your data model to spread traffic evenly across partitions.