When Creating a web application most of times you come to specific scenarios in which you need to send your users notifications but you start wandering how to do it?
Notifications Types/Methods
we can categorize notifications into types based on how notifications are being send to users
- Push Notifications / Realtime Notifications this is when a specific action occurs a notification is created and sent directly to user (in real-time)
- Pull Notifications unlike the first type the notification is not sent to user but it's being saved into a store and wait for user to ask for it
most systems use a combination of two types ,facebook for example, when someone react or add comment to your post you immediately get a notification (push notification) but also you still able to click on your notifications icon and list all your notifications (pull notifications)
How To Implement notifications?
for the pull notification it's straight forward by adding a table into your database where you can store your notification for each user, then user select from it by current user id.
on the hand ,push notifications are littlie bit tricky as you need to have an open connection with your user so that you can send notification to him directly, to implement this kind of notifications you can make a good use of sockets or long polling , or you can simply use a library specialized in real-time communications like firebase or SignalR if you are using .net stack, but don't forget to also store your notifications in the database as user can currently be offline or can get history of old notifications later.
Top comments (2)
thanks for this simple explanation, it really helped me to understand how notifications are working.
you welcome, glade that you enjoyed it. i highly recommend you to read my other articles