I am implementing a similar feature like the StackExchange Inbox and I have many considerations about the resource usage.

My system has inbox messages, system health notifications and Achievements. On each page request I am querying the DB if there are any notifications from all these three resources (2 tables and one complex query).

To save some resources I am using Redis Cache to cache the notifications response IEnumerable<NotificationModel> for 10 minutes. That way I don't have to query the DB too often but I might have to wait 10 minutes to get the latest Notification.

While this works and I suppose won't hurt my Server I feel that it must be a better solution because:

  • Redis doesn't work well with large objects and my notification list contain all the information that might got large enough.
  • StackExchange does this better with instant notifications (maybe using SignalR)
  • Querying three tables, even every 10 mins, is a waste of resources.
  • I don't have the viewed state that hides the bubble notification, the one it shows about the new messages that haven't been read.

I suppose I should create a new table that will store all the notifications and I should query only that.

Maybe add a column that let me know if some of the messages are new and the rest are already read.

Store at the Redis Cache only the number of the new notifications and not the actual messages, use Ajax to show the notification only when the user request it(click on the notification icon).

What do you think about this? Have you implemented anything similar?

  • Shouldn't this be better asked on meta about inner works of a site ? – kayess Jul 27 '18 at 8:39
  • 1
    @kayess I thought meta is about the community, not about the technical stuff – Menelaos Vergis Jul 27 '18 at 8:48
  • 1
    @MenelaosVergis Not entierly – Florian Peschka Jul 27 '18 at 8:54
  • How slow is your database? – immibis Jul 30 '18 at 4:02
  • @immibis It's S2 of Azure. It's not slow, I don't want to call the DB everytime it's because this is standard load in every request of every page in any app i am developing. – Menelaos Vergis Jul 30 '18 at 11:41

Its a big topic but here are some general recommendations

  • Redis Cache should not be part of your solution design. It's something you put in to deal with load, not to achieve a solution. Get your solution working first, then add caching as required.

  • If you want to avoid polling you have to go back to the initial event. In this case when the user does something that will appear in someone else's inbox; that's the event that triggers everything else. Use that event as your starting point.

  • Don't worry about querying databases as long as your query is simple. Databases are fast

  • You don't pay the browser's electricity bill. Anything you can do on the client, do on the client.

  • These are not bad advice, not too specific but nice general advice. thanks – Menelaos Vergis Jul 27 '18 at 12:25
  • happy to add more, if you want to tighten your question up a bit? – Ewan Jul 27 '18 at 12:34
  • I wrote my current solution, my concerns and my suggested solution. What part i could tight more? – Menelaos Vergis Jul 29 '18 at 9:09
  • is there a specific aspect of your solution which is causing you an issue? – Ewan Jul 29 '18 at 9:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.