Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does GetItem/BatchGetItem compare to Querying and Scanning a DynamoDB table in terms of efficiency?

Specifically, when is it better to use one or the other? I am using BatchGetItem now and it seems pretty damn slow.

like image 662
sometimesiwritecode Avatar asked Sep 13 '16 17:09

sometimesiwritecode


1 Answers

In terms of efficiency for retrieving a single item, for which you know the partition key (and sort key if one is used in the table), GetItem is more efficient than querying or scanning. BatchGetItem is a convenient way of retrieving a bunch of items for which you know the partition/sort key and it's only more efficient in terms of network traffic savings.

However, if you only have partial information about an item then you can't use GetItem/BatchGetItem and you have to either Scan or Query for the item(s) that you care about. In such cases Query will be more efficient than Scanning since with a query you're already narrowing down the table space to a single partition key value. Filter Expressions don't really contribute all that much to the efficiency but they can save you some network traffic.

There is also the case when you need to retrieve a large number of items. If you need lots of items with the same partition key, then a query becomes more efficient than multiple GetItem (or BatchGetItem calls). Also, if you need to retrieve items making up a significant portion of your table, a Scan is the way to go.

like image 135
Mike Dinescu Avatar answered Oct 22 '22 02:10

Mike Dinescu