undefined
undefined

Reputation: 6844

DynamoDB batchGet vs multiple getItem

Is there any difference in terms of cost or performance between using multiple getItem calls:

Promise.all([
     client.getItem({ TableName, Key }).promise(),
     client.getItem({ TableName, Key }).promise(),
     client.getItem({ TableName, Key }).promise(),
   ]

to one batchGet call:

const params = {
  RequestItems: {
    'TABLE_NAME': {
      Keys: [
        {'KEY_NAME': {N: 'KEY_VALUE_1'}},
        {'KEY_NAME': {N: 'KEY_VALUE_2'}},
        {'KEY_NAME': {N: 'KEY_VALUE_3'}}
      ]
    }
  }
};

db.batchGetItem(params).promise()

Upvotes: 4

Views: 2087

Answers (1)

Maurice
Maurice

Reputation: 13108

In terms of cost: No - both Operations consume the same number of Read Capacity Units.

In terms of performance: Yes - using multiple GetItem requests sends separate network requests for each of them and for BatchGetItem there is only one request, which should be quite a bit faster.

There is no real downside to BatchGetItem except for a slight increase in complexity when some items aren't found.

Upvotes: 5

Related Questions