How does Discourse update the client on new posts from the server?

AI-generated summary

The discussion explores how Discourse and its chat plugin, Babble, update clients with new posts or messages without requiring a page refresh. Watercolor_Games questions whether Discourse uses websockets or a custom implementation, noting that Babble likely operates similarly. joebuhlig clarifies that both systems use the same mechanism: the MessageBus, a backend process that pushes updates to subscribed front-end endpoints. sam adds a reference to a Meta Discourse post explaining how Discourse maintains real-time updates through MessageBus and long polling.

Hey guys. My friend Declan and I were chatting on our forum’s Babble chat and we got curious how the chat plugin updates clients when a new message is sent in chat. I said “It probably uses the same code behind-the-scenes that Discourse uses to tell you ‘hey, there is a new/unread post’ without needing to refresh the page.”

First of all, am I wrong to say that? If so, how does Babble propagate messages across clients? And how does Discourse send those sorts of “new post” notifications out without refreshing? Declan did some inspection out of curiosity and didn’t see any sort of websockets going to the server.

My idea is that Discourse uses something similar to web sockets but doesn’t actually use true websockets. Like its own implementation. Either that or it uses something like SignalR in the ASP.NET world. What’s really going on behind the scenes? I’m really interested in those sorts of things and I’m really curious now.

I’ve not looked at Babble, but I’m assuming it uses the same mechanism the rest of Discourse uses:

https://github.com/SamSaffron/message_bus

It’s a process or subscribing to an endpoint on the front-end and pushing updated data to said endpoint from the back-end. You can see this process if you do a search for MessageBus on the Discourse repo.

See also: