Home > Blockchain >  DynamoDB batchGet vs multiple getItem
DynamoDB batchGet vs multiple getItem

Time:03-31

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()

CodePudding user response:

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.

  • Related