How akshay931/distri_notification_and_alert_system works
Purpose and Entry Point
A Node.js/Express distributed notification backend for ingesting, processing, scheduling, and delivering Email, SMS, and Push alerts. The application entry point is src/server.js, exposing /notify for notification submission and /analytics for delivery metrics.
Runtime and Deployment Boundary
The system uses Node.js with Express, Kafka for asynchronous service decoupling, MongoDB through Mongoose for persistent state, and node-schedule for deferred work. Container orchestration is defined by Dockerfile and docker-compose.yml; Kafka and MongoDB are material infrastructure dependencies.
Ingestion Stage
services/notificationIngestion.js receives and validates notification requests from the API layer before publishing accepted work to the Kafka notifications topic. This isolates synchronous client handling from downstream processing and delivery latency.
Processing and Scheduling Engine
services/notificationProcessing.js consumes notification work, classifies urgent/high-priority versus deferred messages, and applies delivery eligibility rules. Scheduled notifications are persisted and revisited through the scheduling runtime rather than delivered directly.
Core policy queries are separated from orchestration:
• queries/throttling.js
• queries/quietHours.js
• queries/deduplication.js
• queries/aggregation.js
• queries/urgentAlerts.js
These rules determine whether a notification is immediately delivered, suppressed, combined, or rescheduled.
Persistent Domain Model
MongoDB documents define the key state boundary:
• models/notification.js stores notification lifecycle data, scheduling, delivery status, retries, and likely audit information.
• models/user.js holds recipient preferences such as channel choices, quiet hours, and rate limits.
Processing reads user policy and notification history from this persistence layer to make rule-driven decisions.
Delivery and Reliability
services/notificationDelivery.js performs channel delivery through mock Email/SMS/Push integrations. It records delivery outcomes in MongoDB and retries failed attempts, separating transport-specific failure handling from policy evaluation in the processor.
The intended flow is: API request → Kafka publication → processing/rules → immediate or scheduled delivery → persisted status and retry updates.
Analytics Surface
services/analytics.js aggregates persisted notification and delivery records for the /analytics API. Analytics is a read-oriented boundary for delivery success, retries, and engagement/operational metrics, rather than part of the delivery critical path.
Main entry points: notificationProcessing.js Notification processing · docker-compose.yml Container deployment · notification.js Notification records · notificationDelivery.js Notification delivery
Components 20
API Surface
- Express server · Exposes notification submission and analytics endpoints.
src/server.js - /notify
src/server.js - /analytics
src/server.js
Notification Services
- Notification ingestion · Validates accepted notification requests before asynchronous publication.
services/notificationIngestion.js - Notification processing · Classifies work and selects immediate, suppressed, combined, or deferred handling.
services/notificationProcessing.js - Notification delivery · Delivers Email, SMS, and Push messages and handles failed-attempt retries.
services/notificationDelivery.js - Analytics service · Reads delivery records for success, retry, and operational metrics.
services/analytics.js
Policy Rules
- Throttling
queries/throttling.js - Quiet hours
queries/quietHours.js - Deduplication
queries/deduplication.js - Aggregation
queries/aggregation.js - Urgent alerts
queries/urgentAlerts.js
Runtime Infrastructure
- Kafka notifications · The notifications topic decouples submission from processing.
- Scheduling runtime · Revisits persisted deferred notifications when eligible.
- Email / SMS / Push
- Notification records · Stores lifecycle, schedule, status, and retry state.
models/notification.js - User preferences · Stores channel preferences, quiet hours, and rate limits.
models/user.js - MongoDB
- Container deployment · Defines the application, Kafka, and MongoDB runtime boundary.
docker-compose.yml - Application image
Dockerfile
Connections 25
- Express server → /notify: routes
- Express server → /analytics: routes
- /notify → Notification ingestion: submits
- Notification ingestion → Kafka notifications: publishes accepted work
- Kafka notifications → Notification processing: consumes
- Notification processing → Throttling: evaluates
- Notification processing → Quiet hours: evaluates
- Notification processing → Deduplication: evaluates
- Notification processing → Aggregation: evaluates
- Notification processing → Urgent alerts: classifies
- Notification processing → User preferences: reads preferences
- Notification processing → Notification records: reads and updates state
- Notification processing → Notification delivery: immediate delivery
- Notification processing → Scheduling runtime: defers eligible work
- Scheduling runtime → Notification processing: revisits scheduled work
- Notification delivery → Email / SMS / Push: sends via
- Notification delivery → Notification records: records outcomes and retries
- Notification records → MongoDB: persists
- User preferences → MongoDB: persists
- /analytics → Analytics service: queries
- Analytics service → Notification records: aggregates records
- Application image → Container deployment: builds application image
- Container deployment → Express server: runs
- Container deployment → Kafka notifications: orchestrates
- Container deployment → MongoDB: orchestrates