In this article, I will learn about Amazon DynamoDB Throughput Capacity Provisioned Mode. This is also the default mode when you create a new table in Amazon DynamoDB. We will also see examples when designing DynamoDB using Provisioned Mode, how will it consume RCU and WCU?
What is RCU? What is WCU?
Amazon DynamoDB has no table size limit, data storage is horizontally expanded, so dynamodb is ideal for storing huge data sets. Moreover, the storage of dynamodb is also flexible, there is no need to be rigid about how much space to allocate 10GB or 1TB initially. Storage will automatically expand as you have more data. This reduces the worry of having to operate and maintain a database.
But that’s only in terms of storage, when using dynamodb you need to see how much read and write capacity you need which DynamoDB calls RCU (Read Capacity Unit) and WCU (Write Capacity Unit).
The default when initializing a table in amazon dynamodb capacity mode will be Provisioned with 05 WCUs and 05 RCUs.
- 1 RCU = 1 strong read consistency request = 2 eventual consistency requests
- 1 WCU = 2 write requests
Each Read request can be maximum 4KB, write request is 1KB.
Some examples of RCU, WCU to better understand dynamodb:
- Write 1KB => 1 WCU
- Write 3KB => 3 WCU
- Write 1.5KB => 2 WCUs (round up)
- Read 4KB => 1 RCU strong consistency, 0.5 eventual consistency
- Read 2KB => 1 RCU strong consistency, 0.5 eventual consistency
- Read 8KB => 2 RCU strong consistency, 1 eventual consistency
- Read 7KB => 2 RCU strong consistency, 1 eventual consistency
- Read 15KB => 4 RCU strong consistency, 2 eventual consistency
Thus the cost of strong consistency is twice (2x) the read cost of eventual consistency.
Difference between Strong Consistency and Eventual Consistency
Eventual Consistency is a read mechanism that doesn’t guarantee you read the final data (stale data) but offers fast speed and is less than half the cost of strong consistency.
Strong consistency is a reading mechanism that ensures the data you read is the most up-to-date. The cost of strong consistency is twice as expensive as eventual consistency. Strong consistency can fail if the network has problems.
By default dynamodb uses Eventual Consistency. In some cases where you need final up-to-date data such as financial statements or ticketing systems, you may need to use strong consistency.
Transactional Request in DynamoDB also consumes RCU and WCU. In general, transactional requests will cost twice as much as usual.
- 1 Transactional Read = 2 RCUs (for items up to 4KB)
- 1 Transactional Write = 2 WCUs (for items up to 1KB)
Note that in case when a read or write request exceeds the allocation limit of the dynamodb table, it will result in throttled.
To get a better idea of the throughput capacity calculation, let’s look at the following two examples:
Example 1: Suppose we allocate 10 RCUs and 10 WCUs. Let’s see the maximum capacity of this dynamodb table:
- Read throughput
- Strong consistency read: 10 * 4KB * 1 = 40KB/s
- Eventual consistency read: 10 * 4KB * 2 = 80KB/s
- Transactional Read consistency: 10 * 4KB / 2 = 20KB/s
- Write throughput
- Eventual & Strong consistency: 10*1KB*1 = 10KB/s
- Transactional Write consistency: 10*1KB/2 = 5KB/s
Example 2: Calculate the required RCU and WCU when reading and writing 15KB item
- Read capacity
- Strong consistency read: roundup(15/4)*1 = 4 RCUs
- Eventual consistency read: roundup(15/4)/2 = 2 RCUs
- Transactional read consistency: roundup(15/4)*2 = 8 RCUs
- Write capacity
- Strong & Eventual write: 15*1KB = 15 WCUs
- Transactional write consistency: 15*2 = 30 WCUs
In this article we have learned about Amazon DynamoDB throughput capacity Provisioned mode. This mode allows us to predefine the read and write capacity of a dynamodb table. We have also seen some examples of calculating the capacity of the dynamodb table in two cases. Wish you have the right design so that your database is not throttled.