Gaming

Pair players by skill in real time

Watch a matchmaking engine queue simulated players, pair them by skill and region, and update their ratings after each game. Built with Node.js, Next.js, and the PubNub Chat SDK.

Illustration of miniature soldiers in a battle on a gaming keyboard
About this demo

A live view into a matchmaking engine

This demo has two parts. A Node.js engine runs the matchmaking and simulates the players. A Next.js dashboard shows what the engine does, step by step. Both use the PubNub Chat SDK. Every player profile, with its name, Elo rating, region, and play style, is stored in App Context.

Simulated players send a request to a regional matchmaking channel. Every five seconds, the engine takes everyone in the queue, scores each possible pair by Elo gap and region, and picks the pairing with the lowest total cost. Each pair gets a pre-lobby channel. When both players confirm, the engine opens a game lobby, plays a simulated match, and saves the new ratings. The engine reports each step on a channel the dashboard listens to. The source code is open on GitHub.

Features

What you can do

  • Watch the queue fill up

    Players show up in the queue as they ask for a match. Once the engine pairs them and they confirm, they move to Recently Matched. The dashboard gets each step as a message on a Chat SDK channel.

  • See players grouped by skill

    The dashboard loads player profiles from App Context and sorts them into Elo buckets, from beginners to the top tier. Each bucket shows its highest-rated player first.

  • Confirm the match in a lobby

    Each matched pair gets its own pre-lobby channel. Both players have 30 seconds to confirm. If they do, the engine opens a game lobby. If one of them doesn't, the engine flags that player's profile.

  • Follow ratings and stats live

    When a simulated game ends, the engine saves both players' new Elo ratings to App Context. A stats profile counts the matches formed and the last wait time, and the dashboard updates the moment it changes.

  • Change the rules while it runs

    Matchmaking constraints, such as the maximum Elo gap, arrive as messages on a PubNub channel that an Illuminate decision can publish to. The engine and the dashboard apply new values without a restart.

  • Find your own best matches

    Open the players page, set your name, Elo, region, play style, and toxicity level, and start matchmaking. Your profile is saved in App Context, and the engine returns the most compatible players with a score for each.

Build it yourself

Make your own matchmaking system

Clone the repo, add your PubNub keys, and run the engine and the dashboard locally.

GitHub

PubNubDevelopers/SBMM-Engine

The engine and the dashboard. Enable Message Persistence and App Context on your keyset and add your keys to the .env files. Run npm run build and npm run start in the root for the engine, then npm run dev in client/ for the dashboard.

git clone https://github.com/PubNubDevelopers/SBMM-Engine.git
View on GitHub
Keep building

Build interactive real-time experiences with PubNub

Bring chat, live updates, and real-time interactions into your application without building the infrastructure from scratch.