Home > Software engineering >  Handling Websockets channel states with nodejs
Handling Websockets channel states with nodejs

Time:03-27

I am trying to create an online game with multiple game sessions happening at the same time. My current setup has one NODEJS server handling all the sessions states. If I wanted this to be scalable, how could I go about it? I believe the server might get overwhelmed after a certain number of things happening at once. I am not sure if there is a way to instantiate one Nodejs server per game session or some other type of method. I'd appreciate any information that would point me in the right direction.

Thank you!

CodePudding user response:

There are multiple ways you could go about scalability.

One way would be having multiple instances of the server and using a load balancer to redirect traffic to one server.

If the state is only on the server memory and not stored in a shared store between the servers, there are ways to make a given user access the same server all the time.

I would recommend reading this article on that subject (from haproxy which might be used for that): https://www.haproxy.com/blog/load-balancing-affinity-persistence-sticky-sessions-what-you-need-to-know/.

And for more advanced configuration, there are tools that can start and stop instances depending on load.

That being said, I would recommend keeping that in mind but doing the minimal setup needed for now. Over-engineering while a simple solutions works is often a not so good idea.

  • Related