How many rows to insert per notification in a notification system?

拜拜、爱过 提交于 2021-02-07 08:50:37

问题


Following on from this question I am looking at building a similar notification system and I have a question (which has an obvious answer I think but I'd prefer to have some other opinions):

If a particular post generated a million likes, and then someone adds a comment to that post, I would need to notify those million people who liked the post about the comment that was added. Is the only way to achieve this to write a million rows into a NotificationRead table which has the NotificationID and 'send' them to the various users?

I can't visualise any other approach that would let me keep a track of who read their notifications and potentially inserting a million rows per post per notification sounds daunting and expensive.

Is there any other way to do it? I am using SQL Server 2014 and my application server is ColdFusion 2016


回答1:


First off, if you need push notifications, there's no escaping the fact that you need to somehow notify each of the million users. However you don't necessarily need to store all the notifications on your server.

One could make some reasonable assumptions:

  • Most activity will occur on recent posts (say, posts less than a week old)
  • Most users will not respond to the notification immediately

With this, you can skip storing notifications for recent posts: when a user logs in, you can simply poll the user's recent posts to see if there is any new activity. You're doing extra work when the user logs in but this is spread over time.

For older posts, you would still fall back to storing individual notifications for each user, but this shouldn't happen often. Here again, instead of inserting a new row for each notification, you could choose to keep a list of the last N notifications per user. That way, if a user doesn't log in for a long time, you're not piling up old notifications (that the user probably doesn't care about anyway).



来源:https://stackoverflow.com/questions/40660223/how-many-rows-to-insert-per-notification-in-a-notification-system

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!