DEV Community

Kelvin Amoaba
Kelvin Amoaba

Posted on

@mentions Notifications Design

So we have all used platforms where we receive notifications whenever we are mentioned in a post or a comment. These notifications are to keep us engaged in conversations.

I am going to be explaining at the high level how to build out a simple @mentions notifications feature in any system. Note that this post is only giving you a fair idea about how to go about the whole implementation and not showing you how to actually do it in code.

Steps

  • Receive the incoming post / comment text from your UI, this data could be from an endpoint that your frontend sends posts requests to.

  • Once this data is retrieved, you would need to parse the content of the post to find every instance of an @mention. This can be done by by using regular expressions. An example is given by r'(^|\s)@(\w+)', this would match all mentions like @someone and not weird cases like some@One.
    Note that, you would have to store every mention in some form of data structure to be referenced later, probably storing it in an array.

  • Next, you would have to filter the mentions to see if they are actually present in your users table. If not, you eliminate them from the final list of users to send the notifications to.

  • Finally, you can pass these users to the notification service to then send the notifications via your favorite channel, either In-app, email or other media.

Final Takeaway

Note that, if the above steps are done in the request-response cycle, it will not be very convenient as your users will be waiting for all these steps to complete before you send back a response to them. To overcome that, you can use tools such as Redis or RabbitMQ as a message broker and Celery to perform these steps in the background.

That's it, a high level overview of the implementation. Let me know if you have any questions in the comments.
Cheers 🥂

Top comments (0)