I’ve been recently playing with Phoenix Channels. It’s what a lot of people call the bread and butter of Phoenix, it’s what makes Phoenix really powerful. I haven’t ran into a problem yet where I had to use them or that they were the fix solution I reached for. I’ve only written 2-3 small production elixir applications.
I’m currently playing with phoenix channels and using them instead of ajax to send data to the server when a user answers questions on a survey. It doesn’t seem like the best problem to be using them for, compared to maybe just ajax calls to a controller when a user answers the questions but it’s something I wanted to explore to solve a new feature request on the application I’m working on.
I’ve been going back and forth on when it makes sense to use channels and it seems like they make the most sense when:
- Sending data bidirectionally fairly often ( like chat )
- When you want to send data from the server to the client ( like notifications )
I’ll give another good example that a co-worker and I recently had a discussion about:
We work in the medical industry and it’s pretty common to have an auto logout feature for our applications. So when a user isn’t active, we log them out.
My co-worker thought it would be interesting to see if we could implement that auto logout functionality with phoenix channels, and how well that would work.
On one hand I don’t think this is a good solution, because though it works it seems odd to use a web socket just to timeout and log a user out. Especially because the server has a process just sitting around for this use. I do understand that phoenix is very performant, and this would scale probably well beyond our needs, but it just doesn’t seem like the right solution.
Should I be worried with how I am currently playing with using them?
I also think a more general question is, Phoenix makes it so easy to hookup channels and use them that it seems to be used in ways that may not make sense. When in other development stacks it would be a pain to setup and we would often skip over them unless they really make sense.
So the bigger question is, because phoenix makes them easier to setup and use I wonder if we will see them used in places where we normally wouldn’t, and if that makes it more of a blurry line between when it’s a good idea to use them versus not.