You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

github.com/mhewedy-playground/golang-redis-websocket-chatserver

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/mhewedy-playground/golang-redis-websocket-chatserver

v0.0.0-20200528135545-af230301480f
Source
Go
Version published
Created
Source

Golang-Redis-WebSocket-ChatServer

Chat service using Redis, Golang and websockets

Design Decisions

  • The chat service allows users to subscribe to multiple channels.
  • Redis client opens a TCP connection per subscription which requires opening too many connections from the chat service to Redis if we open a connection for each channel as user subscribers to. To avoid this, whenever the user subscribes to a new channel, I have to cancel the old subscription and subscribe to all user channels at once. (Redis allow subscribe to multiple channels at once)
  • The chat service registers all connected users in two channels by default “general” and “random” (following slack conventions). The user can subscribe to any arbitrary channel at any time, and only users subscribed to such channels can see the messages.
  • I used WebSockets to handle the communication between the JavaScript client and the Golang Service.
  • The javascript client sends messages in JSON to the Websocket API which uses the following structure {"command": <0, 1 or 2>, "channel": "channel name", "content": "content text"} (will know more later)
  • Users and channels are saved on Redis, so we can horizontally scale the Golang Service without warring about using WebSocket the stateful protocol.
  • The Service provides a couple of REST APIs to get the active users and the channels a particular user subscribed to. (would help if we will build a GUI on top of the service)

FAQs

Package last updated on 28 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts