How to architect a fast data exchange for a game?

Hi,

I’m building a JS game with react, and I want to keep the game state on the server to prevent cheating.

My backend is an express server that handles game logic. When the user performs an action its result is saved to moralis DB from the frontend part, and then frontend sends a message to the backend via socket.io to download the updated state from DB and perform the action. After that the backend updates the DB and sends a message to the frontend to download the latest state of the game with the action results.

I noticed that this takes quite a bit of time, like 3-4 seconds, whereas if I just keep the state in the local storage it’s happening near instant. So my question is what is your suggestion on the best way to integrate a simple HTML game with moralis DB for the fastest speed and protection from cheating?

Thank you

You could try some different flows e.g. when your frontend updates your Moralis DB, have your Moralis server send that updated state to your backend directly.

Or subscribe to your Moralis DB from your backend.

It would probably be better to have client <> backend <> DB.

1 Like