greentornado
Hi i’m a new elixir user
I have a question like this, if I’m creating a phoenix cluster and allowing user to come and play game/chat via channel.
The case is: i’m load balancing those phoenix server under a single domain.
Do I need to deal with something like sticky session/ server affinity like socket.io land ?
Can I use digital ocean load balancing service ?
Thanks.
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app?
Looking for hints regarding:
Addi...
New
Kia ora,
We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
Hi all, I wanted to ask how the community is dealing with post-release steps.
Today we have Ecto migrations, which make sure that the db...
New
Hello,
I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #ai
- #genstage
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










First 5 of 5 Posts
aseigo
Phoenix’s PubSub works from any node to any node in a cluster. So once a user connects and opens a websocket connection, they are able to connect to their channels, and if they have multiple connections (on same or different nodes) this is tracked as part of their overall presence. The websocket connections themselves are stateful, and if they are disconnected a new one is created.
You could also try this locally
Start a couple of nodes running your application, running it with something like
iex --sname s1 -S mix phx.server, changing the name passed to --sname on each instance. You’ll also need to change the port number phoenix starts listening in your config before you launch each instance (4000, 4001, ..). At that point you should have a nice local cluster and you can try connecting to the various running nodes and see how it works. If you really want to get “fancy” you can set up haproxy or nginx to load balance between your locally running nodes to fully emulate a load-balanced cluster.Having local setups like this for testing is not so difficult and really useful for testing clustered deployments of applications you know will be deployed in that manner.
I don’t know anything about DO’s load balancing, so can’t say anything about that …
greentornado
Thanks
So we dont need to care about those sticky session then ?
How do we deal with in-memory channel state between nodes ? ex: we have a poker game, we need to store which cards player has
gon782
Presumably you would store the state for a game in a
Gameprocess in the cluster, not in the channels themselves. The clients, when they initially connect to the channels, then query for “Which games am I in?” and get a list of games that they can sync from.What coordinates that and the games themselves are all presumably
GenServers that will be registered so that any node can reach them (the easiest way to do this is just to use:globaland register them with names like{PokerServer.PokerGame, poker_game_id}and any process in the cluster could then reach them by using that unique name.Using
:globalwill mean that things lock up heavily with regards to process registration and what not when there is a netsplit and the short version is that it prohibits you from having too many nodes in the cluster. The exact number isn’t something I’ve seen myself, but from what I’ve heard 8+ isn’t going to be the best idea.If you do go with global,
:pg2is a great addition alongside it as it will allow you to have cluster-wide process groups out of the box, much like:globalis global registration within a cluster.grych
You may store your data in the socket. But, there is a catch - it only exists until disconnect, so in case of the network issue you loose everything.
I keep the data in the browser, and send it to the server on connect, so reading is cached, but update must be done on the both client and server side.
greentornado
Yeah i wanna store everything at server side. So once an user got network, he can resume later and then sync