I built a Connect 4 multiplayer game using Java Spring for the backend and React for the frontend. This is my first web development project and I’m running into deployment issues on Google Cloud App Engine.
Right now when I deploy my backend to App Engine, all users who visit the site see the same game instance. This means if two players open the game from different browsers or devices, they’re both looking at the exact same game state instead of having separate game sessions.
I need help figuring out the right way to structure and deploy both parts of my application so that each pair of users gets their own unique game instance. What’s the recommended approach for handling multiple game sessions with this tech stack on Google Cloud?
Any guidance would be appreciated since I’m pretty new to web development and cloud deployment.
interesting challenge! you’ll need a room/lobby system where each game gets its own ID. how do you want players to find each other - room codes or auto-matching? also, are your websocket connections set up right for real-time play? that’s usually the trickiest part with spring webSockets.
Your problem is that all users share one game state. You need session management to create separate game instances for each match. Use Spring Session with Redis or Cloud Firestore to store individual game states - just key them by session IDs or room codes. When players join, generate a unique room ID and link their WebSocket connections to that specific room. On the frontend, add room creation and joining features so users can either start a new game or join existing ones with a room code. This keeps each game pair completely separate. Also, consider switching from App Engine to Cloud Run - you’ll get better scalability and WebSocket support. Pair it with Cloud SQL or Firestore for storing game states.
you’re storing game state globally - that’s the problem. each session needs its own state. use webSockets with stomp since spring handles it well. when players connect, create unique game rooms and store each room’s state separately in memory or a database. on google cloud, check out firestore for real-time player updates instead of just app engine.