Suggestion for Socket.IO Server

Hi,
We have a chat server built on Socket.IO, which depends on MongoDB adapter. We only connect with Websocket, so do not need to worry about sticky sessions. I have a couple of questions on the setup and will really appreciate if you guys can throw some light on it:

  • I am using dedicated-1x server. How much should be the Hard Limit for the connection in config? 25 is too less, but what should be the basis of calculation, as there can be 100’s or 1000’s connections, but most being in idle state. How can I scale or set server size in this scenario?

  • Can I scale this server, just as any other regular node server. Do I need to look at anything apart from implementing Socket.IO adapters? The socket.io documents do mention about clustering, via node or pm2, however, I am not scaling via node/pm2, so have not implemented any clustering code in the project. So can I just scale this server with flyctl scale ?

  • When is the new server created if soft limit is reached? Is it the moment concurrent requests hit soft limit, or it watches for few seconds after concurrent limit hits soft/hard limit?

This varies quite a lot! I would bet you can support 500 concurrent connections pretty easily, though you’ll want to monitor RAM.

We scale based on our metrics. So when our metrics show that the count * soft_limit is less than total connections, we increase the count. This runs once every 15 seconds so it’s slower to scale than if we launched one on demand.

I would try setting a soft limit of 400 and a hard limit of 500 to start.

Scaling should work fine just like any app, especially if MongoDB is holding all the state. If you’re sending messages between people without touching the database, you’ll need to do some clever stuff with socket adapters. NATs is a really good tool for messaging between websocket clients, for example.