Question

Difficulty: MediumData Store Operations with Amazon DynamoDB

A developer is optimizing data access for a multiplayer mobile game. The player data is stored in an Amazon DynamoDB table with `GameID` as the partition key and `PlayerID` as the sort key. The table includes attributes for `HighScore` and `RegistrationDate`. The developer needs to implement two new requirements:

1. Retrieve the top 10 players for a specific game, sorted by `HighScore` from highest to lowest.
2. Retrieve the profiles of 50 specific players across various games using a single network request.

Which combination of actions should the developer take to meet these requirements efficiently? (Select TWO.)

  1. Create a Global Secondary Index (GSI) with `GameID` as the partition key and `HighScore` as the sort key, and query the GSI with `ScanIndexForward` set to `false`.Answer
  2. Use the `BatchGetItem` API operation to retrieve the 50 player profiles.Answer
  3. C
    Use the `Scan` API operation with a `FilterExpression` to search for players of a specific game and sort the results client-side.
  4. D
    Instantiate the DynamoDB client inside the retrieval function by hardcoding temporary IAM credentials to fetch the player profiles.
  5. E
    Increase the provisioned Read Capacity Units (RCUs) for the entire table to resolve partition throttling errors instead of using batch operations.

Answer

Create a Global Secondary Index (GSI) with the game identifier as the partition key and the high score as the sort key, query it with the sorting parameter set to false, and use the batch get operation to fetch multiple player profiles.
To retrieve sorted high scores, a Global Secondary Index (GSI) with the game identifier as the partition key and high score as the sort key must be created, and then queried with the scan index direction reversed. To retrieve multiple distinct items across partitions in a single network request, the batch get operation is the most efficient and standard API call.

Step-by-Step Solution

1
Analyze the sorting and retrieval requirement for the top 10 players.
Identify that a Global Secondary Index (GSI) with GameID as the partition key and HighScore as the sort key is needed because the base table's sort key is PlayerID, which does not allow sorting by HighScore.
DynamoDB queries can only sort results by the table's or index's sort key.
2
Determine the query configuration for descending sort order.
Query the GSI with ScanIndexForward set to false.
By default, ScanIndexForward is true (ascending). Setting it to false returns results in descending order.
3
Analyze the requirement to retrieve 50 profiles across different games in a single network request.
Select the BatchGetItem API operation.
BatchGetItem allows retrieving up to 100 items from one or more tables using their primary keys in a single network call.

Key Concept

DynamoDB Index design and batch operations
Rate this question