2

When querying a DynamoDB table, you may get back a LastEvaluatedKey parameter, indicating that the result is paginated and that LastEvaluatedKey is the primary key of the last item that was processed in this page. To fetch the next page, ExclusiveStartKey should be supplied with the value of the LastEvaluatedKey from the previous page.

However, if querying through all items and inside that loop deleting some items, I'm curious as to how DynamoDB handles scenarious like ExclusiveStartKey referencing an item which was just deleted. Will fetching the next page then fail, or does DynamoDB maintain deleted keys for the purpose of concurrent queries and deletes?

Example:

Items: A, B, C, D, E, F, G, H

Query({ExclusiveStartKey: undefined}) => A, B, C, D and LastEvaluatedKey: D
Query({ExclusiveStartKey: D}) => E, F, G, H and LastEvaluatedKey: undefined

But what happens if I (or another client in a concurrent scenario) delete item D between these two statements? Will the next page be returned as E, F, G, H or will it return no items since it cannot find where it left off due to D not existing anymore?

I don't simply want to perform a quick test this to determine how it works, since there might be factors such as the key being valid for some time after being deleted, or concurrency/replication/transactional issues at play, so I'm looking for a more definitive answer. I cannot find anything in the documentation covering this case.

JHH
  • 8,567
  • 8
  • 47
  • 91

1 Answers1

3

If I understand correctly, your concern is does DynamoDB pagination still work after you delete an item which is associated with pagination tokens (the lastEvaluatedKeys you kept). If that is the question, then pagination still works even after item is deleted. You can still use 'stale' lastEvaluatedKeys to the next pagination call, and DynamoDB is able to find out next batch of items.