Skip to content

Latest commit

Β 

History

105 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ’¬ Real-Time Chat App

Distributed Messaging Platform Β· Go Β· Microservices Β· WebSockets

Go Kafka Redis MongoDB Docker License

A production-inspired distributed real-time messaging backend β€” 6 independent Go microservices communicating through WebSockets, Redis Pub/Sub, and Kafka. Built to demonstrate strong system design and backend engineering skills.


✨ Highlights

  • πŸ—οΈ 6 Independent Microservices β€” each fault-isolated with its own DB connection, config, and entry point
  • πŸ“‘ WebSocket Real-Time Delivery β€” persistent bi-directional connections for instant messaging
  • ⚑ Redis Pub/Sub β€” low-latency message fan-out across service instances
  • πŸ“¨ Kafka Event Streaming β€” durable async processing, guaranteed message delivery
  • πŸ’Ύ MongoDB β€” flexible document storage for chats and messages
  • πŸ” JWT Authentication β€” access + refresh token flow across all services
  • 🐳 Fully Dockerized β€” all 6 services + infrastructure via Docker Compose
  • 🧱 Clean Architecture β€” handler β†’ service β†’ repository layering in every service

πŸ—οΈ Architecture

                        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                        β”‚   API Gateway   β”‚
                        β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                 β”‚
          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
          β”‚                      β”‚                      β”‚
   β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”
   β”‚ Auth Serviceβ”‚      β”‚  User Service  β”‚    β”‚  Chat Service  β”‚
   β”‚ JWT tokens  β”‚      β”‚ Profile mgmt   β”‚    β”‚ Groups/1-on-1  β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚  Message    β”‚      β”‚  Notification  β”‚    β”‚   WebSocket    β”‚
   β”‚  Service   β”‚      β”‚    Service     β”‚    β”‚    Service     β”‚
   β”‚ Send/Edit  β”‚      β”‚ Kafka-driven   β”‚    β”‚ Real-time hub  β”‚
   β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
          β”‚                     β”‚                     β”‚
          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β”‚                 β”‚                 β”‚
       β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”
       β”‚   MongoDB   β”‚  β”‚    Kafka     β”‚  β”‚    Redis    β”‚
       β”‚  Messages   β”‚  β”‚   Events     β”‚  β”‚   Pub/Sub   β”‚
       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Message Flow

Client β†’ WebSocket Service β†’ Redis Pub/Sub β†’ Kafka β†’ Message Service β†’ MongoDB β†’ Broadcast

πŸ› οΈ Tech Stack

Layer Technology
Language Go 1.21+
HTTP Framework Fiber
Real-Time WebSockets (gorilla/websocket)
Event Streaming Kafka
Pub/Sub Redis
Database MongoDB
Authentication JWT (access + refresh tokens)
Containerization Docker + Docker Compose

πŸ”§ Services

πŸ” Auth Service

  • User registration and login
  • JWT access token + refresh token issuance
  • Token validation middleware

πŸ‘€ User Service

  • Fetch and update user profile
  • Delete account
  • User search

πŸ’¬ Chat Service

  • Create 1-on-1 chats
  • Create and manage group chats
  • Add/remove group members

πŸ“¨ Message Service

  • Send, receive, edit, delete messages
  • Mark messages as read
  • Message history with pagination

πŸ”” Notification Service

  • Kafka-driven async notification processing
  • User notification delivery
  • Event-based triggers

🌐 WebSocket Service

  • Maintains persistent WebSocket connections
  • Publishes events to Redis Pub/Sub for real-time fan-out
  • Forwards durable message events to Kafka

πŸ“ Project Structure

chat-app/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ api-gateway/              # Request routing
β”‚   └── services/
β”‚       β”œβ”€β”€ auth-service/
β”‚       β”‚   β”œβ”€β”€ cmd/              # Entry point
β”‚       β”‚   β”œβ”€β”€ internal/         # Handler Β· Service Β· Repository
β”‚       β”‚   β”œβ”€β”€ configs/          # Environment config
β”‚       β”‚   └── .env.example
β”‚       β”œβ”€β”€ user-service/
β”‚       β”œβ”€β”€ chat-service/
β”‚       β”œβ”€β”€ message-service/
β”‚       β”œβ”€β”€ notification-service/
β”‚       └── websocket-service/
β”œβ”€β”€ docs/                         # Architecture diagrams
β”œβ”€β”€ postman/                      # API collection
β”œβ”€β”€ docker-compose.yaml           # Full stack orchestration
└── dockerfile

Each service follows Clean Architecture:

cmd/         β†’ entry point, dependency wiring
internal/    β†’ handler β†’ service β†’ repository
configs/     β†’ environment-based config

πŸš€ Getting Started

Prerequisites

  • Go 1.21+
  • Docker & Docker Compose

1. Clone the repo

git clone https://github.com/fathimasithara01/chat-app.git
cd chat-app/backend

2. Configure environment

# For each service
cp services/auth-service/.env.example services/auth-service/.env
cp services/user-service/.env.example services/user-service/.env
# ... repeat for other services

3. Start all services

docker-compose up --build

This starts all 6 microservices + MongoDB + Redis + Kafka together.


πŸ“‘ API Endpoints

Auth Service

Method Path Description
POST /auth/register Register new user
POST /auth/login Login β€” returns JWT pair
POST /auth/refresh Refresh access token
POST /auth/logout Logout

User Service

Method Path Description
GET /users/:id Get user profile
PATCH /users/:id Update profile
DELETE /users/:id Delete account

Chat Service

Method Path Description
POST /chats Create 1-on-1 chat
POST /chats/group Create group chat
PATCH /chats/:id/members Add/remove members
GET /chats List user's chats

Message Service

Method Path Description
POST /messages Send message
GET /messages/:chatId Get message history
PATCH /messages/:id Edit message
DELETE /messages/:id Delete message

WebSocket

ws://localhost:PORT/ws?token=<jwt>

πŸ”‘ Key Design Decisions

Why Redis Pub/Sub + Kafka together? Redis handles low-latency real-time fan-out β€” messages reach online users instantly. Kafka provides durability β€” events are persisted and processed asynchronously even if a service is temporarily down.

Why separate WebSocket service? Isolating WebSocket connections in their own service means connection state is independent of business logic. Other services simply publish to Redis β€” they don't need to know which users are connected.

Why Fiber? Fiber's fasthttp foundation handles high concurrency well β€” important for a chat backend where many connections are open simultaneously.


πŸ“¬ Postman Collection

Import postman/ collection into Postman to test all services. Set base_url per service and use Auth endpoints to get your JWT token automatically.


πŸ‘©β€πŸ’» Author

Fathima Sithara β€” Backend Engineer (Go Β· Distributed Systems)

GitHub Email

Also check out:


⭐ If this project helped you, please give it a star!

About

Real-time messaging platform built with Go, WebSockets, Kafka, Redis, and MongoDB using clean microservices architecture. Supports distributed events, secure authentication, scalable WebSocket delivery, and fault-isolated services. Designed to demonstrate strong backend and system design skills.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages