SaaS matchmaking system
- Install the python dependencies:
pipenv install
- Install a local version of the database:
docker compose up --build --remove-orphans -d
- Run database migration to have the latest schemas:
alembic upgrade head
- Run the app locally:
uvicorn app.main:app --reload
- Run the worker locally:
python matchmaking_worker.py
The easiest way to get started with the api is to head over to the docs generated by fastapi at localhost:8000/docs
.
- Create a queue using the endpoint
POST /queues
. It is possible to add a cost function, and a maximum cost to the queue. The cost function should output a number that represents the cost of matching players together. The higher the cost of a matching, the less likely it is the that the players will be matched together. If a max cost is provided, the queue will never match players with a matching cost higher than the max. - Add players to the queue using the
POST /players
. Each players can have a set of attributes (for example a rating) that can be used in the cost function. - Call the
GET /players/{player_id}
endpoint to get the status of a player. When a player gets a match, its status will have the valueMATCHED
. - Using the match id of a player, call the
GET /matches/{match_id}
endpoint to get the list of players in the matching.
As mentioned above, a cost function can be associated to a queue. The cost function supports aggregate functions for the attributes of the players in the potential matching. For example, 60 * diff(rating) / avg(wait_time)
would be a cost function that takes into account the difference in rating of the players in a matching and the inverse of the average wait time of the players. Note that wait_time
is an attribute that can be used even if it's not in the attributes of a player.