Case study 02 The API and mobile apps are live
Real-time sync for a multiplayer party game
Keeping every player's screen on the right step of the game, driven by a WebSocket event stream, through refreshes, reconnects and players leaving mid-round.
Key points
- Screen navigation driven by one WebSocket event stream, surviving refreshes and reconnects.
- One game room shared by older mobile clients and a new web client through versioned channels.
- Scores kept intact when players leave mid-round.
The problem
A game room moves through steps: waiting for players, choosing a pack, a round, its answers, the scores. Every player's device has to show the same step at the same time. The server broadcasts events such as game started, round started, answer submitted, player left, and each client decides which screen to show from them.
Players' web clients kept ending up on the wrong screen: after a refresh, after a reconnect, or when someone left in the middle of a round.
What I did
Web client
- Built most of the game screens (home, join room, pack selection, scoreboard with multiple winners and losers) and the shared UI components.
- Fixed the "lost screen" bugs at the root: unified how room data is loaded, and made navigation a function of the event stream through a dedicated navigation store and wrapper, instead of each screen deciding for itself.
- Refactored the room state into store slices persisted across reloads, so a page refresh lands the player back in the right room and step.
API
- Built the second version of the API resources used by the web client (players, answers, current game), with a generic response helper.
- Refactored the game services (building the next round, calculating scores, dispatching events) to return explicit results.
- Kept scores intact when players leave mid-game by soft-deleting them and tracking only active players.
- Added admin statistics (average players per room, global filters) on top of pre-aggregated rollups, and fixed N+1 queries on packs.
Decisions and trade-offs
- Versioned channels. Old mobile clients and the new web client had to share a room, so broadcasts are streamed per API version instead of breaking existing apps.
- Events drive navigation. Deriving the screen from the last event makes behaviour predictable, but every new event needs a clear "where does this send each player" rule.
- Soft-deleted players. Leaving mid-game must not erase a player's score from the round already played.
What I'd point out
Real-time bugs rarely live in one place. Most of the fix was making a single source of truth for "which step are we on" and removing the places that guessed.