Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suggestions for a user notification system in MySql and PHP

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.

  • Notification table stores notification texts and Id.
  • Option 1: Alerts table stores all users who have read the notification
  • Option 2: Alerts table stores all users who have NOT read the notification

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?

like image 281
Peter Craig Avatar asked Jul 25 '09 08:07

Peter Craig


People also ask

How can I get FB notification like PHP?

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.


2 Answers

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.

like image 158
cletus Avatar answered Oct 15 '22 20:10

cletus


I'm coding my our website and have the same question but I solved myself this way:

  1. Store all record in a notifications table.
  2. Read/Unread = true/false
  3. CRON Job: delete old 10 notifications if user have more than 50 notifications.

I think Facebook periodically runs a cron job to delete old notifications which we cannot see after our limit notification has been reached.

like image 22
Huy trịnh Avatar answered Oct 15 '22 18:10

Huy trịnh