Building Real-Time Multiplayer with Partykit

Adding online multiplayer to Free Flick Football was one of the most complex features to build — and one of the most rewarding. Two players, each on their own device, need to see the same ball flying across the same board in real-time. Here's how it works.

The multiplayer system is built on Partykit, a platform for real-time WebSocket applications. Partykit gives each match its own 'room' — a persistent WebSocket connection that both players share. When one player flicks the ball, that input is broadcast to the other player's client through the room.

The key design decision was around what data to sync. Rather than trying to synchronize the entire physics state every frame (which would be expensive and conflict-prone), the game sends the input that caused the physics to happen: the angle and power of each flick. The receiving client then simulates the same shot locally.

This works because Matter.js is deterministic — given the same initial state and the same force input, both clients produce identical physics results. The host runs the authoritative simulation, and the guest replays each shot locally to produce the same visual result.

Ball positions are also streamed from the host to the guest as a backup. The guest client uses these position updates to smooth out any tiny floating-point differences between the two simulations. This prevents the 'ball is in a different place' problem that plagues naive implementations.

Matchmaking uses a simple room-code system. Create a match and get a 4-character code (or a shareable link). The other player enters the code or clicks the link to join. Once both players are connected, the match starts. The Partykit room handles player readiness, turn management, and disconnection gracefully.

One challenge was handling the transition between game states. When a goal is scored, both clients need to agree on the score and the new game state before continuing. The host broadcasts state transitions (goal scored, kickoff, game over) as authoritative messages that the guest applies immediately.

The result is online play that feels responsive and fair. Typical latency is imperceptible for a turn-based game — you're watching the opponent's shot replay, not trying to react to it in real-time. It's one of my favorite ways to play the game.

← All posts