Hi folks, I’m a (fairly) new user of Autobahn, and I was wondering if I could get some advice on dealing with large numbers of subscriptions.
Imagine an application that has a ‘search’ feature - such as an email app, bulletin board or a social network. Now suppose you want live updates on the search results - that is, if someone adds a comment to a post, or makes some mutation to one of the objects in the search result set, you’d want to publish that so that other users get notified.
So how do we set up a subscription topic that represents these search results?
The brute force approach is to have a separate topic for each item, something like ‘posts.update.’. However, that means that if you have 100 items in your search results, you have to subscribe to 100 topics. So my first question is, is that likely to be a problem, performance-wise? (There’s also the issue that subscription is async, so you’d have to wait for 100 promises, and manage 100 subscription handles. And when you start talking multiple async operations, there’s race conditions to consider - what happens if someone mutates a bunch of objects at once, and some subscriptions have completed the handshake while others are still pending?)
Note that you can’t use topic wildcards in this case because the set of search results is an arbitrary set - listening for ‘posts.update.*’ is going to give you every post, not just the ones in the search results, which is not what we’d want.
A somewhat more graceful approach would be to somehow encode the search terms in the subscription topic. If it’s a simple keyword search, you could have a topic name such as ‘posts.search.my.search.keywords’, but this won’t handle cases like ‘from:ellen to:me’. And it requires the publisher to listen for topic creation / delete events so as to know what search terms are actively being subscribed to.
So I’m curious to know how folks have approached these kinds of issues.