How does AWS DynamoDB count read units for Query?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Understanding AWS DynamoDB Read Capacity Units for Query Operations
Amazon DynamoDB is a fully managed NoSQL database service that provides fast, predictable performance with seamless scalability. One of the key elements of managing DynamoDB is understanding its pricing and performance, particularly when it comes to read operations. In DynamoDB, read capacity is measured in terms of "Read Capacity Units" (RCUs). This article delves into how DynamoDB counts RCUs for query operations, providing an in-depth explanation and examples.
The Basics of DynamoDB Read Capacity
In DynamoDB, a Read Capacity Unit corresponds to one strongly consistent read per second, or two eventually consistent reads per second, for items up to 4 KB in size. This means if you are reading an item larger than 4 KB, it will consume additional RCUs.
Consistency Models in DynamoDB
DynamoDB offers two read consistency models:
- Strongly Consistent Reads: Return a result that reflects all writes that received a successful response prior to the read. This ensures the most updated data, but it also consumes more resources.
- Eventually Consistent Reads: Deliver results that might reflect some but not necessarily all writes. These reads achieve better performance by using fewer resources.
How Query Operations Use RCUs
The Query operation in AWS DynamoDB retrieves items based on their partition key and optionally filter them using sort keys or secondary indexes. The number of RCUs consumed by a Query operation depends on several factors:
- Size of Data Read: RCUs are calculated based on the total size of the data returned by the
Query, rounded up to the nearest 4 KB multiply. - Read Consistency: Using eventually consistent reads will halve the RCUs compared to using strongly consistent reads for the same data volume.
- Secondary Indexes: Performing a
Queryon a Global Secondary Index (GSI) or Local Secondary Index (LSI) will also impact the RCU calculation as each index might have different storage attributes.
Example of RCU Calculation
Suppose you perform a Query operation that returns three items, each being 6 KB in size, with a request for strongly consistent reads. The RCUs consumption would be calculated as follows:
- Total Data Read:
- Item 1: 6 KB
- Item 2: 6 KB
- Item 3: 6 KB
- Total: 18 KB
- Calculate for RCU:
- Each 4 KB costs 1 RCU for a strongly consistent read.
- Total size of 18 KB would require RCUs.
If the same request is made using eventually consistent reads, the RCUs reduce to:
- Half of a strongly consistent read = RCUs, rounded up = 3 RCUs.
Factors Influencing RCU Usage
- Pagination: For large result sets, DynamoDB may require pagination, meaning multiple requests may be necessary to retrieve all data, each potentially consuming additional RCUs.
- Attribute Projections: Queries that fetch unnecessary attributes may result in higher data sizes and consequently higher RCU consumption.
- Return Values: The amount of data transferred over the network will be added, and items not completely fitting into a 4 KB boundary will result in a full 4 KB unit consumption.
Optimizing Read Capacity Usage
To optimize the usage of RCUs and thus reduce costs:
- Use eventually consistent reads where feasible.
- Tailor queries to fetch only the required attributes to minimize data size.
- Design efficient table structures and indexes to reduce unnecessary data retrieval.
Summary Table
| Factor | Strongly Consistent | Eventually Consistent |
| RCU per 4 KB | 1 RCU | 0.5 RCU |
| 6 KB Read Count | 2 RCUs | 1 RCU |
| Data Size Rounding | Up to nearest 4 KB interval (5 KB = 2 units) | Up to nearest 4 KB interval (5 KB = 1 unit) |
| Application Use Case | Need the most updated data | Can tolerate slight delays in data reflection |
| Cost Efficiency | Higher | Lower |
In conclusion, understanding DynamoDB's RCU metrics and optimization methods can significantly improve application performance and reduce operational costs. By carefully choosing consistency models and structuring queries to minimize data retrieval, organizations can leverage DynamoDB's capabilities efficiently.

