# How does Discourse implement live update notifications?

**URL:** https://meta.discourse.org/t/how-does-discourse-implement-live-update-notifications/46610
**Category:** Development
**Created:** [June 29, 2016, 11:11am UTC](https://meta.discourse.org/t/how-does-discourse-implement-live-update-notifications/46610 "2016-06-29T11:11:33Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![piratdavid](https://avatars.discourse-cdn.com/v4/letter/p/ba9def/32.png) [@piratdavid](https://meta.discourse.org/u/piratdavid)
#### Post date: [June 29, 2016, 11:11am UTC](https://meta.discourse.org/t/how-does-discourse-implement-live-update-notifications/46610/1 "2016-06-29T11:11:33Z")

</div>

Hi,

I have written a plugin that has a news feed with a lists of latest topics in a sidebar. It updates regularly by making an ajax call to /latest.json every few seconds. The existing latest page in the forum has the same kind of functionality but the update is instant when something is posted. Is it safe to turn down the ajax calls to a very short interval or is this implemented using something like websockets, etc.

Thanx

---

<div class="post-metadata">

### Author: ![angus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/angus/32/341715_2.png) [@angus](https://meta.discourse.org/u/angus)
#### Post date: [June 29, 2016, 11:52am UTC](https://meta.discourse.org/t/how-does-discourse-implement-live-update-notifications/46610/2 "2016-06-29T11:52:45Z")

</div>

Discourse does this via its messagebus.

The messagebus the Discourse team built has its own separate repo [here](https://github.com/SamSaffron/message_bus).

It looks like the ‘latest’ topics are subscribed to [here](https://github.com/discourse/discourse/blob/8f4bc2228fd5def7a4190222b0ae993a384791d9/app/assets/javascripts/discourse/models/topic-tracking-state.js.es6#L71).

So rather than making ajax calls on a timeout, just subscribe to the messagebus.

---

<div class="post-metadata">

### Author: ![gdpelican](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gdpelican/32/81308_2.png) [@gdpelican](https://meta.discourse.org/u/gdpelican)
#### Post date: [June 29, 2016, 12:40pm UTC](https://meta.discourse.org/t/how-does-discourse-implement-live-update-notifications/46610/3 "2016-06-29T12:40:15Z")

</div>

If you’re curious, MessageBus is implemented using long polling (it does not support Websockets), which means the ‘live’ updating is done through requests which are held waiting on the server until something needs to update, at which point it responds with some data, and then initiates another ‘long’ request.

Sam’s exhaustive explanation [here](https://meta.discourse.org/t/how-discourse-stays-online-message-bus-faye-long-polling/3238/7).

---

<div class="post-metadata">

### Author: ![piratdavid](https://avatars.discourse-cdn.com/v4/letter/p/ba9def/32.png) [@piratdavid](https://meta.discourse.org/u/piratdavid)
#### Post date: [June 29, 2016, 12:46pm UTC](https://meta.discourse.org/t/how-does-discourse-implement-live-update-notifications/46610/4 "2016-06-29T12:46:06Z")

</div>

Thanx guys!

Things cleared a lot. 🙂

---

<div class="post-metadata">

### Author: ![piratdavid](https://avatars.discourse-cdn.com/v4/letter/p/ba9def/32.png) [@piratdavid](https://meta.discourse.org/u/piratdavid)
#### Post date: [June 29, 2016, 1:00pm UTC](https://meta.discourse.org/t/how-does-discourse-implement-live-update-notifications/46610/5 "2016-06-29T13:00:58Z")

</div>

Is it necessary or even possible to stop subscribing if I switch to another page or for some reason don’t want my feed to update? That is without stoping any subscriptions in discovery.

---

<div class="post-metadata">

### Author: ![piratdavid](https://avatars.discourse-cdn.com/v4/letter/p/ba9def/32.png) [@piratdavid](https://meta.discourse.org/u/piratdavid)
#### Post date: [July 1, 2016, 3:13pm UTC](https://meta.discourse.org/t/how-does-discourse-implement-live-update-notifications/46610/6 "2016-07-01T15:13:53Z")

</div>

Is there an answer to this? 🙂

---

<div class="post-metadata">

### Author: ![gdpelican](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gdpelican/32/81308_2.png) [@gdpelican](https://meta.discourse.org/u/gdpelican)
#### Post date: [July 1, 2016, 4:37pm UTC](https://meta.discourse.org/t/how-does-discourse-implement-live-update-notifications/46610/7 "2016-07-01T16:37:20Z")

</div>

Yep, it’s certainly possible. Babble’s implementation:

```plaintext
const messageBus = Discourse. __container__.lookup('message-bus:main')
messageBus.subscribe('/babble/topics/1/posts', (data) => { performSomeAction() })

```

Later, when we switch chat channels and don’t want to listen for topic 1’s events anymore:

```plaintext
messageBus.unsubscribe('/babble/topics/1/posts')
messageBus.subscribe('/babble/topics/2/posts', (data) => { performSomeOtherAction() })

```
