Improving my multiplayer game data handling logic

Hey,
I am developing my first multiplayer game, it is a “casino” game. I have horse racing as one of my games that i’ve coded in it. Right now i have two versions of the game:

#1) a server version that needs to be running, it handles the games.
#2) a main version of the game for (front end) users where you actually play

The way i currently handle the game’s data is this:
I have a database, i write EVERY single change that happens in the game, to my database (including horse’s positions). I am able to sync positions of the horses in real time with everyone who is in the game this way. Now this is really bad, because horses move fast, and i write around 15 writes per second, meaning i am doing another 15 reads on users end to update the horses positions… What would be the

Here is two possible solutions i have been thinking:

Solution A) Should i be using a multiplayer solution like fish networking or something? And sync the horse race on everyones screen that way?

Solution B) I could stop writing the horses positions to database in the server => then i would have to read the winning horse’s data on user’s front end app to know which horse is going to win => i would then just trigger the race to start on everyone’s clients at the same time, and it would render the race because we know which horse will win.

^^but i think solution B) is bad because i think saving the winning horse to the users app isnt ok… and some smart guy can read that data then and abuse this…

Any ideas? idk if i explained this well enough… Thanks in advance!

If the player cannot affect the horse movement in any way, there’s no point in storing its position in the database.

Instead, let the server decide how the match went/ended, and send the data to the client. Then the client can play the race animation.

Abuse it how? If the logic is on the server, he can know the outcome before the race animation finishes playing, but can’t do anything about it.

1 Like

To avoid cheating you essentially want an authoritative server. This is either a server that spins up on demand per game instance, using tech like Edgegap to orchestrate the game instances in a location closest to all players.

Or if you want a simpler version, host a single server in the cloud which can be used as your authority.

You can use a multiplayer framework like Mirror to handle the server authority and to update all clients in realtime on the race progress.

You will have two builds of your game, a client version, and a server version. The server version will run all the game logic and determine the winner, which also during the race broadcasts the race positions to all clients (running the client version). The server version will also write all race results to your database.

You don’t ever want your client writing anything to the race results database. Your server should always be writing/recording anything critical.

I’m building a multiplayer racing game and my tech stack is…

Unity > Mirror > Playfab > Azure Functions > Edgegap

2 Likes

Thanks! This helps alot.

1 Like