Introduction
Learn to set up the Redis server.
We can run a single monolithic instance of a server application only if the number of clients accessing our application doesn’t exceed a couple of thousand. But what if we expect hundreds of thousands, or even millions of clients to connect to our application simultaneously? Then a single instance of an application won’t be able to handle the load, and we will need to scale the application out.
Scaling out a stateless application is relatively easy. If our web application merely accepts HTTP requests and then sends a query to a different application or a service that stores the data, we can have as many instances of such a web application as we want. To the client, it doesn’t make any difference which specific instance it connects to. The outcome will be exactly the same.
But what would we do if our application needs to maintain a persistent connection with each client, as is the case with SignalR? After all, we would still need to maintain the ability to send messages to specific clients and groups. But what if those groups are connected to a different instance of the application?
Fortunately, SignalR comes with a scaling-out mechanism that will allow multiple instances of our application to act as if it’s a single application. And this is what we will be talking about in this chapter.
The chapter consists of the following topics:
Setting up Redis backplane.
Preparing to run multiple hub instances via Redis backplane.
Launching distributed SignalR Hub.
Using HubContext to send messages from outside SignalR Hub.
Get hands-on with 1400+ tech skills courses.