How satvikg7/scalable-notification-system works
1. This repository is a Go-based notification service with two main runtime paths: an HTTP API for managing users/notifications, and a RabbitMQ-backed async processing path for delivering notifications.
2. main.go is the composition root. It likely loads configuration, initializes the database connection, starts the HTTP server, and wires up RabbitMQ producers/consumers and any scheduler logic. config/env.go centralizes environment-variable loading from .env.
3. The HTTP boundary lives under internal/server and internal/handlers. The README indicates the server is built with Fiber, so external clients talk to a Fiber HTTP API. The handlers are split by responsibility:
- internal/handlers/users/* for CRUD-style user endpoints
- internal/handlers/notification.go for notification-related API actions
4. The user subsystem is isolated as a small application slice. createUser.go, getUser.go, getUsers.go, and deleteUser.go suggest separate endpoint handlers rather than a single large controller. internal/utils/getUser.go likely provides shared lookup/validation logic used by multiple handlers.
5. The domain layer is modeled explicitly in internal/models:
- user.go
- preference.go
- message.go
- notification.go
These structs are the shared data contracts between HTTP handlers, persistence, and queue payloads.
6. Persistence is separated into internal/db/db.go plus schema.sql. This strongly suggests a relational database, and the README mentions PostgreSQL for logging failed notifications. The schema file is the authoritative source for tables and relationships, while the db package owns connection setup and query access.
7. RabbitMQ is the asynchronous backbone. internal/rabbitmq/producer.go publishes notification work, consumer.go processes jobs from queues, config.go holds broker configuration, and scheduler.go coordinates queue/worker behavior. This is the main decoupling point between request intake and notification delivery.
8. The notification workflow is therefore split into ingestion and execution:
- API receives a request and validates it
- a notification/message model is created
- the producer routes it to RabbitMQ, likely by channel and priority
- consumers pull work and perform delivery
- failures are retried or persisted for later inspection
9. The README describes queue prioritization, rate limiting, and dynamic worker reallocation. Architecturally, that means the RabbitMQ layer is not just a simple queue consumer; it also includes scheduling/coordination logic to protect external delivery services and keep high-priority messages moving.
10. Failed delivery handling is a separate concern from the request path. The service logs unsuccessful notifications to PostgreSQL, which makes the database both a source of user/preference data and an audit trail for delivery failures.
11. schema.sql and the models package together define the data contracts for both synchronous API operations and asynchronous message processing. That makes the models a shared boundary between HTTP, queue workers, and persistence.
12. In diagram terms, the cleanest boundaries are:
- Client/API layer: Fiber server + handlers
- Core domain/data: models + utils
- Persistence: db package + PostgreSQL schema
- Async messaging: RabbitMQ producer/consumer/scheduler
- Bootstrap/config: main.go + env config
13. The main external dependencies that materially shape the architecture are Go, Fiber, RabbitMQ, and PostgreSQL. The repo is organized as a classic layered service with an async broker in the middle to scale notification throughput and isolate delivery work from request handling.
Main entry points: handlers Handlers · models Models · db.go DB · main.go main.go
Components 17
Bootstrap
Process startup and configuration
- main.go · Wires configuration, HTTP server, database, and messaging together
main.go - Env config · Loads environment variables and runtime settings
config/env.go
HTTP API
Fiber server and request handlers
- Server · HTTP server setup and route registration
internal/server/server.go - Handlers · HTTP entrypoints for users and notifications
internal/handlers - Create user · Creates a new user record via HTTP
internal/handlers/users/createUser.go - Get user · Fetches a single user via HTTP
internal/handlers/users/getUser.go - List users · Returns user collections via HTTP
internal/handlers/users/getUsers.go - Delete user · Removes a user via HTTP
internal/handlers/users/deleteUser.go - Notification API · HTTP actions related to notification submission or control
internal/handlers/notification.go
Domain
Shared data models and helpers
- Models · Shared structs for users, preferences, messages, and notifications
internal/models - Lookup utils · Shared user lookup and validation logic
internal/utils/getUser.go
Persistence
Database connection and schema
Async messaging
RabbitMQ delivery pipeline
- Broker config · RabbitMQ connection and topology settings
internal/rabbitmq/config.go - Producer · Publishes notification work onto RabbitMQ
internal/rabbitmq/producer.go - Consumer · Consumes queued notifications and performs delivery work
internal/rabbitmq/consumer.go - Scheduler · Coordinates prioritization, rate limiting, and worker allocation
internal/rabbitmq/scheduler.go
Connections 24
- main.go → Env config: loads · Reads runtime configuration at startup
- main.go → Server: starts · Bootstraps the HTTP service
- main.go → DB: opens · Initializes database connectivity
- main.go → Broker config: configures · Sets up RabbitMQ connectivity
- main.go → Scheduler: wires · Starts async coordination logic
- Server → Handlers: routes to · Connects HTTP routes to handlers
- Handlers → Create user: includes · User creation endpoint
- Handlers → Get user: includes · Single-user retrieval endpoint
- Handlers → List users: includes · User listing endpoint
- Handlers → Delete user: includes · User deletion endpoint
- Handlers → Notification API: includes · Notification-related HTTP actions
- Create user → Models: uses · Builds and validates user domain objects
- Get user → Lookup utils: uses · Shares lookup logic
- List users → DB: queries · Reads users from persistence
- Delete user → DB: mutates · Deletes users in persistence
- Notification API → Models: creates · Creates notification/message payloads
- Notification API → Producer: publishes · Enqueues notification work
- Producer → Scheduler: coordinates with · Respects prioritization and dispatch rules
- Consumer → DB: logs failures · Persists unsuccessful deliveries
- Consumer → Models: deserializes · Consumes shared message and notification structures
- DB → Schema: implements · Backed by the SQL schema
- Models → DB: shared by · Domain structs are stored and queried in persistence
- Models → Producer: shared by · Payloads are published to the queue
- Models → Consumer: shared by · Payloads are consumed from the queue