1

Say we have a table with average item size of 1 KB. We perform a query which reads 3 such items. Now according to what I have read, the number of RCUs should be (strongly consistent reads) : (Number of items read) * ceil(item_size/4) = 3 * ceil(1/4) = 3*1 = 3.

So wanted to confirm : is this correct? Or do we use a single RCU as total size of messages read is 3, which is less than 4.

Mooncrater
  • 4,146
  • 4
  • 33
  • 62
  • is this correct? - yes. Each items is treated as 4KB, even if its smaller. – Marcin Jun 10 '21 at 10:19
  • Ohkay. Thanks @Marcin. There is not much clarity on these questions in the docs, or the internet itself I think. – Mooncrater Jun 10 '21 at 10:23
  • [Here](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ProvisionedThroughput.html#ProvisionedThroughput.CapacityUnits.InitialSettings) more examples clarifying that. – Marcin Jun 10 '21 at 10:27
  • @Marcin This works for both on-demand and provisioned capacities right? – Mooncrater Jun 10 '21 at 10:29
  • 1
    I think so. I haven't heard of different RCU calculations for on-damand and provisioned capacities. – Marcin Jun 10 '21 at 10:33
  • Seems like the second option is correct for queries : https://stackoverflow.com/questions/50178275/how-are-consumed-read-capacity-units-calculated-in-dynamodb-query – Mooncrater Jun 10 '21 at 11:24
  • @Marcin I believe the answer from Charles is more accurate. A 'read' can be a getItem or a query. So if Mooncrater uses a query its 1 RCU but the same 'read' with getItem requests would be 3 RCU. I've not noticed AWS explicitly explaining this subtle difference anywhere. – F_SO_K Jun 11 '21 at 08:27
  • Actually, AWS *do* document this difference between getItem and query. Its in the same page you linked to but a bit further up https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ProvisionedThroughput.html#ItemSizeCalculations.Reads – F_SO_K Jun 11 '21 at 08:31

1 Answers1

4

An RCU is good for 1 strongly consistent read of up to 4KB.

Thus you can query() four 1KB items for 1 RCU.

Since you have only 3 to read, 1 RCU will be consumed.

Using GetItem() to get those same 3 records would cost 3 RCU.

Let say you had 100 items that matched (HK+SK) the query, but you're also using filter to further select records to be returned; so you're only getting 4 records back. That query would take 25 RCU, as the records still have to be read even if not returned.

Reference can be found here :

Query—Reads multiple items that have the same partition key value. All items returned are treated as a single read operation, where DynamoDB computes the total size of all items and then rounds up to the next 4 KB boundary. For example, suppose your query returns 10 items whose combined size is 40.8 KB. DynamoDB rounds the item size for the operation to 44 KB. If a query returns 1500 items of 64 bytes each, the cumulative size is 96 KB.

Mooncrater
  • 4,146
  • 4
  • 33
  • 62
Charles
  • 21,637
  • 1
  • 20
  • 44