Player statistics microservice

September 26, 2019 ยท View on GitHub

This microservice is specialized on storing statistics data per for each existing player in Open Matchmaking platform.

Why

  • Requires a storage for the data per each player, separately from Authorization / Authentication microservice
  • Necessary to track a player progress after each game and perform certain actions on this data

Benefits of using

  • The data can be easily denormalized depends on your use cases
  • The stored data can be used for analytics and tracking for a state of the game (balance, the most picked characters and so on)

Dependencies

Entity relationship diagram

Statistic table

Field nameField typeConstraintsDescription
player_idUUIDPKA database unique object identifier (same as in Authorization / Authentication microservice)
gamesIntegerNOT NULLTotal number of games played
winsIntegerNOT NULLTotal number of games when the player won
losesIntegerNOT NULLTotal number of games when the player was defeated
ratingIntegerNOT NULLAn actual rating of the player

Also the table can have an extra fields in database (for example, extra columns/documents in NoSQL or a nested JSON/HStore field in RDBMS) that can be used for providing for a detail information about the player.

API Endpoints

MethodEndpointUsageReturns
GET/player-statistics/api/health-checkHealth check endpoint for API Gateways"OK"

RabbitMQ exchanges and queues

Exchanges

Exchange nameExchange typeOptions
open-matchmaking.player-stats.statistic.init.directdirectdurable=True, passive=False, auto_delete=False
open-matchmaking.player-stats.statistic.retrieve.directdirectdurable=True, passive=False, auto_delete=False
open-matchmaking.player-stats.statistic.update.directdirectdurable=True, passive=False, auto_delete=False

Queues

Queue nameQueue optionsExchange nameUsageReturns
player-stats.statistic.initdurable=True, passive=False, exclusive=False, auto_delete=Falseopen-matchmaking.player-stats.statistic.init.directInitializes statistics from an empty state for the new playerStatistics or a validation error
player-stats.statistic.retrievedurable=True, passive=False, exclusive=False, auto_delete=Falseopen-matchmaking.player-stats.statistic.retrieve.directReturns the player statisticsStatistics or a validation error
player-stats.statistic.updatedurable=True, passive=False, exclusive=False, auto_delete=Falseopen-matchmaking.player-stats.statistic.update.directUpdates the player statisticsStatistics or a validation error

Request and response examples

Initializing player statistics

For initializing and resetting the player statistics a developer should send a message to the player-stats.statistic.init queue with content inside in JSON format and content_type=application/json in headers. The message content contains the following fields:

Field nameParentDescriptionType
player_idStores a unique identifier of the player.UUID as string

An example of the request between microservices directly

{
  "player_id": "507f1f77aabbccd000000001"
}

An example of the response:

{
  "content": {
    "id": "507f1f77aabbccd000000000", 
    "player_id": "507f1f77aabbccd000000001", 
    "total_games": 0, 
    "wins": 0, 
    "loses": 0, 
    "rating": 0
  },
  "event-name": "init-player"
}

Retrieving player statistics

For getting the player statistics a developer should send a message to the player-stats.statistic.retrieve queue with content inside in JSON format and content_type=application/json in headers. The message content contains the following fields:

Field nameParentDescriptionType
player_idStores a unique identifier of the player.UUID as string

An example of the request between microservices directly:

{
  "player_id": "507f1f77aabbccd000000001"
}

An example of the response:

{
  "content": {
    "id": "507f1f77aabbccd000000000", 
    "player_id": "507f1f77aabbccd000000001", 
    "total_games": 10, 
    "wins": 6, 
    "loses": 4, 
    "rating": 2676
  },
  "event-name": "init-player"
}

Updating player statistics

For updating the player statistics a developer should send a message to the player-stats.statistic.update queue with content inside in JSON format and content_type=application/json in headers. The message content contains the following fields:

Field nameParentDescriptionType
player_idStores a unique identifier of the player.UUID as string
total_gamesTotal amount of games, already finished by the player.Integer
winsTotal number of wins.Integer
losesTotal number of defeats.Integer
ratingCurrent rating in competitive mode.Integer

An example of the request between microservices directly:

{
  "player_id": "507f1f77aabbccd000000001",
  "total_games": 11,
  "wins": 6,
  "loses": 5,
  "rating": 2648
}

An example of the response:

{
  "content": {
    "id": "507f1f77aabbccd000000000", 
    "player_id": "507f1f77aabbccd000000001", 
    "total_games": 11, 
    "wins": 6, 
    "loses": 5, 
    "rating": 2648
  },
  "event-name": "init-player"
}