Need help setting up a logic behind a Facebook notification system style
I want build a notification system to my website, similar to Facebook. The
notifications don't need to be in real time.
This is what I have in mind:
User create an event (upload a new photo, add a new comment, like a photo,
or even an administration alert to all users)
Run a cronjob every 5 minutes to add the notifications into the
notifications table:
id|id_content|type_of_content_enum|affected_user_id|date|seen_bool
The cronjob, will run several functions for each type of notification, for
example:
add_photos_notification() // This function will check all photos added in
the past 5 minutes, and insert a row in the notification table, for each
user following this person. The function will group all photos added into
the past 5 minutes, so the follower don't get many notifications for the
same type of content. Resulting in a notification like: User X added Y
photos in his profile.
add_admin_notification() // This function will check all news added by the
administration of the site in the past 5 minutes, and insert a row in the
notification table, for each user on the system ...
Is this a correct approach to build a notification system?
Is it possible to miss an event, running a cron every 5 minutes where
functions retrieve the past 5 minutes events?
To be safe, do you think an alternative could be checking all events where
a field 'notified' is not true? The same function that will grab the
events where 'notified' = false, update it to true after adding that
notification into the notifications table.
Thanks,
No comments:
Post a Comment