How to handle UnprocessedItems using AWS JavaScript SDK dynamoDB?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Overview
When working with DynamoDB using the AWS JavaScript SDK, it's common to perform batch operations such as BatchWriteItem or BatchGetItem. These operations can include up to 25 PutItem or DeleteItem requests and 100 GetItem requests, respectively. However, due to limitations such as size constraints or DynamoDB's capacity settings, not all items in these requests may be processed. This is where handling UnprocessedItems becomes crucial.
UnprocessedItems, as the name suggests, are items that DynamoDB was unable to process in the original request. These can occur for several reasons, and handling them correctly ensures robustness in your application.
Understanding UnprocessedItems
Before diving into the implementation, it’s critical to understand the nature of UnprocessedItems:
- Capacity Exceedance: If the provisioned throughput limit has been exceeded, some items may remain unprocessed.
- Size Limit: DynamoDB batches have a size limit, and items exceeding that can result in
UnprocessedItems. - Internal Issues: Sometimes, transient issues within DynamoDB result in items being left unprocessed.
Handling UnprocessedItems involves reattempting these unprocessed items until they have been successfully written or retrieved.
Handling UnprocessedItems using AWS SDK for JavaScript
Prerequisites
Make sure you have the following prerequisites:
- AWS SDK for JavaScript installed in your project:
- AWS Credentials properly configured:
- Through the
AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEYenvironment variables or your AWS credentials file.
- DynamoDB table set up with appropriate read/write capacity settings.
Handling in BatchWriteItem
Here's how you'd effectively handle UnprocessedItems in a BatchWriteItem request:
Handling in BatchGetItem
Similarly, to handle UnprocessedItems in a BatchGetItem request:
Additional Considerations
- Backoff Strategy: Implementing an exponential backoff with jitter is recommended to handle retries, especially in high-load scenarios.
- Error Handling: Ensure that your application logs these errors and handles them according to your use case.
- Provisioned Throughput: Make sure your table’s provisioned throughput settings align with your use case's demand to minimize unprocessed items.
Summary
The table below summarizes key strategies when handling UnprocessedItems:
| Aspect | Strategy |
| Reason for UnprocessedItems | Capacity limits, size constraints, internal issues |
| Retry Mechanism | Use a loop with a retry count and handle errors |
| Maximum Retries | Configure according to your needs (e.g., 5 retries) |
| Exponential Backoff | Implement backoff to prevent rapid retries in case of errors |
| Logging and Monitoring | Log retry attempts and errors to enhance observability |
| Table Capacity Considerations | Ensure your table’s capacity aligns with use cases and expected load |
By understanding and properly implementing these strategies, your application can handle UnprocessedItems in DynamoDB effectively, ensuring data consistency and reliability.
Related reading
- How to identify the storage space left in a persistent volume claim?
- How to import existing VPC in aws cdk?
- How to improve random number generation in kubernetes cluster containers?
- How to improve slow uploading to Amazon S3
- How to have a processor intensive function update every tick of the metronome and draw to canvas using web workers?
- How to implement a Promise retry and undo
- how to include and copy files that are in current directory to s3 and not recursively
- How to increase aws dynamodb index limit from 5

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.