DBS-C01 · Question #63
An online gaming company is planning to launch a new game with Amazon DynamoDB as its data store. The database should be designated to support the following use cases: - Update scores in real time whe
The correct answer is D. Create a composite primary key with user_id as the partition key and game_id as the sort key. Explanation Option D is correct because using user_id as the partition key and game_id as the sort key directly supports both use cases: real-time score updates can target a specific player (via user_id), and retrieving a player's score for a specific game session is efficiently
Question
An online gaming company is planning to launch a new game with Amazon DynamoDB as its data store. The database should be designated to support the following use cases:
- Update scores in real time whenever a player is playing the game.
- Retrieve a player's score details for a specific game session.
A Database Specialist decides to implement a DynamoDB table. Each player has a unique user_id and each game has a unique game_id. Which choice of keys is recommended for the DynamoDB table?
Options
- ACreate a global secondary index with game_id as the partition key
- BCreate a global secondary index with user_id as the partition key
- CCreate a composite primary key with game_id as the partition key and user_id as the sort key
- DCreate a composite primary key with user_id as the partition key and game_id as the sort key
How the community answered
(40 responses)- A5% (2)
- B15% (6)
- C3% (1)
- D78% (31)
Explanation
Explanation
Option D is correct because using user_id as the partition key and game_id as the sort key directly supports both use cases: real-time score updates can target a specific player (via user_id), and retrieving a player's score for a specific game session is efficiently handled by querying the composite key (user_id + game_id together) without any additional index overhead.
Why the distractors are wrong:
- A & B are wrong because Global Secondary Indexes (GSIs) are supplementary access patterns - they add cost and complexity when a well-designed primary key already satisfies the query requirements natively.
- C is wrong because making game_id the partition key would cluster all players of the same game together, making it inefficient to quickly retrieve or update a specific player's score - the dominant use case here.
Memory Tip: Ask yourself "Who is the primary actor?" - in player-centric applications, the player (user_id) should be the partition key, because most queries start with "give me data for THIS player." The sort key (game_id) then narrows down which game session, perfectly matching both requirements.
Topics
Community Discussion
No community discussion yet for this question.