Skip to content

πŸ’¬πŸš€ Scalable real-time chat app with WebSockets and Redis, featuring horizontal scaling and live connection tracking.

License

Notifications You must be signed in to change notification settings

mutasim77/fast-redis-chat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

19 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Banner

Real-time Scalable Messaging πŸš€

🌟 Introduction

FastChat is a high-performance, real-time chat application that demonstrates the power of WebSockets and Redis for scalable messaging. Built with modern web technologies, it offers a seamless chatting experience that can easily scale to handle a large number of concurrent users.

🎯 Features

  • βœ‰οΈ Real-time messaging using WebSockets
  • πŸ‘₯ Live user connection count across multiple instances using Redis Pub/Sub
  • πŸš€ Horizontally scalable architecture with multiple backend instances
  • βš–οΈ Load balancing with Caddy as a reverse proxy
  • πŸ–₯️ Sleek, responsive UI built with Next.js and Tailwind CSS
  • 🐳 Dockerized for easy deployment and scaling

πŸ› οΈ Tech Stack

Backend πŸ–₯️

  • ⚑ Fastify: Fast and low overhead web framework
  • πŸ”Œ Socket.io: Real-time bidirectional event-based communication
  • πŸ—„οΈ Redis (Upstash): In-memory data structure store, used as a database, cache, and message broker
  • 🐳 Docker & docker-compose: Containerization and multi-container Docker applications
  • 🌐 Caddy: Open source web server with automatic HTTPS

Frontend 🎨

  • βš›οΈ Next.js: React framework for production-grade applications
  • 🎭 Tailwind CSS: Utility-first CSS framework
  • πŸ”— Socket.io-client: Client-side library for real-time web applications

πŸš€ Getting Started

Prerequisites

  • Node.js (v18 or later)
  • pnpm || yarn || npm
  • Docker and docker-compose
  • Redis instance (Upstash account)
  • Make (usually pre-installed on most systems)

Installation

  1. Clone the repository:

    git clone https://github.com/mutasim77/fast-redis-chat.git
    cd fast-redis-chat
  2. Set up environment variables:

  • Create a .env file in the server directory with:

    UPSTASH_REDIS_REST_URL=rediss://.....

    Replace ... with your actual Upstash Redis URL.

  • Create a run.sh file in the server directory and populate it with:

    docker-compose down
    
    export UPSTASH_REDIS_REST_URL=rediss://...
    export CORS_ORIGIN=http://localhost:3000  # or your specific CORS origin
    
    docker-compose -p chat_project up -d --build

    Replace ... in the UPSTASH_REDIS_REST_URL with your actual Upstash Redis URL.

  • Make sure to make the run.sh file executable by running:

    chmod +x run.sh
  1. Use the Makefile to install dependencies and run the application:
# Install dependencies for both client and server
make install

# Run both the backend and frontend
make run

# Or simply just run
make all

This will start the backend server using the run.sh script and the frontend development server.

πŸ’» Usage

Once you've run make run or make all:

  1. Open your browser and navigate to http://localhost:3000
  2. Click Start Chatting
  3. Start sending messages in real-time!

To stop the application, press Ctrl+C in the terminal where you ran make run. To clean up the project (remove node_modules, etc.), you can run:

make clean  

πŸ“Έ Preview

Home Page Chat SS

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“œ License

This project is licensed under the MIT License - see the LICENSE file for details.

Made with ❀️ by Mutasim

About

πŸ’¬πŸš€ Scalable real-time chat app with WebSockets and Redis, featuring horizontal scaling and live connection tracking.

Topics

Resources

License

Stars

Watchers

Forks