How to get online status for everyone in friends list?


Let’s say there are a million users online (as an example), and each user has like 50 friends in their friends list. What’s the strategy on how to display the friends list and live online status for the people in the list?

Basically the way I have it set up, a million logged in users will be added to “room:lobby”, which will be our default site-wide room that everyone will join.

I have Presence set up for smaller fixed-name chat rooms that are limited to 100 members per room, but I don’t think Presence would work well in a huge “room:lobby” with a million people. Also, I’m not sure if Presence would be a good fit for keeping track of who is online with a friends list (like a million separate friends lists).

Like say if I login, do all 50 of my friends have their own friends list “room” with a Presence set up and I get added to all of my friends’ “friends list” room (50 separate rooms), and they get added to mine - silently in the background?

How do I deal with this problem?


1 Like

This is a quite old post, which iirc still uses API of pubsub pre V2, but it should tell you gist. I might just be that some of the code examples no longer work exactly as posted.


Hi @peppy I’m thinking about your question in this way. Each friend list is group of participants. Each participant can be part of one or more friend lists. To be able to know which group the participant belongs to you need to store these relations in database. Database could look like:

friend_lists table
id | name | ...
friends table
id | username | password | ...
friend_list_membership table
friend_list_id | friend_id
status table
id | status
friend_status table
friend_list_id | friend_id | status_id

Topics that you need to provide are room:#{friend_list_id) and status:#{friend_list_id}.

So whenever participant joins room:#{friend_list_id), list of participants will be loaded with all their statuses.
In other hand when participant joins status:#{friend_list_id}, online status will be inserted in database and all other participants in that friend list that are subscribed on topic for status changes will be informed. Same thing will happen when participant go offline (by closing application or some other reason), terminate/2 callback will be triggered and there you will update status in database from online to offline. Again all subscribed participants will be informed about it.

I hope I helped somehow :slight_smile: