DynamoDB query() versus getItem() for single-item retrieval based on the index

Amazon Web-ServicesAmazon Dynamodb

Amazon Web-Services Problem Overview


If I'm retrieving a single item from my table based on the indexed hash key, is there a performance difference between query() or getItem()?

Amazon Web-Services Solutions


Solution 1 - Amazon Web-Services

getItem will be faster

getItem retrieve via hash and range key is a 1:1 fit, the time it takes (hence performance) to retrieve it is limited by the hash and sharding internally.

Query results in a search on "all" range keys. It adds computational work, thus considered slower.

Solution 2 - Amazon Web-Services

In Amazon's DynamoDB, your performances are guaranteed whatever the access method. (you pay for it).

There may be a couple a milliseconds differences on the DynamoDB servers themselves as suggested by Chen Harel but these are negligible because of the HTTP request RTT.

This said, it's a good practice to issue a GET instead of QUERY when you have enough informations to do so.

Solution 3 - Amazon Web-Services

As suggested by aws employee in one of the discussion, I quote:

> The latency of GetItem vs Query with limit=1 will be equivalent.

AWS discussion link

Solution 4 - Amazon Web-Services

There is no performance difference between the two. The hash calculation in both the queries are done 1 by 1. The latter, i.e., get item is just provided as an analogy to the JPA repository/spring findOne/findById to make wiring in Spring Bean wiring/ Hibernate configs easier.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionensnareView Question on Stackoverflow
Solution 1 - Amazon Web-ServicesChen HarelView Answer on Stackoverflow
Solution 2 - Amazon Web-ServicesyadutafView Answer on Stackoverflow
Solution 3 - Amazon Web-ServicesDeep PatelView Answer on Stackoverflow
Solution 4 - Amazon Web-ServicespurpleguyView Answer on Stackoverflow