siris icon indicating copy to clipboard operation
siris copied to clipboard

Websockets over Redis

Open kamilgregorczyk opened this issue 7 years ago • 1 comments

Hi, some time ago I reported new issue in the iris repo but it got closed and my comment was deleted:/ then I found this repo and I think it has the same problem as iris has.

WebSockets should use some kind of a backend like Redis or RabbitMQ (or any other pubsub mechanism).

Why?

You see, let's imagine we have three clients:

CLIENT 1 <--->  |  INSTANCE 1 
CLIENT 2 <--->  |  INSTANCE 1

CLIENT 3 <--->  |  INSTANCE 2

Client 1 and 2 is connected to the 1st replica of our go app, and the 3rd one is connected to the 2nd instance of our go app.

If Client 1 calls some endpoint on instance 1 which then results in a published message (which should be received by everyone) over websockets then it will be delivered to only client 1 and client 2, the 3rd one won't receive it.

There's a good pattern (used in django's channels package) which uses some pubsub mechanism:

CLIENT 1 <--->  |  INSTANCE 1 | <--> REDIS
CLIENT 2 <--->  |  INSTANCE 1 | <--> REDIS

CLIENT 3 <--->  |  INSTANCE 2 | <--> REDIS

In that way when client 1 publishes a message, it is published not into websocket channel but to redis, then it gets received by every instance that listens on messages and is then forwarded from that channel to websockets.

kamilgregorczyk avatar Jun 22 '18 12:06 kamilgregorczyk

https://hackernoon.com/communicating-go-applications-through-redis-pub-sub-messaging-paradigm-df7317897b13

kamilgregorczyk avatar Jun 22 '18 12:06 kamilgregorczyk