nestjs / nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀
https://nestjs.com
MIT License
66.89k stars 7.56k forks source link

Documentation for scaling websocket gateways horizontally #1442

Closed JeetChaudhari closed 5 years ago

JeetChaudhari commented 5 years ago

I'm submitting a...


[ ] Regression 
[ ] Bug report
[ ] Feature request
[*] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Please add documentation on how to horizontally scale web socket implemented using gateways with Nest.

cojack commented 5 years ago

@JeetChaudhari why?

It doesn't have to related to nestjs at all, scaling can be done in the layer up above. Read about haproxy loadbalancer.

hmica commented 5 years ago

Are you looking to Redis adapter to interconnect several app instance ?

Destreyf commented 5 years ago

@JeetChaudhari

In order to handle websockets and scale horizontally you'd have to use a different adapter and for the websocket gateway to be aware of connections to other hosts, as @cojack states scaling can be done a layer up, but this doesn't take into account how to communicate across multiple instances (a requirement IMO for scaling websockets).

The best way to do this IMO is to use the redis adapter that @mickz18 has mentioned, this requires you to have a redis server setup that all of your websocket gateways can talk to, this isn't specific to nestjs and some common knowledge for socket.io & redis could go a long way to helping understand how to accomplish this.

@marcus-sa i am unsure why there was a thumbs down without a simple response pointing to the documentation, i understand that this is out of scope for nestjs as having a general understanding of socket.io (or other socket libraries) and sharing information via some pub/sub mechanism (redis for example) would be required to accomplish this in a sane way.

kamilmysliwiec commented 5 years ago

Just use Redis adapter as has been shown here https://docs.nestjs.com/websockets/adapter

JeetChaudhari commented 5 years ago

@mickz18 @Destreyf @kamilmysliwiec Thank you for the response, I was looking for redis adapter and how to set up. It seems I missed the adapter section in docs. Thank you for pointing out.

lock[bot] commented 4 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.