The multiplayer framework
developers love
Open-source, battle-tested, and built for real-time games. Free forever.
npm create colyseus-app@latest ./my-server Supports your favorite engine & platform
- Cheat-proof by design
- Built-in matchmaking
- Real-time sync that just works
- Client-side prediction built in
- Scale from 10 to 10,000+ CCU
- Self-host or use Colyseus Cloud
- Use tools you already know
- Free forever (MIT License)
See it in action
From zero to multiplayer
Define rooms, sync state, connect clients. A complete multiplayer server in just a few lines of code.
import { Room } from "colyseus";
export class MyRoom extends Room { maxClients = 4;
messages = { move: (client, payload) => {/* your code */}, };
onCreate(options) {/* your code */} onAuth(client, options) {/* your code */} onJoin(client, options) {/* your code */} onLeave(client) {/* your code */} onDispose() {/* your code */}}import { defineServer, defineRoom } from "colyseus";import { MyRoom } from "./MyRoom";
export default defineServer({ rooms: { my_room: defineRoom(MyRoom), },});import { schema, t } from "@colyseus/schema";
export const Player = schema({ name: t.string(), position: t.number(),}, "Player");
export const MyState = schema({ players: t.map(Player), board: t.array("number"), currentTurn: t.string(),}, "MyState");import { Room } from "colyseus";import { MyState, Player } from "./MyState";
export class MyRoom extends Room { state = new MyState();
onJoin(client, options) { // every connected client sees the new player this.state.players.set(client.sessionId, new Player()); this.state.currentTurn = client.sessionId; }
onLeave(client) { this.state.players.delete(client.sessionId); }}import { Client } from "@colyseus/sdk";
// Initialize SDKconst client = new Client("http://localhost:2567");
// Connect to a roomconst room = await client.joinOrCreate("my_room");import { Client, Callbacks } from "@colyseus/sdk";
const client = new Client("http://localhost:2567");const room = await client.joinOrCreate("my_room", { /* client options */});
const callbacks = Callbacks.get(room);
// on player added/joincallbacks.onAdd("players", (player, sessionId) => { console.log("Player added!", player, sessionId); // on player "position" change callbacks.listen(player, "position", (position, previousPosition) => { console.log("player position changed!", { position, previousPosition }); });});
// on player removed/leftcallbacks.onRemove("players", (player, sessionId) => { console.log("Player removed!", player, sessionId);});
// on "board" changecallbacks.onChange("board", (value, index) => { console.log("board item changed to", value, "at", index);});
// on "currentTurn" changecallbacks.listen("currentTurn", (currentTurn, previousValue) => { console.log("currentTurn:", currentTurn); console.log("currentPlayer:", room.state.players.get(currentTurn));});Define your room
Rooms are the core building block. Each room runs your game logic, handles connections, and manages state. Define lifecycle hooks for when players join, leave, or send messages.
Expose for matchmaking
Register your room type with a single line. Colyseus handles the rest — creating new instances on demand, filling them up, and routing players to the right one.
Define your state
Describe your game state with schema(). Colyseus tracks every change and syncs it to all clients with binary delta compression.
Mutate state
Just modify your state objects like regular JavaScript. Colyseus detects changes and broadcasts only the deltas to connected clients.
Connect from the client
Connect to your server and join a room with a few lines of code. If no room is available, the server creates one automatically.
Listen to state changes
React to state changes with fine-grained callbacks. Know exactly when players join, leave, or any state updates.
Define your room
Rooms are the core building block. Define lifecycle hooks for when players join, leave, or send messages.
import { Room } from "colyseus";
export class MyRoom extends Room { maxClients = 4;
messages = { move: (client, payload) => {/* your code */}, };
onCreate(options) {/* your code */} onAuth(client, options) {/* your code */} onJoin(client, options) {/* your code */} onLeave(client) {/* your code */} onDispose() {/* your code */}}Expose for matchmaking
Register your room type with a single line. Colyseus handles the rest.
import { defineServer, defineRoom } from "colyseus";import { MyRoom } from "./MyRoom";
export default defineServer({ rooms: { my_room: defineRoom(MyRoom), },});Define your state
Describe your game state with schema(). Colyseus tracks and syncs changes automatically.
import { schema, t } from "@colyseus/schema";
export const Player = schema({ name: t.string(), position: t.number(),}, "Player");
export const MyState = schema({ players: t.map(Player), board: t.array("number"), currentTurn: t.string(),}, "MyState");Mutate state
Just modify your state objects. Colyseus detects changes and broadcasts deltas.
import { Room } from "colyseus";import { MyState, Player } from "./MyState";
export class MyRoom extends Room { state = new MyState();
onJoin(client, options) { // every connected client sees the new player this.state.players.set(client.sessionId, new Player()); this.state.currentTurn = client.sessionId; }
onLeave(client) { this.state.players.delete(client.sessionId); }}Connect from the client
Join a room with a few lines of code. If none is available, the server creates one.
import { Client } from "@colyseus/sdk";
// Initialize SDKconst client = new Client("http://localhost:2567");
// Connect to a roomconst room = await client.joinOrCreate("my_room");Listen to state changes
React to state changes with fine-grained callbacks.
import { Client, Callbacks } from "@colyseus/sdk";
const client = new Client("http://localhost:2567");const room = await client.joinOrCreate("my_room", { /* client options */});
const callbacks = Callbacks.get(room);
// on player added/joincallbacks.onAdd("players", (player, sessionId) => { console.log("Player added!", player, sessionId); // on player "position" change callbacks.listen(player, "position", (position, previousPosition) => { console.log("player position changed!", { position, previousPosition }); });});
// on player removed/leftcallbacks.onRemove("players", (player, sessionId) => { console.log("Player removed!", player, sessionId);});
// on "board" changecallbacks.onChange("board", (value, index) => { console.log("board item changed to", value, "at", index);});
// on "currentTurn" changecallbacks.listen("currentTurn", (currentTurn, previousValue) => { console.log("currentTurn:", currentTurn); console.log("currentPlayer:", room.state.players.get(currentTurn));});New in 0.18
Netcode for fast-paced games
The server stays authoritative and controls still feel instant. Colyseus runs the prediction, reconciliation and rewind loops. You write the step function once and share it between server and client.
import { Room } from "colyseus";// Shared with the client, which runs the same step.import { applyInput } from "./shared/applyInput";
export class GameRoom extends Room { state = new GameState();
// Buffered per client; hacked values are clamped on arrival. inputs = this.defineInput(MoveInput, { sanitize: { moveX: (v) => Math.max(-1, Math.min(1, v)) }, });
// Remembers past positions for lag-compensated hits. rewind = this.allowRewindState({ maxRewindMs: 500 });
onCreate() { this.rewind.attachAll(this.state.players, { fields: ["x", "y"] }); this.setFixedTimestep((ctx) => this.step(ctx), 30); }
step(ctx) { for (const [sid, p] of this.state.players) { const cmd = this.inputs.get(sid).next(); if (cmd) applyInput(p, cmd, ctx.dt); } }}import { Predict } from "@colyseus/sdk";// The same function the server runs.import { applyInput } from "./shared/applyInput";
const predict = Predict.get(room, { mode: "lerp", delay: 100 });
// Everyone else: interpolated 100ms in the past.predict.attachAll("players", { mode: "lerp", fields: ["x", "y"] });
// You: predicted now, reconciled when the server answers.const input = room.input({ type: MoveInput });const me = predict.reconciler(room.state.players.get(room.sessionId), { input, step: (ctx, s, cmd) => applyInput(s, cmd, ctx.dt),});-
Client-side prediction
Your player moves on the next frame. When the server's state arrives, the reconciler rewinds, replays the inputs it hasn't acknowledged and smooths out the difference.
-
Lag compensation
Hit tests see the world as each shooter saw it, so a shot fired at 250 ms of latency still lands.
-
Smooth remote players
Everyone else renders a short delay behind, interpolated between snapshots, so they move smoothly.
-
Fixed timestep, validated input
Your simulation steps at a constant rate. Inputs are buffered per client, and hacked values are clamped before your code reads them.
The playground is open source: twelve labs, each with a latency slider.
Client SDKs
Build on any platform
Connect to your Colyseus server from any engine, framework, or language. State synchronization works the same everywhere.
import { Client, Callbacks } from "@colyseus/sdk";
const client = new Client("https://your-server.com");const room = await client.joinOrCreate("game_room");const callbacks = Callbacks.get(room);
callbacks.onAdd("players", (player, key) => { addSpriteForPlayer(player); callbacks.onChange(player, () => moveSprite(key, player.x, player.y));});
callbacks.onRemove("players", (player, key) => removeSpriteForPlayer(key));
room.send("move", { x: 10, y: 20 });npm install @colyseus/sdk import { Client } from "@colyseus/sdk";import { useRoom, useRoomState } from "@colyseus/react";
const client = new Client("https://your-server.com");
function Game() { const { room, isConnecting } = useRoom( () => client.joinOrCreate("game_room"), ); const state = useRoomState(room);
if (isConnecting) return <p>Connecting...</p>;
return ( <ul> {state?.players.map((player, key) => ( <li key={key}>Player at {player.x}, {player.y}</li> ))} </ul> );}npm install @colyseus/react using Colyseus;using Colyseus.Schema;
var client = new Client("https://your-server.com");var room = await client.JoinOrCreate<GameState>("game_room");var callbacks = Callbacks.Get(room);
callbacks.OnAdd(state => state.players, (sessionId, player) => { AddSpriteForPlayer(player); callbacks.OnChange(player, () => MoveSprite(sessionId, player.x, player.y));});
callbacks.OnRemove(state => state.players, (sessionId, player) => RemoveSpriteForPlayer(sessionId));
await room.Send("move", new { x = 10, y = 20 });var client: ColyseusClient = Colyseus.create_client()client.set_endpoint("wss://your-server.com")var room: ColyseusRoom = client.join_or_create("game_room")
room.joined.connect(func(): var callbacks = Colyseus.callbacks(room)
callbacks.on_add("players", func(player, key): add_sprite_for_player(player) callbacks.on_change(player, func(): move_sprite(key, player.x, player.y) ) )
callbacks.on_remove("players", func(player, key): remove_sprite_for_player(key) )
room.send("move", {"x": 10, "y": 20}))client = new ColyseusClient("https://your-server.com");room = client.join_or_create("game_room");callbacks = ColyseusCallbacks(room);
callbacks.on_add("players", function(player, key) { add_sprite_for_player(player); callbacks.on_change(player, function() { move_sprite(key, player.x, player.y); });});
callbacks.on_remove("players", function(player, key) { remove_sprite_for_player(key);});
room.send("move", { x: 10, y: 20 });local ColyseusSDK = require "colyseus.sdk"
local client = ColyseusSDK.Client("https://your-server.com")client:join_or_create("game_room", function(room) local callbacks = ColyseusSDK.callbacks(room)
callbacks:on_add("players", function(player, key) add_sprite_for_player(player) callbacks:on_change(player, function() move_sprite(key, player.x, player.y) end) end)
callbacks:on_remove("players", function(player, key) remove_sprite_for_player(key) end)
room:send("move", { x = 10, y = 20 })end)import io.colyseus.Client;import io.colyseus.schema.Callbacks;
var client = new Client("https://your-server.com");client.joinOrCreate("game_room", [], MyRoomState, function(err, room) { var callbacks = Callbacks.get(room);
callbacks.onAdd("players", (player, key) -> { addSpriteForPlayer(player); callbacks.onChange(player, () -> moveSprite(key, player.x, player.y)); });
callbacks.onRemove("players", (player, key) -> removeSpriteForPlayer(key));
room.send("move", {x: 10, y: 20});});haxelib install colyseus #include "colyseus.h"
colyseus_client_t* client = colyseus_client_new("https://your-server.com");colyseus_room_t* room = colyseus_join_or_create(client, "game_room");colyseus_callbacks_t* callbacks = colyseus_callbacks_get(room);
void on_player_add(colyseus_state_t* player, const char* key) { add_sprite_for_player(player); colyseus_on_change(callbacks, player, on_player_change, (void*)key);}
void on_player_change(colyseus_state_t* player, void* ctx) { float x = colyseus_get_float(player, "x"); float y = colyseus_get_float(player, "y"); move_sprite((const char*)ctx, x, y);}
colyseus_on_add(callbacks, "players", on_player_add, NULL);colyseus_on_remove(callbacks, "players", on_player_remove, NULL);colyseus_room_send(room, "move", data, data_len);const client = new Colyseus.Client("https://your-server.com");const room = await client.joinOrCreate("game_room");const callbacks = Colyseus.Callbacks.get(room);
callbacks.onAdd("players", (player, key) => { const sprite = runtime.objects.Player.createInstance("Game", player.x, player.y); callbacks.onChange(player, () => { sprite.x = player.x; sprite.y = player.y; });});
callbacks.onRemove("players", (player, key) => { // destroy sprite instance});
room.send("move", { x: 10, y: 20 });Under the hood
A solid stack, so you don't rebuild it
Focus on your game instead of re-inventing the networking, the rooms and the serialization.
Node.js runtime
Asynchronous, event-driven JavaScript runtime, designed to build scalable network applications.
Networking transport
WebSockets by default. Swap in uWebSockets.js, Bun, or the experimental WebTransport.
Room-based system
Stateful rooms spawn on demand, one per match, each with its own state, logic and clients.
Message serialization
Binary delta encoding for state, about 2.4× faster in Schema 5.0, and the fastest MessagePack serializer for everything else.
HTTP routes
Define your own API routes with Express or better-call, next to your rooms.
Database & auth
Persist players, cloud saves and leaderboards with @colyseus/database, or bring the database and auth provider you already use.
Scale with confidence
From one process to a cluster
A simple yet powerful scaling strategy. Add processes and machines behind a load balancer, share a Redis, and matchmaking works across all of them.
- Distribute rooms across servers and/or processes
- Allow cluster-wide match-making
- Leverage all your available CPUs
- Connect clients directly to their requested rooms
- Stateful processes keep track of their own rooms
joinOrCreate() asks any process for a seat, through the load balancer. 2The processes agree through Redis where the room lives, and reserve the seat. 3The client connects straight to that process over WebSocket. Developer experience
Tools from first line to production
Built-in tools that accompany you from development to production.
Playground
Open client connections from the browser and inspect every message exchanged with the server.
Monitoring panel
List the rooms your server spawned, inspect their state and manage connected clients.
Room debug panel
Inspect state and messages in your game's page, and simulate high latency or dropped connections.
Admin panel Beta
A production console for users, database tables, live rooms, dashboards and an audit trail.
Unit testing
Utilities for testing your rooms with your favorite test framework.
Load testing
Simulate concurrent client connections and see how your server behaves under traffic.
Sponsors
Colyseus is free and open source, made possible by these amazing people.
Supporters get exclusive demos, full source & premium guides.
Become a sponsorStart your multiplayer game
Scaffold a server in seconds, connect your engine, and deploy when you're ready.
npm create colyseus-app@latest ./my-server Colyseus is independent and MIT-licensed. Colyseus Cloud subscriptions and sponsors keep it going. If you use it and don't use Cloud, consider sponsoring.