REDIS X NODE.JS = ❤️
Redis is an in-memory data structure store that can be used as cache, and message broker.
We will take a real-time scenario and try to implement using Nodejs and Redis.
Suppose , We are processing user information in our backend server, Where sending notification to them via email or SMS is a crucial feature. For this we have to depend upon third party services like Twilio , Send-grid , etc... to send notifications to the user(as most of the products).
We can use Redis Lists to implement a simple queue for storing notifications. When a new notification needs to be sent, you can push it onto the list of queue and a worker server will be responsible for processing the same.
The benefit will be our mains server will have Separation of Concerns, which primary goal is to communicate to the database itself.
So for this i have created two servers using express.
express-backend
This will responsible for taking the payload and push to the Redis notifications queue and process with other database operations.
worker
Worker will be subscribed to the Redis notification all the time. Whenever it will receive the response from Redis queue it will proceed with the data to send notifications.
LETS SEE THIS IN ACTIONS