Choose and design how a browser game plays online or together. Decision guide for local co-op, turn-based, real-time server-authoritative, host-and-guests peer-to-peer and shared-state games; Bash spaces (rooms, shared values, routes from the playing-together guide) versus your own WebSocket server versus WebRTC; where to host a game server when the game ships to itch.io or other portals; messa...
Download skill (.zip) Files on GitHubMultiplayer architecture
Decide how players are connected and who decides what is true before writing any networking code. Changing either later means rewriting most of the game.
First: is this a Bash space with a kit?
Bash kits (game-kit-2d, game-kit-3d, app-kit) already include rooms, shared saved values, room messages and
server routes, with the viewer’s Bash name. Read the playing-together skill and use those. It handles
hosting, sign-in, reconnects and “alone first”. Only build your own server (below) when:
- the game must run outside Bash (itch.io, your own site), or
- it needs fast real-time play the kit’s rooms don’t fit: room state is sent at most 20 times a second and is “latest value wins”, which is fine for cursors, boards and party games, but not for server-checked action games with prediction.
Pick the model
| Game | Model | Skills |
|---|---|---|
| Same screen, same room (couch play) | Local co-op: no network | local-coop |
| Quiz, party, voting, drawing, board game in rounds | Shared state + server rules (Bash rooms and routes, or a small server) | playing-together, multiplayer-lobbies |
| Turn-based (cards, chess, tactics) | Server checks each move, sends the new state | multiplayer-security, multiplayer-reconnection |
| Real-time action, 2-16 players, strangers | Authoritative server: clients send inputs, the server simulates, sends snapshots | websocket-multiplayer, network-synchronization, multiplayer-prediction |
| Real-time with friends, no server budget | Host and guests (peer-to-peer): one browser runs the game | webrtc-multiplayer |
| Talk while playing | Voice over WebRTC beside any model | voice-chat-integration |
| High scores, daily challenge | No live connection: submit and fetch | leaderboard-system, game-replay-system |
Rules of thumb:
- Strangers or rankings → the server decides. Anything in a player’s browser can be edited.
- Turn-based is much easier than real-time. If the design allows turns, choose turns.
- Peer-to-peer is not free of servers. Players still need a signaling server to find each other, and about 1 in 5 connections needs a TURN relay (paid bandwidth) because of strict networks.
- Keep it small. 2-8 players per room covers most browser games.
The authoritative loop (real-time)
client: read input → apply locally (prediction) → send { seq, input } 60x/s
server: apply each input with the SAME step function → tick world at 60 Hz → send snapshot 20x/s { tick, ents, ack: last seq }
client: own player = server state + replay inputs after ack (reconcile); others = drawn 100 ms in the past (interpolation)
- One shared rules file (
shared/) imported by both the server and the browser. websocket-multiplayer’s example does this. - Tick 60 Hz, send 20 Hz, interpolation delay about 2 send intervals (100 ms). Turn-based: send only on change.
- Messages are small JSON objects with a type:
{ t: "input", seq, dx, dy }. Add a protocolversiontohelloand refuse old clients with a “please reload” message.
Where it runs
| Piece | Where |
|---|---|
| The game page | itch.io, GitHub Pages, Netlify, Cloudflare Pages (static files: see docs/services) |
| A WebSocket game server | A host that runs Node all the time: Fly.io, Render, Railway, a small VPS. itch.io and the static hosts can’t run it |
| Signaling for WebRTC | The same small server, or Bash room messages |
| Leaderboard | A server route, Supabase (docs/services/supabase.md), or Bash routes in a kit |
A server started in the Bash sandbox is reachable through its preview address, including WebSockets, which makes it good for building and testing with friends. Don’t treat it as permanent hosting.
From an itch.io page, the game connects with wss://your-server.example.com/ws (secure WebSockets are required on HTTPS
pages). Allow that page’s origin on the server (origins option in game-server.mjs).
Build order
- Make the game fun offline with a bot or local second player. Networking amplifies whatever is there.
- Put the rules in
shared/, pure functions withdtin seconds and noMath.random()(seeded RNG). - Lobby (multiplayer-lobbies) and a match with 2 browsers on a perfect network.
- Add prediction and interpolation, then test on a bad network (game-network-testing has
net-sim.jsprofiles). - Reconnection, cheating checks, spectators and leaderboards.
- Alone first: one person can always start and play (a bot, or a solo mode). A game that waits for a second person looks broken.
Pitfalls
Trusting the client (positions, scores, hits), different movement code on client and server, sending every frame at full size, no protocol version, game logic inside network callbacks, testing only on localhost, and starting with 3D, 32 players or an MMO.
Tested
Run every module test in this category: node assets/tests/all-modules.mjs (94 checks across lobbies, matchmaking,
security, sessions, sync, prediction, replays, leaderboards, spectators and local co-op). The server and voice tests live in
websocket-multiplayer, leaderboard-system and webrtc-multiplayer.