Distributed Message Fan-Out System
Horizontally Scalable Real-Time WebSocket Infrastructure
Highlights
- Sustained 500 concurrent connections at 500 messages/sec
- Message drop rate reduced from 21% to 2% by eliminating broadcast lock contention
- Cut database queries by ~90% by replacing polling with Redis Pub/Sub
System Overview
A horizontally scalable real-time messaging system in Go. Clients connect over WebSockets to stateless application nodes with Redis Pub/Sub coordinating cross-server broadcasts and PostgreSQL providing persistent message history.
The Problem & Architectural Rationale
Single-server WebSocket architectures cannot scale horizontally. Synchronously iterating over client connection lists under mutex locks during high-frequency broadcasts causes message drops and latency spikes.
Architecture & Components
1. Stateless Gateway Nodes
Go instances handle WebSocket connections, JWT authentication, and local socket delivery.
2. Redis Pub/Sub Message Bus
Synchronizes room broadcasts across all running server instances with fire-and-forget message fan-out.
3. Snapshot-Based Broadcast Engine
Eliminated client list lock contention during broadcast loops by cloning immutable client snapshots, dropping broadcast message loss from 21% to 2%.
Outcomes & Results
- Stress-tested with 500 concurrent connections sustaining 500 msg/sec with sub-5ms broadcast propagation.