DEV Community

Cover image for How I Built a Production Ready Microservice Notification System with NestJS, Redis, Bull Queues, and Docker
Peace Melodi
Peace Melodi

Posted on

How I Built a Production Ready Microservice Notification System with NestJS, Redis, Bull Queues, and Docker

I built a real time notification microservice with NestJS, Redis, PostgreSQL, and Docker.
When you are building a system that needs to deliver notifications instantly, a simple REST API is not enough. You need a system that is fast, reliable, and does not collapse when traffic spikes. That is the problem this microservice solves.
The foundation is NestJS with TypeScript. Everything is modular, everything has a clear responsibility, and the codebase scales without becoming a mess.
The first serious architectural decision was Redis. In this system, Redis powers the job queue through Bull. When a notification request comes in, it does not get processed immediately. It goes into a queue stored in Redis and a processor picks it up and handles it. The API responds instantly, the system never gets overwhelmed, and every notification gets processed without anything getting lost. Redis is not just a cache. In this system it is the backbone of the entire asynchronous processing layer.
The notifications are stored permanently in PostgreSQL. Every notification has a type, a read status, a timestamp, and belongs to a specific user. You can filter by read status, filter by notification type, and get an unread count, all from a well structured database.
Real time delivery runs through Socket.IO. When a notification is processed through the queue, it gets pushed instantly to the connected client through a WebSocket. Each user has their own room so notifications are always targeted and never cross between users.
The entire service is containerized with Docker. Without Docker, a backend service works on your machine but behaves differently on a server. With Docker, the application, its dependencies, and its environment are all packaged together. One command and the full system is up, whether that is on your local machine or a production server.
The system also has full unit test coverage across the service layer, controller layer, and WebSocket gateway. Twenty tests, all passing.
This is what backend development looks like when the goal is not just to make something work, but to make something that holds up under real conditions.

GitHub: https://github.com/PeaceMelodi/notification-microservice

Top comments (0)