How many records i can insert using DynamoDb BatchWrite by Boto3
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Amazon DynamoDB is a fast and flexible NoSQL database service designed to provide single-digit millisecond performance at any scale. When using Boto3 to interact with DynamoDB, one key feature is the ability to perform batch operations. The BatchWriteItem API allows you to efficiently insert or delete multiple items in a single request. This article will detail how many records you can insert in a single batch write operation using DynamoDB and Boto3, along with technical explanations, examples, and additional subtopics to give a comprehensive overview.
Understanding DynamoDB BatchWriteItem
Limits of BatchWriteItem
DynamoDB's BatchWriteItem API imposes certain limitations on the number of items you can process in a single batch write operation. These limitations are crucial for ensuring optimal performance and preventing throttling:
- Maximum Items: Each
BatchWriteItemcall can write up to 25 items. - Item Size: Each item can have a maximum size of 400 KB.
- Total Request Size: The total size of all items written in a single request must not exceed 16 MB.
These limitations ensure that a batch write operation remains efficient and manageable for both the client and DynamoDB.
Practical Implications
In practice, these limits mean that while you can process up to 25 writes in one request, if your items are large, you may hit the 16 MB limit before reaching the 25-item limit. As such, it's important to calculate the size of your data beforehand.
Using Boto3 to Perform Batch Writes
Boto3 is the AWS SDK for Python, and it provides a simple way to interact with DynamoDB. Below is an example of how you can perform a batch write using Boto3:
Error Handling and Retries
When performing batch writes, it's vital to manage errors and retries gracefully. DynamoDB can return unprocessed items, often due to throttling, which means these items must be retried. The BatchWriteItem response provides a list of unprocessed items, which you can loop over and resend in a subsequent request.
Key Considerations
Throughput and Costs
Using BatchWriteItem, although efficient, still consumes write capacity units (WCUs) similar to individual writes. Each item write counts against your provisioned or on-demand throughput capacity. Monitoring capacity usage and scaling appropriately can help manage costs and performance efficiently.
Conditional Writes
The BatchWriteItem API does not support conditional writes or updates. If you need conditional updates or deletes, you will need to use individual PutItem or DeleteItem operations instead.
Use with Care
Remember that batch operations are atomic only at the item level, not at the request level. Hence, not all items might be processed in the case of an error. Always check for unprocessed items as highlighted and handle them accordingly.
Summary Table
| Feature | Limit / Description |
| Maximum Items per Batch | 25 |
| Maximum Item Size | 400 KB |
| Maximum Request Size | 16 MB |
| Supports Conditional Ops | No |
| Error Retry Mechanism | Check UnprocessedItems and retry |
| Throughput Consumption | Consumes WCUs for each item written |
By understanding and utilizing these features and limitations of the BatchWriteItem API, you can optimize your DynamoDB interactions using Boto3 for performant, cost-effective data operations.
Related reading
- How redirect a domain to Amazon EC2 Machine?
- How reliable is AWS S3 Event Nofications on SQS?
- How secure are Amazon AWS Access keys?
- How should I automatically associate a Kubernetes-provisioned elastic load balancer with a Route 53 alias?
- How much space and processing will be optimized in Lucene index by storing a field as Byte instead of String for billions of documents
- How MySQL replicate the rows in a table ? and in which order
- How store an object in Dynamodb?
- How to Access header in AWS Lambda in 2018

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.