Read capacity cost of a DynamoDB table scan
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Overview of DynamoDB Table Scan Costs
Amazon DynamoDB is a fully managed NoSQL database service that provides quick, predictable performance and seamless scalability. It automatically distributes data and traffic over a sufficient number of servers to handle request capacity and performance. However, understanding the cost implications, particularly read and write capacity units, is crucial for effective provisioning and optimization. This article delves into the read capacity cost associated with DynamoDB table scans.
Understanding Read Capacity
Provisioned Mode
In Provisioned Mode, you need to specify the number of read and write operations per second that your application requires. The pricing is based on the amount of computing capacity provisioned at fixed hourly rates:
- Read Capacity Unit (RCU): One read capacity unit represents one strongly consistent read per second, or two eventually consistent reads per second, for an item up to 4 KB in size.
On-Demand Mode
On-Demand Mode charges you only for the read and write requests you actually use, instead of provisioning. However, understanding RCUs remains important as they have an impact on your operation's performance.
Table Scan and Its Read Capacity Implications
When performing a table scan in DynamoDB, every item in the table is read. This operation is intensive and can be expensive if not managed efficiently. Scans consume read capacity units based on the size and consistency requirements of the items.
Calculating Read Capacity for Scans
The read capacity consumed by a scan operation depends on:
- Item Size: Larger items require more read capacity. Compute the number of required RCUs based on the total data size.
- Read Consistency: Strongly consistent reads use more RCUs compared to eventually consistent reads.
- Result Set Size: The number of items that match the filter criteria or the entire table size if no criteria are applied.
Example Calculation
Suppose you scan a table with the following properties:
- Table contains items where each is 8 KB in size.
- You perform a strongly consistent scan.
For a strongly consistent scan, each 8 KB item will consume 2 RCUs because:
- 1 RCU allows 1 strongly consistent read up to 4 KB.
- Since each item is 8 KB, it consumes 2 RCUs per read (8 KB / 4 KB = 2).
Summary Table
| Parameter | Calculation | RCU Consumption |
| Item Size | 8 KB (per item) | Each item requires 2 RCUs for strongly consistent read (8 KB / 4 KB = 2) |
| Read Consistency Mode | Strongly Consistent | 2 RCUs per 8 KB item |
| Total Data Size | Total items * Item Size | E.g., 1000 items * 8 KB = 8000 KB (8000 KB / 4 KB * 2 = 4000 RCUs) |
Optimizing Table Scan Costs
To reduce costs associated with scanning:
- Use Queries Over Scans: Queries target specific partitions and are more efficient in terms of read capacity.
- Implement Projection Expressions: Retrieve only necessary attributes to lower read capacity usage.
- Apply Filters: Even though filters are applied post-scan and don’t reduce RCU usage, they threshold return data.
- Limit and Pagination: Implement pagination or setting limits to control data returned per call.
- Increase Use of GSI and LSI: Secondary indexes enable more fine-tuned queries without large scans.
Conclusion
Understanding and optimizing read capacity costs in DynamoDB table scans can greatly affect the performance and expense of your DynamoDB setup. By understanding how RCUs are consumed and leveraging efficient data access patterns, you can maintain a performant and cost-effective cloud database solution. As always, continuous monitoring and adjustment based on workload are key to maximizing the benefits of Amazon DynamoDB.
Related reading
- read dynamodb and get redundant Decimal word
- Read file content from S3 bucket with boto3
- Read file from aws s3 bucket using node fs
- Read, Modify and Update on AWS S3 atomically
- read line by line in the most efficient way platform specific
- Rearrange a list of points to reach the shortest distance between them
- Reading a file from a private S3 bucket to a pandas dataframe
- Reading a JSON file from S3 using Python boto3

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.