finds.dev

link1st/gowebsocket

golang基于websocket单台机器支持百万连接分布式聊天(IM)系统

View on GitHub

★ 3,097GoNOASSERTIONupdated Mar 2026

// the take

A Go IM demo that wires together gorilla/websocket, Gin, Redis, and gRPC to show how to scale WebSocket connections horizontally. It's aimed at developers who want a working reference for the connection-management patterns you need before you can run a chat system at scale — goroutine-per-connection, heartbeat timeouts, cross-node message delivery via gRPC. Single-binary, runs with just Redis.

The connection lifecycle is handled correctly: separate read/write goroutines per client, mutual shutdown when either fails, and a ticker-based sweep for stale connections — the three things that cause goroutine leaks in naive WebSocket servers. The cross-node routing via gRPC with Redis as a service registry is the right call at this scale; no message broker to operate. Benchmark data is honest: 27 KB per connection, 25 GB for a million, and it shows the Linux kernel tuning you actually need to get there. The router abstraction over raw WebSocket messages (register cmd → handler) is a clean pattern that doesn't get enough attention in tutorials.

No authentication — the README explicitly admits it, and the login handler accepts any userID string. You can't use this as a base for a real product without building that from scratch. Message persistence is absent: if a user is offline when a message is sent, it's gone. The service discovery via Redis is hand-rolled and fragile; no health checks, no TTL refresh, so a crashed node leaves stale entries. The codebase is also effectively a monolith in a single binary — the IM logic and WebSocket gateway are coupled, which contradicts the section that argues for separation.

We read the README, the directory tree and a key source file in June 2026. Nobody pays to be listed. How we judge →

// at a glance

Stars
3,097
Forks
640
Language
Go
License
NOASSERTION
Last commit
23 Mar 2026

// nearby

If gowebsocket isn't quite it.

All repos →