What is Read Capacity Unit in DynamoDB: Explained Simply
Read Capacity Unit (RCU) in DynamoDB represents one strongly consistent read per second for an item up to 4 KB in size. For eventually consistent reads, one RCU can handle two reads per second of items up to 4 KB. It helps control and measure the read throughput capacity of your DynamoDB table.How It Works
Think of a Read Capacity Unit (RCU) as a ticket that lets you read data from DynamoDB. Each ticket allows you to read one item up to 4 KB in size per second if you want a strongly consistent read, which means you get the most up-to-date data. If you are okay with eventually consistent reads, which might be slightly out of date but faster, one ticket lets you read two items of up to 4 KB each per second.
This system helps DynamoDB manage how much data you can read at once without slowing down. If your items are larger than 4 KB, DynamoDB uses more tickets (RCUs) to read them. For example, reading an 8 KB item strongly consistently uses 2 RCUs because it is twice the size of 4 KB.
By setting the number of RCUs, you tell DynamoDB how much read traffic your application expects. If you try to read more than your RCUs allow, DynamoDB will slow down or throttle your requests to keep the system stable.
Example
This example shows how to calculate the required RCUs for reading items from a DynamoDB table using Python and the AWS SDK (boto3). It assumes you want to read 10 items per second, each 6 KB in size, with strongly consistent reads.
import math # Item size in KB item_size_kb = 6 # Number of items to read per second read_per_second = 10 # Calculate RCUs needed per item (round up) rcu_per_item = math.ceil(item_size_kb / 4) # Total RCUs needed total_rcus = rcu_per_item * read_per_second print(f"RCUs needed: {total_rcus}")
When to Use
Use Read Capacity Units when you choose the provisioned capacity mode in DynamoDB. This mode is best when you know your application's read traffic in advance and want to control costs by setting a fixed number of RCUs.
For example, if you run an online store and expect about 100 product page views per second, you can calculate the RCUs needed based on the size of each product item and set your table's read capacity accordingly. This helps avoid unexpected throttling or overspending.
If your read traffic varies a lot or is unpredictable, consider using on-demand capacity mode instead, which automatically adjusts RCUs for you.
Key Points
- One RCU = one strongly consistent read per second for an item up to 4 KB.
- One RCU = two eventually consistent reads per second for items up to 4 KB.
- Larger items consume more RCUs, rounded up per 4 KB chunk.
- RCUs help manage and control read throughput in provisioned mode.
- Choosing the right RCUs prevents throttling and controls costs.