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?
For example, if you have a User table, you might have a UUID as a primary key that uniquely identifies each user, but you might also have user name and email fields (“attributes” in DynamoDB terminology), which also must be unique for that user.
DynamoDB supports the following data types: Scalar – Number, String, Binary, Boolean, and Null. Multi-valued – String Set, Number Set, and Binary Set.
DynamoDB does not support empty sets, however, empty string and binary values are allowed within a set.
There are two types of primary keys in DynamoDB: Partition key: This is a simple primary key. If the table has only a partition key, then no two items can have the same partition key value. Composite primary key: This is a combination of partition key and sort key.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With