DynamoDB interview question · Most asked
How do you calculate read and write capacity units?
Summary
One WCU writes one item of up to 1 KB per second; one RCU performs one strongly consistent read (or two eventually consistent reads) of up to 4 KB per second. Sizes round up, and transactional reads and writes cost twice as much.
Longer Answer
Examples:
- Writing a 3.5 KB item: 4 WCU.
- Strongly reading a 9 KB item: 3 RCU (9/4 rounded up). Eventually consistent: 1.5 RCU.
- Query returning 40 items of 1 KB each: total 40 KB / 4 KB = 10 RCU strongly consistent (queries sum the sizes, then round up), 5 eventually consistent.
- Each GSI adds write units for every write that touches it.
On-demand pricing uses request units with the same size rules. Small items and narrow projections save money.
Key Points
- WCU: 1 KB writes; RCU: 4 KB reads.
- Eventual reads cost half.
- Transactions cost double.
- GSIs add write cost.
More most-asked DynamoDB questions
- What are DynamoDB Streams, and how are they used?
- Query or Scan: what is the difference, and why avoid Scan?
- What is DynamoDB, and what workloads is it a good fit for?
- What is a hot partition, and how do you avoid one?
- How do you approach data modelling in DynamoDB, and how is it different from relational design?
- Explain partition keys, sort keys and the two kinds of primary key.
- Global secondary index or local secondary index: what is the difference?
- How do conditional writes work, and how do you implement optimistic locking in DynamoDB?