Why Do Presence Channels Generate So Many Messages?

Presence channels can be extremely powerful because it can expose an awareness of who is subscribed to that channel. However the ability to always keep track of users in the channel can generate a large number of messages: How is my message count calculated in Channels?

The reason for this is as follows:

Imagine you have a channel for to keep track of participants in a game. presence channel feature. For game 123, they have the channel presence-game-123. When player 42 subscribes to this channel, they receives the full current set of other players, and a member_added event is broadcast to all other subscribers. When player 42 unsubscribes (or disconnects), a member_removed event is broadcast to the remaining subscribers.

A typical FooBar game has 600 players, and each player stays for an average time of 60 seconds. By Little’s Law, we know that 600/60 = 10 new clients arrive every second. Clients leave at the same rate, so 10 clients also leave every second. Each arrival triggers a member_added event, and each departure triggers a member_removed event, so we have 10+10 = 20 triggered events per second. Each event is broadcast to the entire group of 600, consuming 600 messages from FooBar’s quota. So the presence channel for this game consumes 20 * 600 = 12,000 messages per second! This is over one billion messages per day! If you are looking for a message (and cost) efficient way to implement large scale presence see this article.

Still have questions? Please reach out to our Support team by visiting this page.

Last updated