A developer is optimizing a multiplayer gaming application backend. The application tracks player performance in real time and stores match results in an Amazon DynamoDB table. The table has `MatchId` as the partition key and `PlayerId` as the sort key. Each item contains additional attributes such as `Score`, `Duration`, and `Region`. For a post-match leaderboard display, the application needs to retrieve only the players who scored more than points in a specific match. The target match contains approximately player records, but typically fewer than players achieve a score above . Which approach will retrieve this data with the lowest latency and minimum Read Capacity Unit (RCU) consumption?
- Create a Global Secondary Index (GSI) with `MatchId` as the partition key and `Score` as the sort key, and then perform a `Query` operation on the GSI using a `KeyConditionExpression` for both keys.Cevap
- BPerform a `Query` operation on the base table using the partition key `MatchId`, and apply a `FilterExpression` of `Score > 10000` to filter the results.
- CPerform a `Scan` operation on the base table with a `FilterExpression` checking if `MatchId` matches the target match and `Score` is greater than 10,000.
- DInitialize the DynamoDB client in the application code using static IAM Access Keys, and run a parallel `Scan` operation with segment filters to retrieve the data.
Cevap
Create a Global Secondary Index (GSI) with `MatchId` as the partition key and `Score` as the sort key, and then perform a `Query` operation on the GSI using a `KeyConditionExpression` for both keys.
The correct approach is to create a Global Secondary Index (GSI) with the match identifier as the partition key and the score as the sort key. By doing so, the query operation can utilize both attributes in its key condition expression. Since DynamoDB only bills RCUs for items returned by a key condition expression, this consumes minimal capacity (only for the matching records) and minimizes retrieval latency.
Adım Adım Çözüm
Anahtar Kavram
Optimizing DynamoDB retrieval using Global Secondary Indexes (GSI) and KeyConditionExpressions instead of FilterExpressions or Scans.
Tahmini Süre:2m 0s