2

I have a chat feature that is using SignalR, and have a sql server backplane. When people are chatting, messages show up on both servers just fine. However, if you refresh the page, obviously the chat history is gone.

So when people say something, I cache that in a dictionary in memory. The problem is, that message is not in the memory of the other server, so if someone refreshes and they are load balanced, that message does not appear.

Is there anyway to subscribe to getting the events that are going on between the server and the backplane so that I can keep the two caches in sync?

Thanks!

bladefist
  • 1,084
  • 3
  • 15
  • 25

1 Answers1

1

The easiest way to handle this issue would be keeping the messages in a database, thing you are trying to avoid probably because SQL is not the fastest database for this.

Now, I would use another SignalR backplane - with Redis for the following reasons:

  • Redis is an in-memory cache, so every operation will be much faster (since everything is loaded in RAM)
  • you have the same functionality as with the SQL backplane
  • Redis has a very nice pub/sub service which is exactly what you need here.
  • you might actually not need the dictionary if you are storing them in Redis which is really fast

Since there is an example from Microsoft for doing this, everything is supported, and you might even only use the pub.sub mechanism (although having 2 services doing this - SQL and Redis might not be worth).

Anyway, this is how I would proceed.

Hope this helps. Best of luck!

radu-matei
  • 3,469
  • 1
  • 29
  • 47