DynamoDB Table Partition Key Best Practices

Choosing the Right Partition Key

Prev Question Next Question

Question

A company is planning to develop an application that is going to make use of a DynamoDB table.

The structure of the table is given below. Attribute Name Type Description Product ID Number Unique ID of product Review ID Number Unique ID of an optional customer review Product Name String Name of the product Product Description String Description of the product Which of the following should be chosen as the partition key to ensure the MOST effective distribution of keys?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

Answer - A.

The most effective one will be the Product ID since you have a unique ID for each product.

Option A is correct.

Option B is incorrect because reviews are optional (as stated in the question)

So we can't guarantee where reviews will be present.

Options C and D are incorrect since it would not be best to keep these as the partition keys.

For more information on DynamoDB and partition keys, please refer to the below URLs-

https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/best-practices.html https://aws.amazon.com/blogs/database/choosing-the-right-dynamodb-partition-key/

In DynamoDB, a partition key is used to distribute data across partitions and is used to determine the physical storage of data in the backend. It is important to choose the right partition key to ensure the most effective distribution of data and avoid hot partitions or uneven load distribution.

Looking at the given structure of the DynamoDB table, there are four attributes available to choose as the partition key.

Product ID and Review ID are both number types, but Product ID is unique for each product while Review ID is unique for each review. Therefore, using Product ID as the partition key would result in a more even distribution of keys as each product has its unique ID, whereas each review is tied to a specific product and might not be as evenly distributed.

Product Name and Product Description are both string types and are less likely to provide an even distribution of keys. Moreover, it is not recommended to use string types as partition keys as it can result in hot partitions and uneven load distribution.

Therefore, in this scenario, the most effective partition key to ensure even distribution of keys would be Product ID. So, option A. Product ID should be chosen as the partition key for this DynamoDB table.