I am implementing a notification system and seeing if these suggestions are valid to set up, if one is better than the other or a better solution is available:
A notification is added to the database. A guest / identifiable user logs onto or uses the site. They are greeted with notifications they haven't seen before with the option to close or read later.
Are these options much of a muchness, is it better to add potentially 100,000+ alerts and as those users discard or interact with the notice, their status is changed or the alert deleted. This could become a very large table...
What's a more extensible set up for custom notifications based on user activity?
you'll display realtime notification alert to your visitors or users. you can simply make a notification bell on the top corner which will display all the related notification alert to user and they will be always get alerted for every new notification.
I wouldn't do it that way. I'd store a record for each (user,notification) and mark each record as read or unread. You can then record when they read it, which might be important depending on your application (eg if you needed an audit trail of some kind).
100k records is not very big. Don't worry about size until you get to at least 10 million records. If necessary archive them at some point. But you should do some estimates on how quickly you'll generate 10 million records. If it's 3 days, then yeah you have a problem. If it's 3 years then you don't.
This option of course has the notification text in a separate table.
This should also scale extremely well with even higher number of messages as you select the unread messages for a user (indexed) and can either join to get the notification text (if your table is in the tens of millions of records size) or select them and then separately select the messages.
Partitioning the (user,notification) table is easy: you base it on user ranges.
And when users delete messages, generally you should just mark it as deleted rather than actually deleting it. Most of the time there's not much reason to delete anything in a database.
I'm coding my our website and have the same question but I solved myself this way:
Read/Unread = true/false
I think Facebook periodically runs a cron job to delete old notifications which we cannot see after our limit notification has been reached.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With