This project is a Node.js microservice designed to send notifications reliably using multiple providers with failover support.
- Provider failover (Primary → Secondary)
- Idempotency using Redis (Duplicate requests are blocked)
- Rate limiting using Redis (10 requests/minute per user)
- Structured logging using Winston
- Health-check endpoint for service and Redis monitoring
- Node.js + Express
- Redis
- BullMQ
- Winston
- TypeScript
Client → API → Middleware → Controller → Service (enqueue jobs) → Queue (BullMQ backed by Redis) → Worker (process jobs) → Primary Provider → Secondary Provider (failover)
npm installdocker run -d -p 6379:6379 redisnpm run start:all{
"userId": "1",
"message": "Hello",
"type": "email"
}202 Accepted– Notification queued successfully
- Provider Handling
{"jobId":"1","level":"info","message":"Sent via secondary provider","service":"notification-service"}- Idempotency
{"key":"notification:2:Hello","level":"warn","message":"Duplicate request blocked","service":"notification-service","userId":"2"}- Rate Limiting
{"level":"warn","message":"Rate limit exceeded","service":"notification-service","userId":"2"}- Health Check
{"level":"info","message":"Health check called","service":"notification-service","uptime":24.1770609}curl -X POST http://localhost:3000/notifications \
-H "Content-Type: application/json" \
-d '{"userId":"1","message":"Hello","type":"email"}'Endpoint: POST http://localhost:3000/notifications
Headers: Content-Type: application/json
Body (JSON): To check Idempotency
{
"userId": "1",
"message": "Hello",
"type": "email"
}Body (JSON): To check Rate Limiting
{
"userId": "1",
"message": "msg{{$randomInt}}",
"type": "email"
}Health-check Endpoint: GET http://localhost:3000/health
- This endpoint verifies that the service is running and that the Redis connection is healthy
Response:
{
"status": "ok",
"uptime": 123.45,
"timestamp": "2026-03-20T10:00:00.000Z"
}- To check Provider Failover
npm test