DynamoDB data type efficiency

0

When I query or scan a table with 10,000 rows, if I assign a field named ID as the primary key, and I perform a query or scan against that table, is it more efficient (speed) to define the Field as a Number or a String?

profile picture
Petrus
asked 2 months ago124 views
2 Answers
0

No, there is no difference which data type you use, you will get the same performance.

profile pictureAWS
EXPERT
answered 2 months ago
0

There is a nuance to be aware of with this data type choice - storing a number as a number is generally going to be a better choice than storing it as a string because it is smaller in storage. This means in the bigger picture it will result in a lower cost for the storage component of your DynamoDB bill. It also means the evaluated size of the item (for metering of read and write unit consumption) could be lower. It seems unlikely that this difference will make the difference of going over the 1KB/4KB boundary for most use cases, but when you think about Query or Scan, they actually add the size of potentially many such items before rounding up to the next boundary to assess read units consumed. Depending on item size this can mean the difference between getting say 1000 items per page from Query/Scan or maybe only 500 perhaps - so the overall time taken to page through the full result set could be significantly longer. Finally, storing a number as a string means it won't work well for sorting (if you ever use it as the sort key for a secondary index, for example).

I would recommend storing numbers as numbers in almost every case. Only store them as strings if you have a really good reason to do so.

answered 2 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions