OpenChat: Real-Time, Scalable, and Self-Hosted Chat Solution

OpenChat is a real-time, self-hosted chat server that allows users to create scalable, anonymous chat rooms with robust spam prevention. It supports both public and local networks, ensuring privacy and high performance, even during internet outages.

AZRAF AL MONZIM
go
websockets
real-time
scalability
redis
docker

I AM WORKING ON THIS ARTICLE. PLEASE CHECK BACK LATER FOR THE FULL WRITE-UP.

Visit: https://openchat.monzim.com


OpenChat is a real-time, self-hosted chat server that allows users to create anonymous, scalable chat rooms. It was born out of necessity during the July protests, when internet shutdowns made communication difficult. I envisioned OpenChat as a reliable, easy-to-set-up chat server that could operate both on public internet and local networks, ensuring communication channels remain openβ€”even in the face of restrictions.

The Inspiration Behind OpenChat

During the july protests 24 (also known as the quota movement), some chat servers hosted on BDIX (Bangladesh Internet Exchange) allowed people to communicate without the public internet. However, many of these servers suffered from issues like spamming and frequent downtime, leaving people frustrated. This made me realize the need for a more reliable, scalable, and spam-resistant solution that could handle high traffic and maintain privacy.

Core Objectives

My primary goals while building OpenChat were:

  • Easy Setup: A straightforward, self-hosted solution with minimal configuration.
  • Versatile Usage: Capable of running on both public and local networks, making it independent of internet availability.
  • Real-Time Communication: Seamless messaging with minimal latency.
  • Scalability: Support for a large number of concurrent users across multiple server instances.
  • Robust Spam Prevention: Implemented measures to combat spamming and abuse.
  • Anonymous Chat Rooms: Allow users to create and participate in rooms without tracking their identities.
  • Private Rooms: Secure rooms with password protection for sensitive conversations.

Tech Stack

For simplicity and scalability, I chose the following technologies:

  • Go: Known for its performance, low memory consumption, and compact binary sizes, making it perfect for building real-time applications that need to scale.
  • Redis: Used for message storage, pub/sub, and WebSocket scalability. Redis ensures the system can scale horizontally, allowing multiple instances of the server to handle more traffic efficiently.
  • Docker: For ease of deployment and portability across different environments.
  • Frontend: I used Remix.run for the front-end framework, and shadcn UI for styling, ensuring a modern and responsive user experience.