Building a Scalable Go-Based Instant Messaging System: Architecture & Deployment Guide
Learn how to build a pure Go instant messaging platform with a three‑layer, distributed architecture—comet, logic, and job—featuring RPC communication, Redis‑based message pushing, and cluster support, plus step‑by‑step deployment instructions, required packages, and future enhancement plans.
This article introduces a simple Go‑based instant messaging (IM) system.
Overview
The IM system is implemented entirely in Go, with three independent layers that communicate via RPC, support clustering, and are available on GitHub at github.com/Terry-Ye/im_api . It draws inspiration from goim.
Comet (user connection layer) – multiple nodes can be deployed, each with a unique serverId defined in comet.toml.
Logic (business logic layer) – stateless, communicates with other layers via RPC, and offers an HTTP interface for receiving messages.
Job (task push layer) – uses Redis pub/sub to push messages to the Comet layer.
System Architecture Diagram
Sequence Diagram
The Comet, Logic, and Job layers can each be scaled horizontally.
Features
Distributed, topology‑aware architecture.
Supports both single‑user and room‑based push.
Heartbeat support (built into gorilla/websocket).
Message pushing based on Redis.
Lightweight.
Continuous iteration.
Deployment
Installation:
go get -u github.com/Terry-Ye/im
mv $GOPATH/src/github.com/Terry-Ye/im $GOPATH/src/im
cd $GOPATH/src/im
go get ./...If golang.org/x/net/ipv4 cannot be fetched, clone it manually:
package golang.org/x/net/ipv4: unrecognized import path "golang.org/x/net/ipv4" (https fetch: Get https://golang.org/x/net/ipv4?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)Clone and move the repository:
git clone https://github.com/golang/net.git
mkdir -p golang.org/x/
mv net $GOPATH/src/golang.org/x/Deploy the IM system:
cd $GOPATH/src/im/comet
go install
cd ../logic/
go install
cd ../job
go install
nohup $GOPATH/bin/logic -d $GOPATH/src/im/logic/ 2>&1 > /data/log/im/logic.log &
nohup $GOPATH/bin/comet -d $GOPATH/src/im/comet/ 2>&1 > /data/log/im/comet.log &
nohup $GOPATH/bin/job -d $GOPATH/src/im/job/ 2>&1 > /data/log/im/job.log &The im_api interface requires the full deployment to run the demo.
Deployment Considerations
Ensure firewall ports required by each layer are open on the server.
Demo
Chatroom URL: http://www.texixi.com:1999/
Used Packages
log: github.com/sirupsen/logrus rpc: github.com/smallnest/rpcx websocket: github.com/gorilla/websocket configuration:
github.com/spf13/viperFuture Plans
Online user list.
Support for WSS (secure WebSocket).
Chatbot integration.
Original source: www.ancii.com/awugjp68e/
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
