A developer is designing the data tier for a mobile multiplayer game. Player match logs are stored in an Amazon DynamoDB table with `PlayerID` as the partition key and `MatchID` as the sort key. The table contains millions of records. The game client needs to perform two operations:
1. Retrieve all matches played by a specific player within the last days.
2. Retrieve all matches across the entire game where a player scored more than points.
Which TWO strategies should the developer implement to support these access patterns with the lowest read latency and minimum consumption of Read Capacity Units (RCUs)?
- Create a Global Secondary Index (GSI) with `PlayerID` as the partition key and `MatchTimestamp` as the sort key, and query the GSI to retrieve the player's recent matches.Cevap
- Implement a sparse Global Secondary Index (GSI) by writing a `HighScoreThreshold` attribute only when a score exceeds , and query the GSI to retrieve the high-scoring matches.Cevap
- CPerform a `Scan` operation on the base table with a `FilterExpression` on `MatchTimestamp` to retrieve the player's recent matches.
- DPerform a `Scan` operation on the base table with a `FilterExpression` on `Score` to identify matches exceeding points.
- EInitialize the DynamoDB client in the application code by hardcoding IAM User credentials to authorize the queries.
Cevap
The developer should create a Global Secondary Index (GSI) with PlayerID as the partition key and MatchTimestamp as the sort key to retrieve a player's recent matches. Additionally, they should implement a sparse GSI by writing a HighScoreThreshold attribute only when a score exceeds 10,000, and query this GSI for high-scoring matches.
Querying a Global Secondary Index (GSI) configured with PlayerID as the partition key and MatchTimestamp as the sort key allows the application to perform a highly efficient query to retrieve recent matches for a specific player. Additionally, creating a sparse GSI by conditionally writing a HighScoreThreshold attribute only when a score exceeds 10,000 enables the application to query only the high-scoring matches, bypassing the need to perform a costly scan of the entire table.
Adım Adım Çözüm
Anahtar Kavram
Optimizing read operations in DynamoDB using Global Secondary Indexes (GSIs) and sparse indexes instead of performing full table Scan operations.
Tahmini Süre:2m 0s