Designing a DynamoDB Table for Game High Scores

High Scores for Game Tables

Prev Question Next Question

Question

You are building a "game high score" table in DynamoDB for many games, and the highest score for each game will be stored in the table.

The table includes some columns such as "Name of the game", "Name of the user", "UserID", etc.

The web application needs to get the highest score of certain games from the table frequently.

You also need a suitable partition key to distribute the workload evenly.

How would you design the structure of the DynamoDB table?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

Answer - B.

It is better to choose the partition key that has a wide range of values.

This is also given in the AWS documentation.

Besides, as you need to retrieve the Highest Score, you can configure it as the sort key.

For more information on the DynamoDB guidelines, please visit the below URL:

http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GuidelinesForTables.html
Choosing a Partition Key

The following table compares some common partition key schemas for provisioned

throughput efficiency:

Partition key value
User ID, where the application has many users.
Status code, where there are only a few possible status codes.

Item creation date, rounded to the nearest time period (e.g. day, hour,
minute)

Device ID, where each device accesses data at relatively similar intervals

Device ID, where even if there are a lot of devices being tracked, one is by far
more popular than all the others.

Uniformity
Good

Bad

Bad

Good
Bad

To design a DynamoDB table for storing game high scores, we need to consider the access patterns of the application, data distribution, and performance.

The access pattern for this table is to frequently get the highest score for certain games. Therefore, we need to design the table to optimize for querying the highest score of each game efficiently.

The partition key determines the physical partition where the data is stored in DynamoDB, and it is also used to distribute the workload evenly across the partitions. So, we need to choose a partition key that evenly distributes the data across partitions and can efficiently query the highest score of each game.

Option A: HighestScore as the partition key Using the HighestScore as the partition key is not a suitable option because it will result in uneven data distribution across the partitions. Scores tend to cluster around specific values, and using the highest score as the partition key will result in hot partitions.

Option B: UserID as the partition key and HighestScore as the sort key Using the UserID as the partition key and HighestScore as the sort key is also not a suitable option. While UserID is a unique identifier for each user, it does not provide an efficient way to query the highest score of each game. Additionally, this option may result in uneven data distribution if some users have a significantly higher number of high scores than others.

Option C: UserID as the partition key Using the UserID as the partition key is not a suitable option because it will result in uneven data distribution across the partitions. Scores tend to cluster around specific games, not users, and using the UserID as the partition key will result in hot partitions for users with many high scores.

Option D: Name of the game as the partition key and HighestScore as the sort key Using the Name of the game as the partition key and HighestScore as the sort key is the best option. It provides an efficient way to query the highest score of each game, and it evenly distributes the data across partitions because high scores for different games will be stored in different partitions. This design also allows for easy addition or removal of games without affecting the overall data distribution.

Therefore, the correct answer is option D: Name of the game as the partition key and HighestScore as the sort key.