Understanding client_id in the message bus

AI-generated summary

The discussion revolves around understanding the client_id in the /message-bus/{client-id}/poll endpoint. Mudit_Maheshwari is seeking guidance on what the client_id represents and how it’s set, as they observe a high number of message-bus poll calls on their Discourse hosting. Alexander suggests that the client_id identifies who the MessageBus should deliver messages to, and pfaffman offers to help if Mudit_Maheshwari provides more context.

Mudit_Maheshwari explains that they want to check if there’s a correlation between client_ids and current users to define effective rate limiting rules. pfaffman clarifies that the polling is expected and is necessary for the forum to function, as it allows for real-time updates. RGJ confirms that a high number of message-bus poll calls represents a lot of concurrent users, with each unique client-id representing a browser session, and advises against implementing rate limiting rules for this necessary traffic.

Hello :wave: ,

I’ve try to dive into the codebase recently, to figure out the client id in /message-bus/{client-id}/poll endpoint. Could someone please provide some guidance or direct me to the relevant code or documentation that explains what exactly this client ID represents and how it’s set?

Thanks in advance for your help!

I could be wrong, but the clientId is likely to identify who the MessageBus should deliver X message to

Imagine it as a conversation where every X amount of time, the client asks the server “Hey, I have id XYZ, do you have a message for me?”

The client id seems to be automatically generated every time the script is loaded (I don’t know if in the case of Discourse this generated clientId somehow persists on the client)

Are you trying to use or understand the message-bus?

If it’s the former, maybe describe what you’re trying to watch and what you’re doing that’s not working. What I do is grep through the plugins in GitHub - discourse/all-the-plugins · GitHub for MessageBus.

To give some more context, we observer a high number of message-bus poll calls on our discourse hosting. Wanted to check whether there’s any correlation between client IDs and current users. If such a connection exists, it could help us identify patterns and define effective rate limiting rules to manage the traffic.

I mostly don’t understand it, but you can look at the browser dev tools and see that every open window is regularly polling the message bus. That’s how stuff happens without reloading the page, like seeing posts get edited, message counts updated, and so on. It’s expected that it will be a lot. Looks like it’s polling a random number, so you (or at least I) can’t tell (easily) what user it is.

Yes - a high number of message-bus poll calls represent a lot of concurrent users, where each unique client-id represents a browser session.

No - this is necessary traffic, it’s required for your forum to function. If you see a lot, it’s also a sign of success! :+1: