So I am making a notification system (much like how Facebook or Instagram have) for a website, and I’m wondering what would be the most efficient way to accomplish this.
I have a table for Messages, and I can put fields such as (title, message, link, user, senddate, expiredate, status). I could then make a message for each user any time a notification comes up (new comment reply, new course, etc).
That seems the most straightforward to me. That would over time generate a lot of messages, especially as the site grows, so I imagine there would have to be some cleaning done (hence the message expiration, which could be used to schedule a delete of the message).
Another strategy would be to make the same message table, remove the user field, and only create one message (not one per user). Then, attach the message to a message list field created into the user table. New messages can be attached to the user, and can be removed after the user chooses to remove it (click an X icon on a message panel for example).
This would generate much less messages, but would be adding lots of messages to users. The list of messages on the user table would not conceivable get bigger than 10-20 messages. However, expiring messages would be trickier, because I couldn’t just delete the message as it would have a soft reference. I would need to remove it from all users who hadn’t removed the message yet before deleting it. I would also lose the ability to have status (message read, clicked, hidden, etc) since there would only be one message.
So functionally it seems better to go with the first strategy. I’m just wondering if there is a performance difference between the two options.