Websockets with channels - worried about nothing?

Hey guys -

I need an admin to visit a page like user/234 and connect to a phoenix channel to get the user’s latest changes.

We’re getting that change data over a websocket connection to couchbase.

So 99.9% of the time, no one will be on page /user/234. So it seems silly that each time I get a message from couchbase, I join that channel user:234, broadcast the info I got from the couchbase websocket, and leave the channel, right? Because no one else is in the channel to receive it most of the time? Or am I worried about nothing because joining and broadcasting is so lightweight?

The other way I thought to implement is when a user joins a channel, on join I initiate a connection to couchbase’s websocket. But then if I have 3 ppl join the same channel, I have 3 connections to couchbase’s websocket all broadcasting messages to the channel… so, seems bad.

The phoenix team fit I think 400k-600k connections onto a single server with 16gb of ram. Channels are pretty cheap.

4 Likes

Wait, what? Why are you joining a channel to broadcast?

All you need to do is Broadcast a message with the user:234 topic. If there are any channels subscribed to that topic then the WebSocket gets the data. If no one is subscribed then it gets thrown away.

Have the server connected to the Couchbase changes WebSocket and then broadcast all the changes with the right topics. The PubSub implementation takes care of the routing and dispatching.

3 Likes