Search code examples
amazon-dynamodbdata-partitioning

What should be my partition key and sort key of dynamo db table?


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?


Solution

  • 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.