- Newest
- Most votes
- Most comments
For your turn-based strategy game, I recommend using a single-table design with generic primary key attributes that can be overloaded with different types of values. This approach is considered a best practice in DynamoDB for gaming applications.
Consider using:
- Partition Key (PK): A composite identifier that can represent different entity types
- Sort Key (SK): A value that helps organize and query related items
For your game records, you could structure it like this:
For game records:
- PK: "GAME#[GameID]"
- SK: "META"
- Attributes: Player_One, Player_Two, Version, Timestamp, Map, Gamemode, Status, GameRecord
For player-game associations:
- PK: "PLAYER#[PlayerID]"
- SK: "GAME#[GameID]#VERSION#[Version]#TIMESTAMP#[Timestamp]"
- Attributes: Role (Player_One/Player_Two/etc.), GameID (for reference)
This design allows you to:
- Get all games for a specific player by querying with PK="PLAYER#[PlayerID]"
- Get all games for a player filtered by version using a begins_with condition on the SK
- Support multi-player games (3+ players) without schema changes by adding more player-game association items
- Retrieve specific game details using PK="GAME#[GameID]"
You can add a Global Secondary Index (GSI) with:
- GSI PK: "VERSION#[Version]"
- GSI SK: "TIMESTAMP#[Timestamp]"
This would allow querying games by version and sorting by timestamp.
The advantage of this approach is that it eliminates the need for multiple tables or excessive GSIs, while still supporting all your access patterns. It also scales well if you need to add more game modes or player counts in the future.
Sources
Gaming profile schema design in DynamoDB - Amazon DynamoDB
Data modeling example - Best Practices for Migrating from RDBMS to Amazon DynamoDB
Should I use a separate DynamoDB table for each App Feature? Or keep it all in one table? | AWS re:Post
Relevant content
asked 3 years ago
- AWS OFFICIALUpdated 2 years ago
