Reputation: 1148
I am about to create a dynamo db table which has below columns and each row will have unique data,
user id | profile Id | attribute1 |
---|---|---|
1001 | 9001 | x |
1002 | 9002 | x |
table will have 1M records which means unique 1M user ids, profile ids. neither user id nor profile id will be repeated. And I will be querying data base by both user id and profile id, Is it advised to use user id as a partition key and profile id as a sort key?
Upvotes: -1
Views: 109
Reputation: 1148
(answered by AWS solutions architect at Amazon on a separate channel) Choose user id as a partition key as it will be queried most of the time and create global secondary index on profile id, this will make sure when database will be perform optimally when queried against user id or profile id
Upvotes: 0
Reputation: 19883
It's not required. But if a user may have a possibility to have many profiles in the future, you could use profileId as the sort key to future proof your table.
However, my suggestion is to pick the partition key based on the value you have most interaction with, as you'd have an index to lookup base on the other.
Upvotes: 1