Introduction
Colyseus is an authoritative multiplayer game framework built on Node.js that handles real-time state synchronization between server and clients. It uses a room-based architecture where each game session runs as an isolated room on the server, with automatic delta-based state patching sent to connected clients over WebSockets.
What Colyseus Does
- Manages game rooms with authoritative server-side state
- Synchronizes state to clients using efficient binary delta patches
- Handles matchmaking, room creation, and player seat reservation
- Provides client SDKs for Unity, Defold, Haxe, Cocos, and JavaScript
- Scales horizontally with Redis for multi-process deployments
Architecture Overview
Colyseus runs as a Node.js process where each game room is an instance of a Room class. The room holds a Schema-based state object that tracks changes automatically. When state changes, Colyseus computes binary patches and sends only the deltas to connected clients. Client SDKs apply these patches to reconstruct the state locally. For scaling, multiple Colyseus processes share room metadata through Redis.
Self-Hosting & Configuration
- Scaffold a project with
npm create colyseus-app@latest - Define room classes extending
RoomwithonCreate,onJoin, andonMessagehandlers - Define state using
@type()decorated Schema classes for automatic synchronization - Deploy on any Node.js host; use PM2 or Docker for production
- Add Redis for horizontal scaling across multiple server processes
Key Features
- Automatic binary state synchronization with minimal bandwidth usage
- Schema-based state definition with type annotations for client code generation
- Room lifecycle hooks for custom matchmaking and game logic
- Built-in lobby and matchmaking system with filtering support
- Client SDKs for Unity (C#), JavaScript, Defold (Lua), Haxe, and Cocos Creator
Comparison with Similar Tools
- Nakama — Go-based with more built-in features (accounts, leaderboards); Colyseus is lighter and JS-native
- Socket.IO — generic WebSocket library; Colyseus adds game-specific state sync and room management
- Photon — proprietary real-time engine; Colyseus is open source and self-hosted
- boardgame.io — focused on turn-based games; Colyseus handles real-time games with continuous state updates
FAQ
Q: Can Colyseus handle hundreds of concurrent players? A: Yes. Each room handles its own players, and you can run multiple rooms across processes with Redis for coordination.
Q: What client engines are supported? A: Unity, Defold, Cocos Creator, Haxe, and JavaScript/TypeScript. Community SDKs exist for other platforms.
Q: Is Colyseus suitable for turn-based games? A: Yes, though its strengths are in real-time state synchronization. For purely turn-based games, boardgame.io may be simpler.
Q: How does state synchronization work? A: You define state with Schema classes. Colyseus tracks mutations automatically and sends binary delta patches to clients at configurable intervals.