I have always wanted to build a chaotic, instant-play IO game. Recently, I finally shipped LavaRun.io, a multiplayer survival browser game where up to 50 players compete in real-time to outrun rising lava.
Here is a technical breakdown of how I tackled the physics, real-time networking, and rendering optimizations to make this run buttery-smooth at 60 FPS in any browser with zero downloads.
The Stack: Pure JS & WebSockets
To ensure the game loads instantly, I avoided heavy engines like Unity or Phaser. Instead, I opted for a highly optimized, custom lightweight stack:
- Frontend: Raw HTML5 Canvas API for lightweight, hardware-accelerated 2D rendering.
- Backend: Node.js running on a lightweight VPS.
-
Networking: Raw WebSockets via the
wslibrary for low-overhead, bi-directional communication.
Challenge 1: Compressing Network Payloads
At 50 players, sending standard JSON updates for position, state, and lava level 30 times a second quickly clogs the network. A single JSON packet might look small, but multiplied by 50 players and 30 ticks per second, it becomes a bandwidth nightmare.
To solve this, I designed a strict binary protocol using JavaScript's ArrayBuffer and DataView. Instead of sending stringified objects, I serialize player positions and states into raw 8-bit and 16-bit integers. This reduced our average network payload size by over 80%!
Challenge 2: Lag Compensation & Interpolation
WebSockets operate over TCP, meaning packet delivery order is guaranteed, but latency jitter can cause visual stuttering. To make movement feel smooth, I implemented client-side interpolation.
Instead of instantly snapping players to the latest coordinates received from the server, the client renders other players lagging slightly behind (around 100ms) and smoothly interpolates (LERP) between their last known positions. This masks any temporary network hiccups perfectly.
Challenge 3: Deterministic Rising Lava Physics
The core mechanic of LavaRun.io is the rising tide of lava. To ensure fairness, the server must be the absolute source of truth for collision detection. If a player touches the lava, they die.
I implemented a deterministic physics loop on the server that increments the lava's Y-coordinate at a constant rate. The server runs standard AABB (Axis-Aligned Bounding Box) collision tests for every active player against the rising lava and platform coordinates. If a collision is registered, the server broadcasts a death event.
Building a real-time multiplayer game from scratch is an incredibly rewarding challenge. It forces you to think deeply about serialization, network loops, and client-side rendering performance.
Check out the live game at https://lavarunio.com and let me know how the movement feels!

Top comments (0)