Giter VIP home page Giter VIP logo

go-random-chat's Introduction

Go Random Chat

GitHub tag (latest SemVer) CI status api

Modern real-time chat platform in scalable architecture, written in go.

Kafka is used for message Pub/Sub. Checkout this branch for the Redis Pub/Sub version.

Overview

System architecture

image

Features

  • Real-time communication and efficient websocket handling using Melody.
  • Microservices architecture. All services are stateless and can be horizontally scaled on demand.
    • web: frontend server
    • user: user account server
    • match: user matching server
    • chat: messaging server
    • forwarder: message forwarding server that maps message receivers to specific chat servers
    • uploader: file uploader
  • Use gRPC for inter-service communication
    • with retry, timeout, and circuit breaker
  • Use cobra and viper for CLI and configuration management respectively.
  • Dependency injection using wire.
  • Graceful shutdown.
  • Observability using Golang Prometheus client for monitoring and opentelemetry-go for tracing.
  • At-least-once delivery for message Pub/Sub using Kafka.
  • Persist messages and chat channel metadata in Cassandra, an open source NoSQL distributed database for scalability and high availability.
  • Automatically generate RESTful API documentation with Swagger 2.0.
  • User login session management using http-only cookie.
  • Support Google OAuth2 login.
  • User matching with idempotency.
  • Chat channel authentication using JWT.
  • S3-compatible object storage for uploaded files.
  • Channel-level file access control using S3 presigned URLs.
  • Support uploading images from clipboard.
  • Use Traefik FowardAuth for file upload authentication.
  • Protect file upload api with distributed rate limiting (token bucket algorithm).
  • Message seen feature.
  • Auto-scroll to the first unseen message.
  • Persist chat history on browser close or page refresh.
  • Automatic websocket reconnection.
  • Responsive web design.

Screenshots

Getting Started

Prerequisite:

  • Docker-Compose v2
  • Root permission

First, create OAuth client ID credentials and replace USER_OAUTH_GOOGLE_CLIENTID and USER_OAUTH_GOOGLE_CLIENTSECRET with your credentials in run.sh.

Example setting:

To run locally, execute the following command:

cd deployments
sudo ./run.sh add-host
./run.sh start

run.sh add-host needs root permission to alias minio to localhost in /etc/hosts.

Check cassandra connection:

docker exec deployments-cassandra-1 bash -c "cat /opt/bitnami/cassandra/logs/cassandra.log"
docker exec deployments-cassandra-1 bash -c "cqlsh -u ming -p cassandrapass"

This will spin up all services declared in docker-compose.yaml. Visit http://localhost and you will see the application home page.

Bucket myfilebucket will be created automatically on minio by createbucket. However, if minio is still initializing after 5 retries of createbucket, the bucket creation will fail. If this happens, please run the following command once minio is up and running:

docker restart deployments-createbucket-1
  • Visit http://localhost for the application home page.
  • Visit http://localhost:8080 for Traefik dashboard.
  • VIsit http://localhost:9001 for Minio dashboard.
  • Visit http://localhost:9090 for Prometheus dashboard.
  • Visit http://localhost:16686 for Jaeger dashboard.
  • Visit http://localhost/api/<svc>/swagger/index.html for API documentation, where <svc> could be user, match, chat, or uploader.

Example configuration: config.example.yaml.

Deploy with SSL

A common scenario is that one deploys the application behind a reverse proxy with SSL termination. If that is your case, remember to correctly configure your proxy for websocket. For example, in Google Cloud Platform, for websocket traffic sent through a Google Cloud external HTTP(S) load balancer, the backend service timeout is interpreted as the maximum amount of time that a WebSocket connection can remain open, whether idle or not. Therefore, you may want to use a timeoutSec value larger than the default 30 seconds in your BackendConfig.

Docker Tagging Rules

Event Ref Docker Tags
pull_request refs/pull/2/merge pr-2
push refs/heads/master master
push refs/heads/releases/v1 releases-v1
push tag refs/tags/v1.2.3 v1.2.3, latest
push tag refs/tags/v2.0.8-beta.67 v2.0.8-beta.67, latest

go-random-chat's People

Contributors

dependabot[bot] avatar minghsu0107 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

go-random-chat's Issues

error getting credentials - err: exit status 1, out: ``

I took a look at your source code and it's exactly what I was looking for.
However, it is difficult to implement it yourself.
I got some errors while deploying. Can you help?
error getting credentials - err: exit status 1, out: ``

Minimum Requirements/ Stress Test etc.

Hi again :)

I was wondering if you had the chance and time to perform some stress tests to determine the "minimum requirements" in different situations like: 1 000 / 10 000 / 100 000 concurrent connections, 1M/10M messages retention etc.? Wonderful job anyway, that's impressive ๐Ÿ‘๐Ÿฝ

Quick question: What's the role of Kafka here (I'm not familiar with it)

Purpose of forwarder component

What's the benefit of having the forwarder? It seems like if the chat components subscribe to the rc.msg.pub topic the forwarder becomes redundant. Is it to prevent unnecessary messages from being sent if there are lots of chat servers in the cluster? Is there a trade-off from the extra computation needed for running the forwarder vs publishing messages to all chat servers based on the number of chat servers we have? Really appreciate you sharing this project.

Is it possible to match the user manually?

Hi minghsu, thanks for doing this project, it's amazing.

As far as I know, your code is only able to match a user with another user randomly. I think it would be great if you can choose manually with whom you want to chat. So, the user (or an admin) can see a list of online users and assign the users to a room manually. What do you think?

Kubernetes Manifest Files

Hi,

Thanks! This is a really helpful chat service. I want to deploy this service on a kubernetes cluster, so I am looking for Kubernetes manifest files for each of the microservices (if you had implemented any). If not, can you point me to how can I start writing them on my own?

I tried to use kompose to convert the docker-compose.yaml file to kubernetes manifest files for each service but that gives several errors such as ImagePullBackOff, CrashLoopBackOff etc.

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.