Realtime Distributed Chat Save

High throughput 🚀 Low latency | Fullstack Realtime messaging platform built using Go and React ❤️ Original LinkedIn post: https://shorturl.at/aeOPQ

Project README

Real-time Distributed Chat

This repo contains the frontend (React.js), backend (Go-Fiber) and Infrastructure (Terraform, CI/CD) code for building a distributed, real-time, scalable messaging platform. If you are a developer seeking to learn system design or even looking to find how end-to-end projects are build, I hope you find this useful ❤️


I will be writing articles on multiple features about the project like Configuring nginx as a reverse proxy for loadbalancing, TLS/SSL certificate for HTTPS communication, Setting up infrastructure using Terraform etc. So do follow me on HashNode (https://joyalajohney.hashnode.dev/). if you like the repo, please consider giving it a ⭐!

. landing page


React Badge * Nginx Badge * Golang Badge * Redis Badge * Postgres Badge * Kafka Badge * Terraform Badge * Docker Badge

Architecture Diagram 🌠

landing page

Product Demo 🚀

https://github.com/JoyalAJohney/Realtime-Distributed-Chat/assets/31545426/db55bf32-1e35-4071-a80e-9f4944614e71

About the Project 🌌

  • Multiple Go-fiber servers providing API endpoints (JWT authentication) and WebSocket connections for full-duplex communication. These Go instances are configured under Nginx (reverse proxy) Which act a layer 7 loadbalancer.

  • To propagate messages for users within the same room but connected to multiple instances, we utilize Redis (Pub/Sub model). Each instance is subscribed to a particular channel in Redis and gets notified on receiving messages. All messages are stored in Postgres.

  • The database can undergo a heavy write load if we receive 100 messages/sec. To avoid this, we use kafka, a message stream designed for high throughput and low latency processing. A consumer (Go instance) will consume messages from kafka in batches and writes them to postgres.

  • The frontend for application is build using React.js and served in an Nginx container. All the nodes are containarized using Docker and Configured using Docker-Compose. We only expose the Reverse-Proxy (Nginx) to the outside world. Al requests are redirected from there.

  • Next step is to deploy the application on AWS. A CI/CD pipeline is implemented using github actions. We use Terraform for setting up Infrastructure on AWS, configuring an EC2 instance, S3 storage, Security groups and Elastic IP. This is ntegrated into the CI/CD pipeline.

  • For secure HTTPS access, Issue certificate and configure it in Nginx for secure TLS/SSL communication.

Setting Up 🔧

  • Create a .env file from the env.sample file.
  • Fill in the values based on your required configuration.
  • Make sure that the .env file is in the same level as docker-compose.yml file
# Redis Config
REDIS_PORT=6379
REDIS_HOST=redis

# Database Config
POSTGRES_DATABASE=chat_db
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_HOST=postgres
POSTGRES_PORT=5432

# Kafka config
KAFKA_HOST=kafka
KAFKA_PORT=9092
KAFKA_TOPIC=chat_messages
KAFKA_GROUP_ID=chat_group
ZOOKEEPER_PORT=2181

# Authentication
JWT_SECRET=secret

# Reverse proxy config
NGINX_ENV=local
NGINX_PORT=8080
NGINX_HOST=localhost

# LLM config
LLM_PORT=11434

# Backend Servers
SERVER_PORT=8080

I have only shared the template code for Infrastructre (pipeline & terraform). You need to configure the AWS credentials, Terraform, and Pipeline according to your requirements. Additionally, you'll have to set up TLS/SSL for HTTPS (since all of this information is sensitive, it has been omitted)

Running the app

if you wish to run llm model, uncomment the changes from docker-compose (llama 2 model requires almost 3.6GB size)

Execute the below command to build the application containers

$ docker-compose up --build

If the application starts perfectly fine, you should be able to head over to http://localhost:8080/

Open Source Agenda is not affiliated with "Realtime Distributed Chat" Project. README Source: JoyalAJohney/Realtime-Distributed-Chat
Stars
152
Open Issues
0
Last Commit
2 months ago

Open Source Agenda Badge

Open Source Agenda Rating