What are the rooms for? What do they contain? Messages? State? Where is that information stored?
I’m holding a count for each channel with themselves contain a list of user_id.
Do you need fault tolerance, or are the rooms ephemeral?
Yes and no.
The room lives as long as people joins or stays in the room.
Those rooms for users to get people in touch with another person, so once someone found a partner, they live the room.
So on average people would join and leave regularly, but you could have more people just in the meantime
Do you need to scale out?
Yes
If not, you can just put all of the rooms in one ETS table on one node. Or in Postgres, or Redis, or whatever. That will probably scale into the millions.
If you look at this post
This is kind of what I’ve done.
I merge the local counters diff with Phoenix trackers and then store the result in an ETS table.
If you do need to scale out, hash partition the rooms across nodes. When a user connects, choose a random node and ask that node to add the user to one of its rooms. The node knows the state of each room on that node, so it can pick one at random. Then if you need to look up any other state about that room, you can hash it and contact its node.
I create room ids on demand in ascending order based on the last room filled.
if all rooms from 0 to 10 are full, I assign the next users to topic “room#11”
That allows me to spread users evenly among new topics.
Not sure to understand how assigning users to random topic in random node, would work ?
Wouldn’t I end up with lonely users in many different topics ?