0

I'm making a realtime multiplayer game and I have an idea on how to structure the backend, but I don't even know if its possible, let alone how to build and deploy it. Basically I want to deploy my backend as a container to cloud run but instead of syncing data through a database common to all instances I want to store the game data locally in each instance and just connect players in the same game to the same instance. Essentially I would need a custom load balancer and scaling logic. I haven't been able to find any useful material on this topic so any help/input is greatly appreciated.

Ben Baldwin
  • 427
  • 1
  • 6
  • 13

1 Answers1

2

This is possible to do on Kubernetes, but I doubt that this can be easily done on Google Cloud Run. Your game-pod is essentially stateful workload and does not fit well on Google Cloud Run, but you can run this on Kubernetes as StatefulSet.

Essentially I would need a custom load balancer and scaling logic.

Yes. For this you need to use an UDP/TCP load balancer and you most likely need to deploy custom configuration to allow longer connections than default. This network load balancer will forward traffic to your custom load balancer - probably running as a Deployment.

Custom Load Balancer - Sharding Proxy

What you need as custom load balancer is a Sharding Proxy that can forward traffic to correct Game Session Pod and potentially also to scale up to more Game Session Pods. See the answer to Sharded load balancing for stateful services in Kubernetes for more info on this.

Game Session App

The app that handles the Game Session need to be deployed as a StatefulSet so that they get an unique network identity e.g. game-session-0, game-session-1 and game-session-2 - so that your custom load balancer can use logic to direct the traffic to correct Game Session Pod.

I want to store the game data locally in each instance and just connect players in the same game to the same instance.

This is possible, use a volume of type emptyDir.

Game Server Example on GKE

For an extensive example of this type of deployment, see Running dedicated game servers in GKE

Jonas
  • 121,568
  • 97
  • 310
  • 388