I'm one developer making an open-wheel racing game, Apex GP. Multiplayer has been in the 0.11 builds for a few weeks and is in every current package — 0.11.12, build 24, on Google Play, itch.io and TestFlight — and it costs nothing: no unlock, no purchase, no subscription behind it. This post is about how it works, what broke while I built it, and the parts that still aren't done.
Nobody touches anybody
Each driver simulates only their own car. The other seven are ghosts: drawn where the server says they are, with no physics of their own, no collisions and no shared state. That was a cheat-resistance decision as much as a networking one. Nothing another client sends can move your car, so your lap time is always your own simulation, and there is no authority problem to solve at the end of a race.
Poses go out at 12 to 15 Hz. The room batches the newest pose per driver every 66 ms and stamps each batch with the server's receive time. Each client keeps a 260 ms playout reserve and runs peers on a monotonic clock between 0.95x and 1.05x real time, holding still when it runs dry and snapping if a peer jumps more than 8 m. In practice a ghost is around a third of a second behind the server. That is fine for racing a field and it is not fine for a photo finish, which is the trade I chose.
The room is a Durable Object
One Cloudflare Durable Object per room, addressed by its six-character code: /mp/ws?code=ABC234 joins, ?create=1 makes one and joins as host. Nine rooms or nine hundred, they cost the same when idle, because the object hibernates — the WebSocket runtime answers keep-alive pings without waking it — and rebuilds itself from one SQLite row and the sockets' attachments when a real message arrives. Lobby settings live in that row. Poses never touch storage at all; they exist for 66 ms and are gone.
All the rules live in one plain TypeScript file with the clock, timers, storage and sockets injected, so the entire rule set is unit-tested under Node and the same code runs in production. The limits that file enforces:
- Eight drivers per room.
- Codes are six characters from a 32-character alphabet with I, O, 0 and 1 removed, regenerated on collision.
- Messages are capped at 2,048 bytes; each socket gets a token bucket of 60 burst and 30 per second; poses closer together than 40 ms are dropped silently rather than queued.
- Per IP address: 60 joins and 12 room creations per ten minutes.
- A silent driver is removed after 75 seconds without a message or a keep-alive.
- An empty room is deleted ten minutes after the last driver leaves.
Everything a client sends is rebuilt from a whitelist, so a bad field is refused with a close code rather than half-applied. The close reason carries the same name as the error, so a client that loses the error frame to a fast disconnect can still explain what happened instead of showing "connection lost".
You can't start until everybody is in their seat
This came from a complaint, and it was the right one. On a phone the race scene takes a while to load, and the driver whose phone is slower used to lose the start while still looking at a loading screen. A countdown that begins when the host presses start is a countdown that begins without you.
So start no longer starts anything. It arms the room: the seed, the grid, the circuit and the weather are fixed and sent, each client loads the race scene, and each sends one fieldless seated when its car is on the grid and the clock is frozen. The lobby tiles of drivers who haven't arrived yet read LOADING. When the last seat lands, the server sends one go, and only then do the five red lights begin. A driver who never turns up is named in a timeout message and the grid is released after 30 seconds; a driver who leaves during arming is removed from the wait, and if the room drops below two it goes quietly back to the lobby. Seating survives the room hibernating or being recreated, so a quiet lobby doesn't forget who was already in their car.
One green light for eight phones
The second half of that complaint is that the start has to feel simultaneous, and a countdown that begins when the "go" message arrives is offset by each player's own latency.
So the countdown isn't a local timer. Every client reports at_lights, the server picks a green time on its own clock — five seconds after the last acknowledgement — and sends it back as an absolute deadline along with the current server time. Clients estimate their clock offset from ping/pong round trips and hold the same five lamps until that instant. A countdown that arrives after its deadline releases immediately, so a slow connection can never start a driver late, only make their lights appear briefly.
Measured on production, with two independent clients in the same room: they resolved the same green within 0.526 ms in the normal round, and within 0.611 ms when one of them held its seat for two seconds. That hold delayed the whole grid by 2,059 ms rather than letting it start without the missing driver, which is the point of the design. Two real Godot clients against the live server agreed to 6.86 ms.
Open lobbies, and a room that closes when you're alone
Rooms are private by default: a six-character code you send to whoever you're racing. The host can flip a room to OPEN, which lists it for anyone — at most 20 rooms at a time, filterable by class and circuit, with a 30-second heartbeat keeping the index fresh and rows older than 90 seconds dropped. Every listed row is re-checked against the room itself before its code is exposed, because a code that leaks is a lobby you didn't invite anyone to; I grep the listing bodies in the tests to prove private codes never appear.
If you are the last driver left in a room, it closes rather than leaving you waiting for players who aren't coming. The client gets a closed message with the reason alone and close code 4011, which is exactly what the screen then says.
Colours are the server's call, for the same reason names are de-duplicated. You pick a livery from the 11-entry palette; if someone already has it, the server scans forward for a free one and tells you it was reassigned, and leaving frees the entry. Nobody races in their teammate's paint by accident.
Builds have to match
Online play between different versions is a support ticket factory: a 0.11.9 client and a 0.11.12 host disagree about circuits, cars and the wire format. So a join is refused when the game build differs, and the refusal names the host's build: "Update the game to join: this lobby is on 0.11.12." Two unknown builds may pair; a known build and an unknown one may not.
Night, Formula 2004, and a bug that made the new circuits unplayable
Multiplayer grew with the rest of the game. Time of day arrived in 0.11.7: the host picks Day, Night or Venue default, everyone applies it before the race scene loads, and it is presentation only — grip, AI, timing and the physics checksum (d0010bb3339fd37d41338f17a2371bc6) are untouched. Formula 2004 arrived in 0.11.11 behind a class-parity gate, because the list of car classes had been duplicated in four places and the lobby was able to offer a car the race scene didn't know about.
Then the embarrassing one. When Sakhir and Bosporus Park shipped they were unplayable in multiplayer. The client knew both circuits; the server kept its own allowlist and hadn't been told. The fix was two lines and a deploy. The lesson wasn't the two lines, so the race harness now races every circuit in the multiplayer gate — mprace-sakhir and mprace-bosporus alongside the default — which fails if a circuit exists in the game and not on the server.
What it doesn't do
- There is no contact between cars and no shared physics, so no bumping and no towing from a rival's wake.
- You can't reconnect into a race that has started. Drop out and you rejoin as a new lobby, not a midfield car.
- A ghost is about a third of a second behind the server.
- The skew numbers above come from one host with two sockets and two local clients. They are not a field test with real friends on different networks, which is still the thing I most want to run before calling this finished.
It's free
Multiplayer is part of the free game, not the paid unlock. The paid version covers the career mode and its development, and nothing about racing other people is behind it: no purchase, no hosting fee, no "available in the full version".
Apex GP is on Google Play and itch.io, currently 0.11.12 (build 24), with the same build on TestFlight for iOS.