Search code examples
amazon-web-servicesperformanceamazon-dynamodblatencythroughput

BatchPutItem vs PutItem in DynamoDB


I have a use case where we don't get that many cases where there are list of entries in a single request to be updated and mostly, it is the case where only a single entry is requested to be updated. But in future, this might grow and hence I was thinking of using BatchPutItem instead of PutItem.

  • Are there any disadvantages using BatchPutItem when the there is only a single item to be updated in the request?
  • I think the RCUs consumed are the same, but are there any other differences or the BatchPutItem will behave same as PutItem when there is only a single entry in the request?

Solution

  • From a monetary cost perspective, it shouldn't matter - the WCUs consumed are the same. The benefit of the Batch API is that fewer requests go over the wire and thus reduce the overall latency for writing multiple items.

    The error handling is different between the two APIs and it requires a bit of additional complexity to deal with BatchPutItem. Even if the BatchPutItem request is successful, individual item writes may have failed and you need to inspect the response from the API and retry and failed writes yourself.

    The regular PutItem would fail in a more straightforward way by returning an error / raising an exception.

    This is just something to keep in mind and if you're going to use BatchWriteItem anyway, you'll have to build logic for that in any case and this wouldn't be a drawback.

    tl;dr: Using BatchWriteItem with a single item should have no drawbacks in your case, because you'll have to build the retry logic anyway.