Author: Utsav Moradiya
Last Updated: 2025-06-29 22:02:12
Each user is treated as a shareholder. Their share value fluctuates randomly every few seconds. The updates are:
- Streamed via Kafka and WebSocket/GraphQL Subscriptions
- Displayed in real-time on a dashboard
- Saved to DB via event when user clicks "Save Snapshot"
Frontend (React + Apollo)
│
▼
Gateway Service (Optional)
│
┌───────────────────────┼──────────────────────┐
▼ ▼ ▼
User Service Kafka Broker Notification Service (gRPC)
│ ▲ ▲
▼ │ │
PostgreSQL Topic: user.price.update WebSocket/Email/SMS
- Backend: FastAPI, gRPC, SQLAlchemy (Async)
- Real-time: Kafka, WebSocket, GraphQL Subscriptions
- Frontend: React + Tailwind + Apollo Client
- DB: PostgreSQL, Redis (cache)
- DevOps: Docker, Docker Compose
| Endpoint | Method | Description |
|---|---|---|
/register |
POST | Register user, assign value |
/login |
POST | Login and return JWT |
/me |
GET | Protected route (JWT) |
/save-snapshot |
POST | Fires event to save value |
/graphql |
POST | Query users + subscriptions |
/ws |
WS | WebSocket real-time feed |
- gRPC Server:
SendEmailNotificationSendSMSNotification
- Kafka Consumer:
- Topic:
user.price.update - Broadcast via WebSocket
- Topic:
| Endpoint | Method | Description |
|---|---|---|
/analytics/user/{id} |
GET | Avg change, snapshot history |
- Updates all user share values randomly every 5s
- Sends to Kafka
user.price.update
- ✅ Register new user via
/api/v1/users/register - ✅ Login and get JWT
- ✅ Subscribe to GraphQL via WebSocket (
onUserRegistered) - ✅ View updates in frontend (WebSocket/GraphQL)
- ✅ Save snapshot and verify event stored in DB
- ✅ gRPC call to Notification triggered on event
- ✅ Kafka message logged for all updates
docker-compose up --build- Check ports:
- Kafka:
localhost:9092 - Zookeeper:
localhost:2181 - User Service:
localhost:8001 - Notification Service:
localhost:8002
- Kafka:
user_service/
├── src/
│ ├── api/
│ ├── db/
│ ├── graphql/
│ ├── kafka/
│ ├── grpc/
│ ├── websocket/
│ └── main.py
notification_service/
├── src/
│ ├── grpc/
│ ├── kafka/
│ └── main.py
frontend/
├── src/
│ └── ... (React app)
analytics_service/
├── src/
│ └── ...
- Use
WebSocketClientor GraphQL Playground to test subscriptions - JWT auth is applied to GraphQL context and WebSockets
- Event-driven + loosely coupled microservices = scalable