How to Calculate Capacity Units in DynamoDB
In DynamoDB,
Read Capacity Units (RCUs) and Write Capacity Units (WCUs) measure throughput. One WCU represents one write per second for an item up to 1 KB, and one RCU represents one strongly consistent read per second for an item up to 4 KB. To calculate capacity units, divide your item size by these limits and multiply by the number of operations per second.Syntax
Capacity units are calculated based on item size and operation type:
- Write Capacity Units (WCU): Number of writes per second ร (item size in KB / 1 KB, rounded up)
- Read Capacity Units (RCU): Number of reads per second ร (item size in KB / 4 KB, rounded up) for strongly consistent reads
For eventually consistent reads, RCUs are halved because they consume half the capacity.
plaintext
WCU = writes_per_second * CEIL(item_size_bytes / 1024) RCU = reads_per_second * CEIL(item_size_bytes / 4096) # for strongly consistent reads RCU_eventual = RCU / 2 # for eventually consistent reads
Example
This example calculates the required capacity units for a table where each item is 3 KB, with 10 writes and 20 strongly consistent reads per second.
python
import math item_size_bytes = 3 * 1024 # 3 KB writes_per_second = 10 reads_per_second = 20 wcu = writes_per_second * math.ceil(item_size_bytes / 1024) rcu = reads_per_second * math.ceil(item_size_bytes / 4096) # strongly consistent print(f"Write Capacity Units needed: {wcu}") print(f"Read Capacity Units needed: {rcu}")
Output
Write Capacity Units needed: 30
Read Capacity Units needed: 20
Common Pitfalls
- Not rounding up item size when dividing by 1 KB or 4 KB can underestimate capacity needs.
- Confusing strongly consistent reads with eventually consistent reads affects RCU calculation.
- Ignoring item size variations leads to incorrect capacity planning.
Always use CEIL to round up and choose the correct read consistency.
python
import math # Wrong: not rounding up item_size_bytes = 2500 writes_per_second = 5 wcu_wrong = writes_per_second * (item_size_bytes / 1024) # 5 * 2.441 = 12.205 (incorrect) # Right: rounding up wcu_right = writes_per_second * math.ceil(item_size_bytes / 1024) # 5 * 3 = 15 (correct) print(f"Wrong WCU calculation: {wcu_wrong}") print(f"Correct WCU calculation: {wcu_right}")
Output
Wrong WCU calculation: 12.20703125
Correct WCU calculation: 15
Quick Reference
| Operation | Item Size Limit | Capacity Unit Definition |
|---|---|---|
| Write Capacity Unit (WCU) | 1 KB | 1 write per second for an item up to 1 KB |
| Read Capacity Unit (RCU) - Strongly Consistent | 4 KB | 1 strongly consistent read per second for an item up to 4 KB |
| Read Capacity Unit (RCU) - Eventually Consistent | 4 KB | 1 eventually consistent read per second consumes 0.5 RCU |
Key Takeaways
Calculate WCUs by dividing item size by 1 KB and rounding up, then multiply by writes per second.
Calculate RCUs by dividing item size by 4 KB and rounding up, then multiply by reads per second for strongly consistent reads.
Eventually consistent reads use half the RCUs of strongly consistent reads.
Always round up item size divisions to avoid under-provisioning capacity.
Consider item size and read/write frequency carefully to estimate capacity units accurately.