Partition key consisting of multiple values in DynamoDB standard attribute name and value formatting?

Viewed 362

I am creating a DDB table which has multiple values make up its partition key and sort key. The primary key is a composite of the partition and sort key.

The partition key would be something like region+date+location and the sort key would be zone+update timestamp millis.

What's the norm for naming these attributes? Is it just naming out the values like region+date+location ? Or some other kind of delimitation? I've also read that it might be better to be generic and just name it something like partitionKey and rangeKey or <typeofthing>id etc. but I've gotten a little pushback on this from my team that the names aren't helpful in that case.

I can't seem to find best practices for this specific question anywhere? Is there a preferred approach for this written down somewhere that I could point to?

1 Answers

There is no "standard" way of naming attributes. But there are two things to consider against mandating a naming standard like region+date+location:

  1. A very long attribute name is wasteful - you need to send it over the network when writing and reading items, and it is included in the item length for which you pay per operation and for storage. I'm not saying it means you should name your attributes "a" and "b", but try not to go overboard on the other direction either.

  2. An attribute name region+date+location implies that this attribute contains only this combination, and will forever contain only this combination. But often in DynamoDB the same attribute name is reused for multiple different types - this reuse is the hallmark of "single table design". That being said, these counterexamples aren't too relevant to your use case, because the attributes overloaded in this way are usually not the key columns as in is your use case.

In your case I think that whatever you decide will be fine. There is no compelling reason to stay away from one of the options you mentioned.

Related