[erlang-questions] Is gproc pub/sub pattern good for status notification?

Akshat Jiwan Sharma akshatjiwan@REDACTED
Sat Nov 9 09:54:03 CET 2013

HI guys,

This is my first post to the group. You will be seeing a lot more of me
from now on as I have started using erlang actively :) Here is the question

Consider a very common scenario

1.A user comes online/or goes offline (i.e his status changes)

2.His friends are notified of the status change.

I am trying to solve the notification problem in erlang using

There are two solutions which immediately come to mind
Solution 1

1.Create a channel for the user

2.Subscribe his friends to his channel(iterative process).

3.Notify them on state change.
Solution 2


   Create a channel for the user.

   Send messages using gproc:send/2 on state change(again an iterative

It seems to me in both cases looping can not be avoided. So I am leaning
towards second approach myself as there is less over head(single channel
for every user no subscriptions)

Which approach is better?
Relevant article

Facebook chat blog <https://www.facebook.com/note.php?note_id=14218138919>

The naive implementation of sending a notification to all friends whenever
a user comes online or goes offline has a worst case cost of O(average
friendlist size * peak users * churn rate) messages/second, where churn
rate is the frequency with which users come online and go offline, in
events/second. This is wildly inefficient to the point of being untenable,
given that the average number of friends per user is measured in the
hundreds, and the number of concurrent users during peak site usage is on
the order of several millions.

With regard to above comment my question is the same. If you use pub/sub
you save on sending notification but incur cost on subscribing in the first
place so how does pub/sub benefit over normal sending.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20131109/135c0081/attachment.htm>

More information about the erlang-questions mailing list