Good DynamoDB Hash Key Examples

A Good DynamoDB Hash Key

Question

Which of the following is an example of a good DynamoDB hash key?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

Answer: B.

DynamoDB best practice states that a hash key should have high cardinality to avoid hot partitions.

Option A is incorrect because there could be many books with the same title.

ISBN is a better choice.

Option B is CORRECT because ISBN is a high cardinality attribute as it uniquely identifies each book.

Option C is incorrect because an author can have many books published.

Therefore, this is a low cardinality attribute resulting in a hot partition.

Option D is incorrect because there are many books published in any single language.

This is a low cardinality attribute resulting in a hot partition.

Reference:

https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-partition-key-uniform-load.html

The correct answer is B. International Standard Book Number (ISBN).

DynamoDB is a NoSQL database service provided by AWS, which uses a primary key to uniquely identify each item in a table. The primary key can be either a single attribute, known as a simple primary key, or a combination of two attributes, known as a composite primary key.

In this scenario, the question is asking for a good DynamoDB hash key. The hash key is the first part of a composite primary key and is used to distribute data across multiple partitions in DynamoDB for scalability and high availability. Therefore, a good hash key should have a high degree of variability and even distribution of values to avoid "hot partitions."

Out of the options given, the ISBN is the best choice for a hash key because it provides a unique identifier for each book and has a high degree of variability. Book Title and Author may not be unique, and Book Language may not have enough variability.

Therefore, using ISBN as a DynamoDB hash key is a good choice as it can provide an even distribution of data across partitions, and can also efficiently query for specific books using the GetItem API operation.