How to setup Provisioned Throughput in DynamoDB?

To work with a DynamoDB table you need to first configure its throughput, which is basically how much do you read and write to a table per second.

DynamoDB is a fully managed NoSQL database service in AWS cloud. All data is stored in the form of key-value pairs and inside DynamoDB tables.

To work with a DynamoDB table you need to first configure its throughput, which is basically how much do you read and write to a table per second.

DynamoDB offers two kinds of capacity modes –

  • first one is Provisioned Throughput, where you define how much do you read/write upfront.
    When the reads/writes go beyond the configured limit, you get ProvisionedThroughputExceeded Exceptions in your code.
  • Second is On-Demand Throughput, where you don’t need to define anything before hand, Dynamo DB provisions automatically based on the demand, but is quite costly when compared to the provisioned throughput. So, generally we go with Provisioned Throughput as it is a more cost-effective solution.

In Provisioned Throughput, you configure your expected reads and writes in terms of units called Read Capacity Units (RCUs) and Write Capacity Units (WCUs)

What is a Write Capacity Unit (WCU) ?

One Write Capacity Unit (WCU) is the unit of capacity you need to write 1KB of data into DynamoDB in one second. Any item with size less than 1KB is rounded off to the nearest whole number.

So for example if you are writing 6 objects per second which are of 4.5KB in size, then you would require 6×5(4.5 rounded off) = 30 WCUs

What is a Read Capacity Unit (RCU) ?

For reads its a bit trickier, since DynamoDB offers two types of reads –

  • Eventually Consistent Reads
  • Strongly Consistent Reads

In an Eventually Consistent Read operation, when you read an item after a write operation you may get an older data.

In a Strongly Consistent Read operation, when you read an item after a write, you get the updated data.

For reads, one Strongly Consistent Read Capacity Unit (RCU) is the unit of capacity you would need to read 4 KB of data from Dynamo DB in one second.

Any item with size less than 4 KB is rounded off to the nearest 4 multiple.

So for example, if you want to read 10 items per second which are of 6 KB in size, then you would require (8KB/4KB)x10=20 RCUs [6KB is rounded off to nearest 4 multiple, which is 8KB]

You can do TWO Eventually Consistent Reads for one Strongly Consistent Read Capacity Unit, so for the above example you need 20/2=10 RCUs for Eventually Consistent Reads.

AWS Console provides you with a neat calculator under the Additional Configurations tab, where you can calculate and decide on the number of capacity units you would require for your use case.

RCU and WCU Calculator for DynamoDB

When you create a new table in DynamoDB, by default you are provided with 5 RCUs and 5 WCUs, which you can configure as per the above logic.


Buy Me A Coffee

Found this article helpful? Please consider supporting!

Ram
Ram

I'm a full-stack developer and a software enthusiast who likes to play around with cloud and tech stack out of curiosity. You can connect with me on Medium, Twitter or LinkedIn.

Leave a Reply

Your email address will not be published. Required fields are marked *