Discourse does this via its messagebus.
The messagebus the Discourse team built has its own separate repo here.
It looks like the ‘latest’ topics are subscribed to here.
So rather than making ajax calls on a timeout, just subscribe to the messagebus.