Calculating WCU and RCU
WCU
1 WCU → 1 write per second up to 1kb
Examples:
12 writes per second of 2kb = 12 * (2/1) = 24 WCU needed
24 items per minute of 3kb = (24/60) * (3/1) = 1.2 WCU needed
RCU
Two modes: Eventually consistent or strongly consistent
1 RCU = 1 strongly consistent or 2 eventual consistent of items up to 4kb (You have to round up to nearest 4kb if anything in between)
Examples:
20 reads per second of 3.5kb (strong consistent) = 20 * (4/4) = 20 RCU
20 reads per second of 3.5kb (eventual consistent) = (20/2) * (4/4) =10 RCU
DynamoDB –Throttling
- If we exceed provisioned RCUs or WCUs, we get “ProvisionedThroughputExceededException”
- Reasons:
- Hot Keys – one partition key is being read too many times (e.g., popular item)
- Hot Partitions
- Very large items, remember RCU and WCU depends on size of items
- Solutions:
- Exponential backoff when exception is encountered (already in SDK)
- Distribute partition keys as much as possible
- If RCU issue, we can use DynamoDB Accelerator (DAX)
DynamoDB – Conditional Writes
- For PutItem, UpdateItem, DeleteItem, and BatchWriteItem
- You can specify a Condition expression to determine which items should be modified:
- attribute_exists
- attribute_not_exists
- attribute_type
- contains (for string)
- begins_with (for string)
- ProductCategory IN (:cat1, :cat2) and Price between :low and :high
- Note: Filter Expression filters the results of read queries, while Condition Expressions are for write operations