Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

Hi, as a hobby I develop multiplayer web games (agar.io type games). After a conversation with a member of the DigitalOcean team where I shared how I load balance traffic to my web games, they encouraged me to share this bizarre problem and its solution on this forum. So here it is!
Typical load balancers spread out requests to servers evenly, attempting to strike a balance so that individual servers are not overwhelmed with traffic. Whilst this works great for almost every application, it does not work for the games I develop. I need to balance servers based on the number of players in each server - a custom metric. Although the load/stress on a server is an indication of how many players are on a server, it is obviously impossible to accurately guess the number of players connected to the server from its load.
When the website loads the static content in the browser, it then connects to the game server with a WebSocket. With standard load balancers the connection could potentially be directed to a server that has already reached the player limit (an arbitrary value that is set to make sure the game doesn’t feel crowded and to balance gameplay). This would mean the connection would be rejected by the game server then the client needs to try again, you can see how this could result in an infinite load loop, especially if the connection keeps getting routed to the same server by the load balancer.
I would love to hear what other people’s solutions are to this problem, I have left my current solution as an answer.
1a3ca91ed97c49039b3e74fb7229fa
Lucid12112
PWA-Bazaar
ulope
jediD83
Bobby
500Foods
Vladislav
Jan Misker
Ben Buzbee
Sharif