Designing Notification System with Message Queues
Ashis Chakraborty
Posted on February 15, 2021
What is Message Queue?
From the name itself, you can understand it is a queue. But it’s a particular type of queue. It routes messages from the sender to the receiver.
It is a queue; it follows the FIFO (First In First Out) policy. It means the message that is sent first will be delivered first. In some cases, we can add priority to a message, which will make it a priority queue.
So, where do we use a message queue? Say we are designing an email server. The sender sends an email, but the receiver is offline. The mail server needs to temporarily store the mail until the recipient comes online and gets the message.
Message queues can also be used for implementing notification systems. Message queues also allow us to run background processes, tasks.
Properties Of A Message Queue
Message queues are asynchronous in style. Asynchronous behavior allows the components(sender and receiver) to communicate with each other in the background.
An important property of message queues is that they give temporary storage for storing messages until they are processed & received by the receiver. This is the property that makes the message queue an important component while designing a system.
We can add priority to the messages in case of the requirement of the system.
Other important message queuing properties include message acknowledgments when a message is received successfully, retrying for failed messages in case of failure scenarios.
We now need to look into a popular messaging model widely used in the industry, the publish-subscribe message routing model.
Publish-Subscribe Pattern
A Publish-Subscribe model is where many consumers receive the same message sent from a single or many sources.
Current days, we often subscribe to various topics on websites for being notified of the new updates on any particular interest. Be it from Facebook groups, Livescore for games, etc. We will discuss pub-sub in another article. For now, we should know, message queues have components that push the messages to the queues based on the message type and the rules which are set.
The exchange component will push the message to the queue, and the consumers will receive the message. The relationship between exchange and the message queue is known as Binding.
Facebook newsfeed notification system with the message queue
In the latter part of this article, we will discuss how notification systems and real-time feeds are implemented using message queues.
For more detailed implementation, check this link
Posted on February 15, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.