WebSockets vs WebRTC for browser multiplayer games
Updated 2026-11-23
Short answer: WebSockets are a reliable, ordered connection from a browser to a server. They're simple, work on every network, and are what most browser multiplayer games use. WebRTC data channels connect browsers to each other and can be unordered and unreliable, like UDP, which cuts latency for fast action games, but they need signalling, STUN and often a TURN relay, and much more code. For racers, score games, board games, casual arenas and lockstep strategy, a WebSocket to a nearby server is enough. Joinable uses exactly that: one WebSocket per player to a room on Cloudflare's network.
WebSockets in one minute
A WebSocket starts as an HTTP request and becomes a two-way, long-lived connection between the browser and a server.
- Reliable and ordered. Every message arrives, in the order it was sent (it runs over TCP).
- Works everywhere. It's ordinary HTTPS traffic to the network, so firewalls, corporate proxies and mobile carriers let it through.
- Simple.
new WebSocket(url),send,onmessage. Every server platform supports it. - The catch: because TCP is reliable, a lost packet holds up the ones behind it until it's resent (head-of-line blocking). On a bad mobile link, that shows up as an occasional stall. And everything goes through the server, so it adds a hop.
WebRTC data channels in one minute
WebRTC is the browser's peer-to-peer stack, built for video calls. Its data channels carry game messages directly between players.
- Can be unreliable and unordered, so a lost position update is simply skipped, and nothing waits for it. That's what fast action games want.
- Can be direct, skipping the server hop when both players can reach each other.
- The catch: setting it up. Two browsers must exchange offers and candidates through a signalling server you run. STUN helps them find their public addresses. Players on strict networks can't connect directly at all and need a TURN server that relays all their traffic. Then you still need rooms, host election, reconnects and a lobby, peer by peer.
Side by side
| WebSocket to a server | WebRTC data channel | |
|---|---|---|
| Delivery | Reliable, ordered | Reliable or not, ordered or not: your choice |
| Path | Player → server → player | Direct when possible, else via TURN |
| Servers you need | One | Signalling, STUN, TURN |
| Works on strict networks | Yes | Only through TURN |
| Code in the browser | Small | Large: connection setup, candidates, renegotiation |
| Late joiners, saved state | The server has them | Someone has to keep them |
| Best for | Most browser games | Fast 1 v 1 action, voice and video |
Does the hop matter?
Less than people expect: the distance between the players dominates. Friends on one continent typically see 20–80 ms to a room near the first player; across oceans, 150–250 ms. Direct WebRTC helps most when two players are close to each other but far from any server.
And netcode hides most of it. A racer predicts rivals to the present, a score game sends only scores, a lockstep RTS runs orders a few hundred milliseconds later on purpose. Where the transport really decides the feel is precise 1 v 1 action: fighting games with rollback, and twitchy shooters.
What Joinable uses, and why
Joinable's SDK opens one WebSocket per player to the room: messages are JSON, and if the connection drops it reconnects with backoff (from half a second, doubling to at most 10 seconds, with jitter) and resends what was queued. The room is a Cloudflare Durable Object, created near the first player and holding every player's WebSocket with Cloudflare's hibernation API, so an idle room costs nothing between messages.
Why a WebSocket and not WebRTC:
- It always connects. No player is left out because their network blocks peer-to-peer.
- The room needs to be in the middle anyway. It picks the seed and the start time so no player can bias them, runs the shared countdown, collects one result, keeps the current world for late joiners and the order log for lockstep catch-up, and drives quick match.
- The genres we support don't need UDP. Racing at 20 updates a second with prediction, score games, shared worlds and lockstep all feel right over a reliable connection.
- Your code never touches it. The kit tells coding agents never to write WebSocket code: the SDK does it.
<script async src="https://relay.getjoinable.com/sdk.js" data-connect="invite"></script>
Where WebRTC could come in
Peer-to-peer data channels, with the relay as matchmaker and fallback, are on our roadmap for fast action and for very large games. We estimate that about 10–20% of players would still need a TURN relay, which costs about as much as our relay does. Not built yet: we'll say so here when it is.
Which should you use?
- Building it yourself, most genres: a WebSocket server. Socket.IO,
wsor a framework like Colyseus. - A fighting game or competitive 1 v 1 action: WebRTC data channels with rollback, plus signalling and TURN.
- You don't want to run anything: a hosted relay. With Joinable, paste the prompt into your coding agent, or start with how to make a web game multiplayer.
FAQ
Is WebRTC faster than WebSockets for games?
It can be, for fast action: unreliable channels skip lost packets instead of waiting, and a direct link skips the server hop. For most browser games the difference is small next to the distance between players, and netcode hides it.
Do WebSockets work for real-time multiplayer games?
Yes. Most browser multiplayer games use them: racers, board games, casual arenas, strategy. They're reliable, work on every network, and a nearby server keeps latency low.
Does WebRTC need a server?
Yes. A signalling server to set up the connection, STUN to find public addresses, and a TURN server that relays all traffic for players whose networks block direct links.
What does Joinable use?
One WebSocket per player to a room on Cloudflare's network (a Durable Object created near the first player). Your game's code never opens it; the SDK does, and reconnects on its own.