0
0
DynamodbHow-ToBeginner ยท 3 min read

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

OperationItem Size LimitCapacity Unit Definition
Write Capacity Unit (WCU)1 KB1 write per second for an item up to 1 KB
Read Capacity Unit (RCU) - Strongly Consistent4 KB1 strongly consistent read per second for an item up to 4 KB
Read Capacity Unit (RCU) - Eventually Consistent4 KB1 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.