How does DynamoDB LastEvaluatedKey work internally?

Viewed 211

DynamoDB documentation (such as here) explains how to use LastEvaluatedKey to paginate through results. I know that it works, but I would like to understand how. As far as I know DynamoDB builds an unordered hash index on the partition key. Shouldn't that mean that if you give it a key, it doesn't know which keys are before or after it -- because it's not ordered? So how does it then know which keys follow the LastEvaluatedKey? How does this index work? Are new items/keys just appended to it? What happens to deleted items/keys?

1 Answers

Query(), which you've linked too, is only useful with a composite (partition + sort) key, and thus the result set is ordered.

Scan() can be used with just a partition key. So in a sense the results is "un-ordered" within a given partition. For that matter, I don't is it guaranteed that the logical first partition key will be the first scanned partition.

However, Amazon isn't magic. There's still some physical (and/or logical) order of the data, they may not publish the internals, and the order you see today may not be the one you see tomorrow. but Scan() by definition, starts at the beginning and goes to the end. You can't have a beginning or an end without an order in-between.

Related