gitmyhub

goim

Go ★ 7.4k updated 3y ago

goim

goim is a high-performance instant messaging server in Go that pushes messages to millions of connected users at once via WebSocket, TCP, or HTTP long-polling, with a three-layer architecture designed for horizontal scaling.

GoWebSocketTCPHTTPKafkasetup: hardcomplexity 4/5

goim is an instant messaging server written in Go, designed to handle a large number of simultaneous connected users. If you are building a chat app, a live comment feed, or any product where messages need to be pushed to many users at once, this provides the server infrastructure to do it.

The server supports sending a message to a single user, to a list of users, or as a broadcast to everyone connected. Users can also subscribe to a shared key (similar to a chat room), and the server will forward messages to all subscribers of that key. The connection stays alive through heartbeat checks, which prevents the server from holding onto dead connections. Users must authenticate before they can subscribe, so anonymous connections are blocked.

The architecture splits the work across three separate services that run independently. The comet layer manages the actual client connections over WebSocket, TCP, or HTTP long-polling. The logic layer handles the business rules for routing messages. The job layer receives messages from Kafka (a messaging queue) and dispatches them to the right comet nodes. This separation means you can run more instances of any layer to handle more load without changing the others.

The README includes benchmark results from a test with one million connected clients. Running on a single server, the system delivered about 35.9 million received messages per second during broadcast testing, using around 14 GB of memory. That gives a rough sense of what kind of scale the server is built for.

Client SDKs for Android and iOS are available in separate repositories linked from the README. A JavaScript WebSocket example is included in the main repository. The project is MIT licensed.

Where it fits