A scalable real-time chat application built with microservices architecture. Supports instant messaging, presence status, and push notifications.
| Microservice | Responsability | Technologies |
|---|---|---|
| WebSocket Service | To handle real-time connections (WebSocket) | Golang + WebSockets |
| Message Service | Store/retrieve messages | Golang + MongoDB |
| Presence Service | Manage user status (online/offline) | Golanng + Redis |
| Auth Service | Authenticate users and validate tokens | Golang + Postgres + JWT |
| Notification Service | Notify events (e.g. new messages) | RabbitMQ |
| API Gateway | Request routing and management | NGINX |
- Authentication:
- Client sends credentials to Auth Service using HTTP
- The Auth Service returns a JWT for access to other services.
- WebSocket connection:
- API Gateway service validates tokens using Public key (RSA)
- The client establishes a WebSocket connection with the WebSocket Service, including user information in the headers.
- The client sends a message via WebSocket.
- The WebSocket Service publishes the message to a message broker.
- The WebSocket Service consumes the message from the broker and sends it to the users.
- The Message Service consumes the message from the broker and persists it to the database.
- The Notification Service consumes the message from the broker and notifies users.
- When a user connects, the WebSocket Service notifies the Presence Service and updates its status to "online" (e.g. using Redis to store state).
- When disconnecting, the WebSocket Service notifies the Presence Service to update the status to "offline".
- The Notification Service listens to broker events (e.g. new message) and sends push notifications
- Synchronous (HTTP/REST/gRPC):
- Refresh token validation and message history query.
- Asynchronous (Message Broker):
- Message events, status updates and notifications.
- WebSocket:
- Real-time communication between client and server.
TODO
- Adicionar Dead letter queue no rabbitmq para persistir mensagens
