Asked

Best practice for adding "notifications" to a site?

Making a dating site.

Imagine James "hearts" Sally's profile. I want a simple notification for Sally next time she logs in. Like Indie Hackers, where a little red number by your profile.

My current idea is having both:

{hearts: [james, fred, george]}
{notifications: [james]}

objects in the users mongo database. And every time an item gets added to hearts it also gets added to notifications. Then when a user acknowledges the notification i remove the item from notifications?

I've never done notifications before so wasn't sure there is a best practice? Bear in mind I also want to add in some notifications for messaging later — thank you!

you want some kind of a queue mechanism to store the notifications and you want some kind of service to check this queue periodically... X minutes, X seconds, X hours... whatever. if queue has stuff, send it out. People usually use redis for this type of things. I dont know what frameworks/backend you use ppl usually use something like Redis for the queue.

hmm thanks alex. So I'm using Node + Mongo . Will checkout Redis

Sign in to answer 😃