One of the challenges in rewriting my online baseball game is dealing with enormous amounts of data that needs to be stored as aggregates, and coming up with a domain model and data mapping pattern that works. In this blog post, I’ll outline how I addressed some of those issues.
The Data Model
Baseball is very much a statistics-oriented game. Consider fielding statistics: putouts (PO), assists (A), errors (E) and others. These stats need to be stored:
- Per game, for each player who played in the game, for each position he played (key fields: game, player, position)
- Per season, for each player, for each team he played for, for each position he played (key fields: season, player, team, position)
- Career, for each player, for each position he played (key fields: player, position)
On the database side, that results in three tables: GameFieldingStats
, SeasonFieldingStats
, and CareerFieldingStats
. Each has the same set of fields to store the statistics (PO
, A
, and E
); the differences are in the key fields for each, as outlined in the diagram below. (Note: For the remainder of this post, I’ll include only the first two of those tables to keep things short.)