8

A UUID is, according to the specification, 128 bits or 16 bytes. The hexadecimal representation is 36 characters including the hyphens. I'm building a new table on DynamoDB and I have to decide the Type for the Hash key which I plan on filling with UUIDs. Should I create the table with a Hash key that is a String or Binary for these UUIDs? My gut tells me byte, because its less than half the size so that saves bandwidth, space, etc.

Does anybody have experience one way or the other and have a good reason to go with one over the other?

Max
  • 8,671
  • 4
  • 33
  • 46

1 Answers1

8

I personally prefer using as many String based attributes/keys as possible mainly because it is easier to debug those in the AWS DynamoDB console.

I also feel that binaries were added for compressed and raw binary data which IMO UUIDs are not.

From a pure performance view, you are probably right - but I would stick with readable UUID String representations.

Chen Harel
  • 9,684
  • 5
  • 44
  • 58
  • 2
    @Max I am playing with this now. At first blush it appears to save space as the dashes are removed. A test 'UUID' 7309c8e6-00f0-4e3c-89cf-a1a79ce20de6 becomes cwnI5gDwTjyJz6GnnOIN5g== in DynamoDB. This does compress things with regard to storage and throughput. If you are dealing with a high transaction environment and it does not matter if humans can read the UUID the savings could be beneficial. Chen is right on the 'debugging' aspect as you would need to use your code to ensure things wire up correctly (can't eye-ball it). Financial trading systems use similar tricks for latency. – Zack Jannsen Feb 20 '16 at 12:27
  • I like the base64 encoded string version. for debugging - It's shorter, and you can look up visually just 2-3 first chars and it should be pretty unique already – atablash Nov 03 '18 at 06:52
  • 1
    @ZackJannsen, It saves a lot more space than you think. You're looking at the base64 encoded version. On disk, (and in memory), it is 16 bytes. – BPS Dec 03 '20 at 20:47