Brooks
Brooks

Reputation: 7410

Does ReturnValue.ALL_OLD within DeleteItem and PutItem requests consume additional capacity?

I've been looking for a while now and cannot find anything definitive that specifies whether or not including ReturnValue.ALL_OLD within DeleteItem and PutItem requests consumes additional capacity.

On the one hand, it would make sense that it would because I can easily imagine it having to perform a separate read (which would hit your RCU).

On the other hand, the response JSON does not look like it has a way to specify both consumed READ capacity AND consumed WRITE capacity. DeleteItem and PutItem both consume write capacity, however I would assume if specifying ReturnValue.ALL_OLD did consume additional capacity, it would be read and I don't see AWS just lumping the two together in one value.

And on the other, other hand, the AWS documentation for UpdateItem specifically says there is no additional capacity consumed as a result of ReturnValue and UpdateItem is a write-based operation, like DeleteItem and PutItem.

https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_UpdateItem.html#API_UpdateItem_ReturnValues

Use ReturnValues if you want to get the item attributes as they appear before or after they are updated. For UpdateItem, the valid values are:

NONE - If ReturnValues is not specified, or if its value is NONE, then nothing is returned. (This setting is the default for ReturnValues.)

ALL_OLD - Returns all of the attributes of the item, as they appeared before the UpdateItem operation.

UPDATED_OLD - Returns only the updated attributes, as they appeared before the UpdateItem operation.

ALL_NEW - Returns all of the attributes of the item, as they appear after the UpdateItem operation.

UPDATED_NEW - Returns only the updated attributes, as they appear after the UpdateItem operation.

There is no additional cost associated with requesting a return value aside from the small network and processing overhead of receiving a larger response. No read capacity units are consumed.

Does anyone have any information from AWS or know of a definitive source for this question?

Upvotes: 3

Views: 2450

Answers (1)

Matthew Pope
Matthew Pope

Reputation: 7679

I know this to be true from my own experience, but I've put together a thorough answer so that you can be confident in it. Here are some relevant parts of the documentation, which I will follow with some comments on it.

UpdateItem (documentation)

You can also return the item's attribute values in the same UpdateItem operation using the ReturnValues parameter.

...

There is no additional cost associated with requesting a return value aside from the small network and processing overhead of receiving a larger response. No read capacity units are consumed.

The values returned are strongly consistent.

PutItem (documentation)

You can return the item's attribute values in the same operation, using the ReturnValues parameter.

...

The ReturnValues parameter is used by several DynamoDB operations; however, PutItem does not recognize any values other than NONE or ALL_OLD.

DeleteItem (documentation)

In addition to deleting an item, you can also return the item's attribute values in the same operation, using the ReturnValues parameter.

...

The ReturnValues parameter is used by several DynamoDB operations; however, DeleteItem does not recognize any values other than NONE or ALL_OLD.


I think there are a few things to note here.

  • All three APIs mention that the values can be returned in the same operation. Only UpdateItem explicitly states that you do not consume any RCU. Let me ask you this: does it cost extra read capacity to do a conditional delete since DynamoDB has to first read the item to check the condition? No. DynamoDB is pretty consistent that one operation can be either read or write, but never both, and in this case, it is clear that ReturnValues is always part of the same operation.
  • The documentation explicitly calls out the fact that the ReturnValues is used by several of the API methods, and it explicitly calls out the differences when there are differences. The documentation does not mention any difference in how ReturnValues affects the consumed capacity.

You can also run a simple experiment yourself to see if this is true.

  1. Create a new table, setting the read capacity to 1 and setting the write capacity to >=10.
  2. Write a script that will alternate between PutItem and DeleteItem (requesting return values for both) until you think you have enough data points. (Once should be enough, but it will be easier to see it in the table metrics if you do it several times a second for maybe 1 minute.)
  3. If returning the old values does consume read capacity, you should see consumed read capacity that (approximately) matches the consumed write capacity in the table metrics.
  4. If you run it for long enough at >1 request per second, then if and only if you are charged for reads, then you will eventually see some read throttling. (You need to have a sustained load that will use up all the burst capacity. If you can run it at 10 requests per second, then it will be less than a minute before your burst read capacity would be consumed if it's using any read capacity at all.)

Update: I did some manual testing, and I confirmed that a write with return values does not consume any RCU.

Upvotes: 2

Related Questions