https://github.com/likhithkp/realtime-notifications-service
A real-time notification service using Go, Kafka, PostgreSQL, Redis, and WebSockets. It stores notifications in PostgreSQL, caches unread IDs in Redis, and delivers notifications instantly via WebSockets if the user is live.
https://github.com/likhithkp/realtime-notifications-service
go golang kafka notification-service notification-system postgresql real-time-notification redis websocket
Last synced: about 2 months ago
JSON representation
A real-time notification service using Go, Kafka, PostgreSQL, Redis, and WebSockets. It stores notifications in PostgreSQL, caches unread IDs in Redis, and delivers notifications instantly via WebSockets if the user is live.
- Host: GitHub
- URL: https://github.com/likhithkp/realtime-notifications-service
- Owner: likhithkp
- Created: 2025-02-24T10:14:35.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-26T05:17:08.000Z (over 1 year ago)
- Last Synced: 2025-10-07T14:00:46.360Z (8 months ago)
- Topics: go, golang, kafka, notification-service, notification-system, postgresql, real-time-notification, redis, websocket
- Language: Go
- Homepage:
- Size: 22.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Real-Time Notification System
## Overview
A real-time notification system built using Kafka, Redis, PostgreSQL, and WebSockets. This backend service ensures instant event-driven notifications with efficient storage and retrieval.
## Features
- **Kafka Producer & Consumer**: Events are produced and consumed asynchronously.
- **PostgreSQL Storage**: Notifications are stored for persistence.
- **Redis Caching**: Unread notifications are cached for quick access.
- **WebSockets**: Real-time push notifications to users.
- **REST API**: Fetch notifications via user ID.
## Tech Stack
- **Go**: Backend service.
- **Kafka**: Message broker for event-driven processing.
- **PostgreSQL**: Persistent storage.
- **Redis**: Fast in-memory cache.
- **WebSockets**: Real-time communication.
## Architecture Flow
1️⃣ **Notification Event Ingestion**
- The API receives notification data and **publishes it to Kafka** for reliable message handling.
2️⃣ **Event Processing & Storage**
- A Kafka Consumer **processes the event**, storing full notification details in **PostgreSQL**.
- The notification **ID is cached in Redis** for quick access to unread notifications.
3️⃣ **Fetching Notifications**
- When users fetch notifications, the API retrieves **IDs from Redis** first (low-latency response).
- If needed, full details are fetched from **PostgreSQL**.
4️⃣ **Real-time Notification Delivery**
- WebSockets **push real-time notifications** to actively connected clients.
- If a user **views a notification live**, it is marked as **read** immediately in Redis and PostgreSQL.
5️⃣ **Manual Read Acknowledgment**
- Users can manually mark notifications as **read** via an API.
- The system **removes the notification from Redis** and updates PostgreSQL.
## Installation
1. Clone the repo:
```sh
git clone https://github.com/likhithkp/realtime-notifications-service.git
```
2. Set up Kafka, Redis, and PostgreSQL.
3. Configure `.env` with necessary environment variables.
4. Run the service:
```sh
go run main.go
```
## API Endpoints
- `POST /createUser` - Create a user first.
- `POST /createNotification` - Publish a notification.
- `GET /notifications/{user_id}` - Fetch notifications for a user.
- `GET /ws/{user_id}` - Listen to live notifications.
## License
MIT License.