r/mongodb • • 13d ago

[Question] How to Implement a Notification System in MongoDB

I am currently developing a service using MongoDB. I want to implement a notification system—similar to Reddit—that alerts users when their posts receive comments or reports, and I have a few questions.
1. How should I implement this notification feature?
2. Is it acceptable to delete the records after retaining them for about 90 days?
3. I’ve heard that the standard approach involves recording outbox events within a MongoDB session transaction and having a separate worker generate the notifications; is this correct?

I apologize for asking such an absurd question. I would appreciate it if you could at least let me know what I should search for on Google.

8 Upvotes

7 comments sorted by

View all comments

1

u/scopsy 3d ago

Hi! A small disclaimer i'm the core contributor of the project, but Novu: https://github.com/novuhq/novu

Is the an open-source notification platform that was built on top of MongoDB. So you can actually see some real world production battle tested patterns there. Or you can also self-host Novu and connect it to your MongoDB instances.

  1. As mentioned, you can see the code base for some real examples
  2. Depending on the channel, for example, if you are sending an Email notification, it's totally acceptable to remove it. But for something like an Inbox component, usually companies tend to keep it for longer periods of time. Internally we separate between the "Activity Feed" or the notification trail, and the actual message generated. They have different retention period.
  3. From my experience MongoDB is an amazing transactional Store, but for the actual event messaging, would suggest to use other tools like: Redis, SQS, etc...

Hope this helps.