Create Your First Project
Start adding your projects to your portfolio. Click on "Manage Projects" to get started
FYP(Sem B) Week 10: The Multiplayer Nightmare (and How We Fixed It)
Remember the sync bug from Week 8? Yeah this week was all about that. And honestly it was the hardest week of the entire project.
The core problem is simple to explain but painful to solve: three players share one city. When the Broker makes a trade, the Municipality's screen needs to show the updated budget immediately. When the MRF processes waste, everyone's CO₂ stat needs to change. If different players see different numbers, the game breaks.
We restructured our state management so there is one central game state that all three clients read from instead of each browser keeping its own local version. When any player does anything, the change gets broadcast to everyone. Sounds straightforward but the edge cases are brutal. What happens if two people try to buy the same listing at the exact same time? We had to implement a locking system — first come first served. What if someone's internet drops and they reconnect? They need to pull the latest state, not resume from where they left off.
We spent two full evenings debugging race conditions where the game state would occasionally get corrupted if actions happened within milliseconds of each other. Not fun. Lots of console.log statements and frustrated sighs.
But by Friday everything was syncing properly across all three roles. We tested by having three of us on different laptops in the same room, making trades and watching each other's screens update in real time. That was a good moment.

