This project implements a real-time order monitoring system where connected clients automatically receive updates whenever an order is created, updated, or deleted.
The solution follows an event-driven architecture using RabbitMQ and Socket.IO to eliminate client-side polling and provide instant updates to all connected clients.
- A client sends a request to create, update, or delete an order.
- The API persists the change in PostgreSQL.
- The API publishes an event to RabbitMQ.
- A consumer receives the event from RabbitMQ.
- The consumer broadcasts the update through Socket.IO.
- Connected clients receive the update instantly without refreshing the page.
- Node.js
- Express.js
- PostgreSQL
- RabbitMQ
- Socket.IO
- Docker
src/
│
├── server.js
│
├── config/
│ ├── db.js
│ └── rabbitmq.js
│
├── routes/
│ └── orderRoutes.js
│
├── controllers/
│ └── orderController.js
│
├── services/
│ └── orderPublisher.js
│
├── consumers/
│ └── orderConsumer.js
│
└── public/
└── index.html
- Node.js
- PostgreSQL
- Docker Desktop
Create the database:
CREATE DATABASE apt_assignment;Create the orders table:
CREATE TABLE orders (
id SERIAL PRIMARY KEY,
customer_name VARCHAR(255),
product_name VARCHAR(255),
status VARCHAR(50),
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);Insert sample data (optional):
INSERT INTO orders (
customer_name,
product_name,
status
)
VALUES (
'Hardyansh',
'Laptop',
'pending'
);Create a .env file in the project root.
PORT=5000
DB_HOST=localhost
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=YOUR_POSTGRES_PASSWORD
DB_NAME=apt_assignment
RABBITMQ_URL=amqp://localhostStart RabbitMQ using Docker:
docker run -d --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3-managementRabbitMQ Management Dashboard:
http://localhost:15672
Default Credentials:
Username: guest
Password: guest
Install dependencies:
npm installStart the backend server:
npm startApplication URL:
http://localhost:5000
POST /ordersRequest Body:
{
"customer_name": "Harry",
"product_name": "iPhone 17",
"status": "pending"
}PUT /orders/:idRequest Body:
{
"status": "shipped"
}DELETE /orders/:idOpen the dashboard:
http://localhost:5000
Any CREATE, UPDATE, or DELETE operation will be pushed instantly to all connected clients through Socket.IO.
No polling or page refresh is required.
┌─────────────────┐
│ Browser Client │
└────────▲────────┘
│
Socket.IO
│
▼
┌─────────────────┐
│ Consumer │
└────────▲────────┘
│
▼
┌─────────────────┐
│ RabbitMQ Queue │
└────────▲────────┘
│
▼
┌─────────────────┐
│RabbitMQ Exchange│
└────────▲────────┘
│
▼
┌─────────────────┐
│ Express API │
└───────┬─────────┘
│
▼
┌─────────────────┐
│ PostgreSQL │
└─────────────────┘
RabbitMQ is used between the API layer and the notification layer to decouple order processing from client notifications.
Instead of directly pushing updates to connected clients, database changes are first published as events to RabbitMQ. Consumers process these events and broadcast them using Socket.IO.
This architecture provides:
- Scalability
- Reliability
- Maintainability
- Separation of concerns
Producers and consumers can be scaled independently without affecting the client-facing layer.
- RabbitMQ decouples database operations from client notifications.
- Multiple consumers can be added to process events in parallel.
- Socket.IO servers can be horizontally scaled using adapters such as Redis.
- Event-driven communication avoids expensive client polling.
- Producers and consumers can evolve independently without affecting each other.
For larger deployments, Change Data Capture (CDC) solutions such as Debezium can be integrated to capture database changes regardless of the source of the update.
This implementation publishes events from the application layer after successful database writes.
As a result, changes made directly in the database outside the application will not generate notifications.
In a production environment, this limitation can be addressed using Change Data Capture (CDC) tools such as Debezium or database-native event streaming mechanisms.
- Real-time order updates
- Event-driven architecture
- RabbitMQ message queue integration
- PostgreSQL persistence
- Socket.IO client notifications
- Browser-based monitoring dashboard
- Dockerized RabbitMQ setup
- Support for CREATE, UPDATE, and DELETE order events
- Change Data Capture (CDC) using Debezium
- Authentication and authorization
- Redis adapter for Socket.IO clustering
- Retry mechanisms and dead-letter queues
- Event persistence and replay support
Hardyansh Sharma Backend Engineer ( IIIT RANCHI )

