Application to show how the scalability of PubNub can be utilized for Skill-based-matchmaking (SBMM) and improve the matchmaking experience.
Peer-to-peer matchmaking processing can be enhanced using PubNub in a variety of ways
- PubNub enables instant communication between players and the server, ensuring that matchmaking decisions based on player status, ELO ratings, latency, and region happen in real-time without any delays.
- PubNub's globally distributed network allows the SBMM system to handle millions of concurrent users across different regions, ensuring low latency and seamless player connections worldwide.
- With PubNub AppContext (Real-time Database), you can trust that player data is processed and transmitted with 0 downtime, leading to uninteruppted gameplayer experiences.
- Customize your matchmaking logic using the PubNub Platform with tools like PubNub Illuminate which allow you to fine-tune and adapt matchmaking algorithms on the fly, using live data to dynamically adjust ELO ranges, latency filters, or regional preferences.
- PubNub's secure messaging ensures that player data remains private and protected, a critical feature of competitive gaming enviornments.
Real-time: <30ms global delivery, regardless of concurrency.
Scale: We handle 3 Trillion real-time API calls every month.
Stability: 99.999& SLA provided for all players
This demo showcases how to run a Skill Based Matchmaking Algorithm in a production environment.
This demo will give you an impression of the kind of real-time features you can add to your SBM matchmaking system with PubNub. The demo is written in our TypeScript Chat SDK to make hosting easier. We also support client side engines such as Unreal Engine, and Unity. This demo simulates "fake" clients to join matches, confirm the match that they have joined, and play a game updating their elo ratings accordingly. This demo is designed to run locally within a browser.
This is architecture explains how the client communicates with the server componenet utilizing our TypeScript Chat SDK. This architecture is set up in a way where the individual user has to confirm the match they have joined before a game is actually created.
- The client signs in using PubNub AppContext
- Create a PubNub Membership by joining the Matchmaking Channel
- Server requests latency from the client.
- Client retrives their latency using a third party service.
- SBM module calculates the cost-optimal solution for matchming players with the lowest latencies
- SBM module get skill level from AppContext to add to the original latency matrix to find the cost-optimal solution for matchming players together with similar skill
- Creates a pre-lobby channel and sends it to the two players that are matched together
- ^^
- Clients can now confirm or deny the match by send a message to the pre-lobby channel. Pre-lobby channel timout after 30s.
- Server creates a game lobby by creating a PubNub channel and sends it to the corresponding clients that agreed to the match
- The client does not confirm the match and is entered back into the matchmaking process starting from (2)
- (Same as 10)
- Visualize the matchmaking DB using PubNub App Context
/multiplayer-matchmaking │ ├── /src │ ├── /config # Configuration files (dynamic K-factor, PubNub config, etc.) │ ├── /core # Core matchmaking logic (main orchestrators, algorithms) │ ├── /utils # Utility functions (PubNub Functions, Error handling, etc.) ├── /client # Client-side application for user interactions │ ├── /public # Public assets for the client application │ ├── /src # Source code for the client application │ │ ├── /app # Layout for the client │ │ ├── /components # UI components for the client │ │ ├── /context # Context providers for state management │ ├── .env # Environment variables for the client │ ├── package.json # NPM dependencies and scripts for the client │ ├── /docker # Docker configuration for containerization ├── /tests │ ├── /test-runner.ts # Simulates a individual client ├── /logs # Logging for monitoring and debugging ├── package.json # NPM dependencies and scripts for the main server ├── README.md # Project documentation ├── .env # Environment variables for the main server
To run the project locally, you’ll need:
- Node.js (v14 or later)
- Docker (for containerization)
- PubNub API Keys (to handle real-time messaging and events)
-
You’ll first need to sign up for a PubNub account. Once you sign up, you can get your unique PubNub keys from the PubNub Developer Portal.
-
Sign in to your PubNub Dashboard.
-
Click Apps, then Create New App.
-
Give your app a name, and click Create.
-
Click your new app to open its settings, then click its keyset.
-
Enable the Stream Controller feature on your keyset (this should be enabled by default after you created the keyset)
-
Enable the Message Persistence feature on your keyset and choose a duration
-
Enable the App Context feature. Important: It is recommended to also uncheck the
Disallow Get All User Metadata
option for this demo. -
Enable the File Sharing feature.
-
Copy the Publish and Subscribe keys and paste them into your app as specified in the next step.
- Clone the repository:
git clone https://github.com/yourusername/multiplayer-matchmaking.git
cd multiplayer-matchmaking
- Install the dependencies for the server:
npm install
- Install the dependecies for the client:
cd client
npm install
- Set up your .env file with PubNub credentials and other configuration settings:
Main Directory (.env)
PUBLISH_KEY=your-publish-key
SUBSCRIBE_KEY=your-subscribe-key
SECRET_KEY=your-secret-key
./client Directory (.env)
PUBLISH_KEY=your-publish-key
SUBSCRIBE_KEY=your-subscribe-key
- Start the server
In the Main Directory
npm run build
npm run start
- Start the client
cd client
npm run dev
- (Optional) If you want to run the project in a Docker container:
docker-compose up --build
-
Sign in to your PubNub Dashboard.
-
On the side menu click the drop down BizOps Workspace
-
Under the drop down select User Management
-
Select the app and keyset you configured the SBMM repo with
-
This is the user management dashboard where you can visualize all the users in your game
- Click on an indivdual user to see their status, and state
-
Sign in to your PubNub Dashboard.
-
On the side menu click the drop down BizOps Workspace
-
Under the drop down select Channel Management
-
Select the app and keyset you configured the SBMM repo with
-
This is the channel management dashboard where you can visualize individual game lobbies and pre-game lobbies and the users that are part of them
- Click on an individual channel to see the status, and state
- Click on view memberships to see who is active in that game lobby. If no one is active that means the game has ended
This project is licensed under the MIT License - see the LICENSE file for details.