Calculating WCU and RCU for Amazon DynamoDB

DynamoDB is a fully managed NoSQL database provided by Amazon Web Services (AWS). It’s considered a “serverless” database because there is no infrastructure to manage, but you do need to manage the provisioned capacity.

There are two configurable capacity units for DynamoDB, read capacity units (RCU) and write capacity units (WCU). These configurable units control your read and write throughput respectively.

So if you are considering DynamoDB for a new project or are simply wanting to have a better understanding of the capabilities of DynamoDB, then it’s vital that you understand how these work as they have a direct impact on:

  1. How much you spend on DynamoDB
  2. The throughput capacity of your tables, which in turn impacts the number requests your application will be able to handle

Read Capacity Units

There are two consistency models supported by DynamoDB, eventually consistent (default) and strongly consistent.

Eventually consistent reads give you higher throughput as the cost of not always returning the latest data. The

In contrast, strongly consistent reads always return the latest data at the cost of reduced throughput.

Both of these consistency models work with items of up to 4KB in size, the difference being eventually consistent reads provide 2 x 4KB reads per 1 RCU, whereas strongly consistent reads only provide 1 x 4KB reads per RCU.

Calculating Read Capacity Units

Read ConsistencyCapacity Units (RCU)Read Requests per second (r)Item Size (i)
Eventually consistent124KB
Strongly consistent114KB

The table above illustrates the difference between a strongly consistent read and an eventually consistent read.

In order to calculate how much RCUs your application needs you can use the following formula.

\huge \lceil \frac{ x \times \lceil\frac{y}{i}\rceil}{r}\rceil = \large RCU

Where x is the expected number of reads per second and y is the size of the item in KB.

Let’s put this into practice with an example:

You need to calculate the required RCU’s for an application which using a DynamoDB table as it’s persistent data store. The application has an average of 1000 reads per minute with an item size of 30KB, the reads can be eventually consistent in order to maximize throughput. We could apply the formula above as follows.

\Large \frac{1000}{60} = 16.6666\overline{6}

\Large \lceil \frac{ 16.6\overline{6} \times \lceil\frac{30}{4}\rceil}{2}\rceil = \large RCU

\Large \lceil \frac{ 16.6\overline{6} \times 8}{2}\rceil = \large RCU

\Large \lceil \frac{ 133.3\overline{3}}{2}\rceil = \large RCU

\therefore RCU = 67

As a result I could adjust the read capacity units of my table to be 67! Or can I?

In theory we need 67 RCU’s for this application but there are other factors you may need to consider. If I put the same numbers into the AWS DynamoDB calculator it gives me a recommendation of 68 RCU’s.

As I’m not 100% sure how this calculated, I’m just going to put this down to being a rounding error or perhaps they are using some other method to calculate size.

Write Capacity Units

Similarly, other configurable capacity unit is write capacity units (WCU) and as the name suggest this controls the write throughput to your DynamoDB table.

Calculating the required write capacity units is simpler because a consistency model doesn’t apply here. One write capacity unit will give you one write per second of an item up to 1KB in size.

Capacity Units (RCU)Read Requests per second (r)Item Size (i)

To calculate the required WCU’s, we can use the following formula.

\Large x \times y = \large WCU

Where x is the expected number of writes per second and y is the size of the item in KB.

So hopefully now you have a better understanding of how you can calculate the throughput requirements for DynamoDB.

In conclusion, we’ve only just scratched the surface when it comes to optimization of DynamoDB tables, I will be putting up some follow up articles on table partitioning and table monitoring in the next few weeks which are also important to understand.

So stay tuned … until then here are some useful references.