finds.dev← search

// the find

link1st/gowebsocket

★ 3,097 · Go · NOASSERTION · updated Mar 2026

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

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.

View on GitHub →

// want more like this?

We dig through GitHub every week and send a few repos picked for what you actually care about — each with an honest take like this one.

Get finds in your inbox → Search again →