About DynamoDB Primary key


hi guys!

I am researching Amazon DynamoDB.

About the Primary key, I know that there are 2 options to setup Primary key (Partition key only and Partition key + Sort key). The Partition key + Sort key must be unique.

In the picture below, I don't know what should we do if we have to add the 3rd record that show the same user_id play the same game_id but they have the "draw" Result.

If you know, please tell me! Enter image description here

  • Hi Steven, what does the game_id stand for?

    1. A game type, like "Kart Racing", "Whack-a-Mole"?
    2. Or different rounds of the same game?

    Because, in case of 1) you'd might need more keys if you want more than one result per user+game.

asked 8 months ago66 views
1 Answer
Accepted Answer

You should probably add more to the sort key like a gameplay_id for the particular play of the game. So your SK becomes "1234#de45a" which is a game_id#gameplay_id concatenated together where de45a is the particular run of the game. Then every game play is tracked, and you can easily query to find all plays by a user, all plays of a user for a particular game, and any particular game play.

You might have different query needs. The data model you pick is directly based on the update and query pattern. I'm just guessing at your query pattern.

answered 8 months ago
  • thank you!

  • Sure thing, feel free to accept the answer.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions