Hello, I am looking into setting up PubSub for my application to listen to the moderator channel events. My application can be used by any broadcaster and therefore means when I setup PubSub it will need to be able to handle setting up PubSub for each channel.
I saw there were some limitations to in the documentation:
Clients can listen on up to 50 topics per connection. Trying to listen on more topics will result in an error message.
- We recommend that a single client IP address establishes no more than 10 simultaneous connections.
I’m not quite understanding this. Say I had 100 channels and I was listening to a pubsub topic for each. What would that structure look like? Would I set up a socket connection for each individual channel and that would be okay with these limitations? Or does the “clients can listen” refer to my application and not the actual individual channel meaning my application as a whole can only listen to 50 topics?
Thanks in advanced. First time using anything like this
You wouldn’t need to establish a connection for each individual channel, as a PubSub connection isn’t limited to any specific channel, you can listen to topics from different channels on the same connection.
For your example of 100 channels, needing to listen to 1 topic for each, you would need at least 2 PubSub connections, and can listen to 50 topics on each of them. If more channels used your app, you would need to establish additional connections as those first 2 would be full.
The recommendation for simultaneous connections is just a recommendation, and not a requirement, and generally means that any single server should ideally stick within that limit. For client-side apps (such as a PubSub connection in an app running on the broadcasters machine, or in a browser tab) it’s not an issue as they would usually only need a single connection for the few topics they use themselves.
For a server-side app the number of connections would need to scale with the number of users you have, and the recommendation is for 10 connections with a max of 50 topics which would allow you to have 500 topics. That per IP number is just a recommendation though, and you can go beyond that but may run into performance issues, and if your server goes down that’s a lot of connections/topics you need to set up again.
Thank you for the great response!
I am curious how a larger application would handle a large user base. Say an application like nightbot was using pubsub on their backend to track a topic for each user. The would be way over the limit. Does twitch not have a solution for a large number of these connections?
Larger apps balance connections over multiple servers, also one of the main advantages of PubSub is that it can be used client-side, where as server-side apps can more readily make use of Webhooks, EventSub, polling the API, and Twitch Chat connections, which allows many apps to simply not need PubSub as it’s quite limited in terms of what topics are available on it.
Okay that makes a bit more sense. Say I was just looking to get moderation actions(bans, timeouts, messages deleted) for these 100 channels. Is there a better option than relying on the limited connections to pubsub?
Depending on what events you need, a chat connection is a popular option as it provides a lot of functionality that many apps require as well as moderator actions. There are still some technical limits to the number of channels you can join per connection, but there’s not strict Twitch limit on how many connections you can have (beyond don’t try to start a malicious number of connections).
Alternatively you could look in to EventSub https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types which has channel ban and unban topics. That’d allow you to not need any established connections, just a web server to listen for incoming notifications from Twitch when those events occur.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.