Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scalable SignalR + Azure - where to put SignalR, and should I be using Azure Queues?

I'm developing an application that has various types of Notifications. Examples of notifications:

  • Message Created
  • Listing Submitted
  • Listing Approved

I'd like to tie all of these up to SignalR so that any connected clients get updates in real-time.

As far as architecture goes - right now the application is entirely within a single solution hosted on an Azure Website. The triggers for each of these notification types live within this application.

When a trigger is hit, I'd like to tell signalR, "Hey, send this message to the following clients" along with a list of userIds. I'm assuming that it's possible to identify connected clients based on userId... and I'm assuming that the process of send message to clients should be executed outside of the web application, so as to not slow down the MVC app or risk losing data in a broken async call. First question - are these assumptions correct?

Assuming so, this means that I'll need something like a dedicated web/worker role to be sending messages to clients. I could pass messages from my web application directly to this process, but what happens if the process dies? The resiliency concerns lead me to believe that the proper way to pass messages would be via a queue of some sort. Second question - is this a valid train of thought?

Assuming so, this means that I can either use a good ol' Azure SQL database as a queue, but it seems like there are some specialized (and maybe cheaper) services to handle message queueing, such as this:

http://www.windowsazure.com/en-us/develop/net/how-to-guides/queue-service/

Third question: Should this be used as a queueing mechanism for signalR? I'm interested in using Redis for caching in the future... would Redis be better or worse than the queue service?

Final Question:

I've attempted to illustrate my proposed architecture here:

enter image description here

What I'm most unclear on here is how the MVC app will know when to queue, or how the SignalR processes will know when to broadcast. Should the MVC app queue blindly, without caring about connected clients? This seems to introduce a lot of wasted space on the queue, and wasted cycles in the worker roles, since a very small percentage of clients will ever be connected.

The only other approach I can think of is to somehow give the MVC app visibility into the SignalR processes to see if the client is connected... and if they are, then Enqueue. This makes me uncomfortable though because it means I have to hit that red line on the diagram for every trigger that gets hit, which - even if done async - gets me worrying about performance and reliability.

What is the recommended architecture for scalable, performant SignalR message broadcasting? Performance is top priority, followed closely by cost.

Bonus question:

  • What if some messages are of higher priority than others? Should two queues be used, one of which always gets checked before the other?
like image 432
RobVious Avatar asked Nov 02 '22 09:11

RobVious


1 Answers

If you want to target some users, you'll have to come up with a mechanism, off the top of my head I can give an example, if any user hits a page, you can create a group for that page and push to all users in that group/in that page.

It's not clear to me why you need the queues. Usually users subscribe to some events when hitting a page or by some action like join a chat room, and the server pushes data using those events/functions when appropriate.

For scalability, you can run signalr in different servers, in which case you should use sql server, or service bus or redis as a backplane.

like image 185
AD.Net Avatar answered Nov 08 '22 14:11

AD.Net