Reliable WebSocket Messaging and Scaling
Build WebSocket and Socket.IO systems with authorized rooms, reconnect recovery, bounded queues, and multi-node presence.
Before & after
Same prompt, same agent — the only difference is the skill.
Real-time communication is definitely possible with WebSockets. You'll need to set up a server that can handle persistent connections, then build a client-side handler for incoming messages. You might want to consider Socket.IO on top of WebSockets for some convenience features like automatic reconnection. Scaling real-time systems can get complex though, especially if you need multiple server instances. There are various approaches to handling presence and rooms, so it depends on your architecture.
REAL-TIME CHAT ARCHITECTURE
CORE SETUP:
→ Socket.IO (WebSocket abstraction with fallback to polling)
→ Redis adapter for multi-server horizontal scaling
→ Namespace pattern: /chat for chat logic
BIDIRECTIONAL MESSAGING:
1. Client emits: socket.emit('message', {text, timestamp})
2. Server broadcasts: socket.to(roomId).emit('message', payload)
3. Client listens: socket.on('message', handleIncomingMessage)
4. Acknowledge delivery: server responds with ACK callback
PRESENCE TRACKING:
• User joins room: socket.join(roomId)
• Emit roster to all clients on join/leave
• Track last-seen timestamp per user
• Graceful cleanup on disconnect
ROOM MANAGEMENT:
→ Create room on demand
→ Store active room list in Redis for persistence
→ Automatic room cleanup after 30 min inactivity
→ Max 500 concurrent users per room (tunable)
SCALING WITH REDIS:
• Adapter = redis.createAdapter(redisClient)
• Messages broadcast across all server instances
• Session storage in Redis (not memory)
• Reconnection handler restores subscriptions
ERROR HANDLING:
→ Reconnection backoff: 1s, 3s, 10s, 30s
→ Message queue (50-msg buffer) during disconnection
→ Server-side timeout after 10min inactivityAbout this skill
Messages disappear after reconnects, users stay online forever, and room broadcasts work until a second server starts. This skill turns those symptoms into concrete protocol, state, and deployment fixes for WebSockets and Socket.IO.
What it does
- Separates disposable updates, such as cursors, from durable messages that need acknowledgments, deduplication, and replay.
- Designs tenant-scoped rooms with authorization on joins and writes, including permission changes during active connections.
- Builds reconnect flows with backoff, replay cursors, snapshot boundaries, and explicit history-expiration behavior.
- Plans Redis fanout, load-balancer routing, and expiring presence leases across multiple server instances.
- Bounds slow-client queues and identifies the measurements and failure tests needed before rollout.
What you get
A scoped implementation, code review, or architecture with message contracts, connection behavior, failure handling, and targeted verification steps. Quick debugging requests receive the smallest useful fix; full builds receive the protocol and deployment decisions needed to implement them.
Best for
Backend and full-stack developers building collaborative editors, chat, live dashboards, multiplayer coordination, or other room-based real-time features.
SKILL.md preview
---
name: reliable-websocket-messaging-and-scaling
description: Design, implement, and debug WebSocket and Socket.IO systems by specifying delivery semantics, authorized rooms, reconnect recovery, bounded queues, and distributed presence before wiring transport and fanout. Use when the user says "build a WebSocket server", "my messages disappear after reconnect", "scale Socket.IO across servers", "users stay online after disconnecting", "room broadcasts only work on one node", "review this real-time implementation", or "slow clients keep crashing my socket server".
---
# Reliable WebSocket Messaging and Scaling
… (sign up to view the full skill)More development skills
View all Development skills →Production Go: Concurrency, Services & Profiling
Production Go code with leak-free goroutines, context-correct services, wrapped errors, and pprof-driven performance fixes.
Backend Feature Build Plan
Builds one backend feature through gates: confirmed requirements, one-screen design, small tested slices, and a deploy/rollback handoff.
Consistent, Safe Application Logging
Adds structured, correlated logs with useful severity, safe fields, bounded volume, and targeted verification.
Laravel App Build: Eloquent, Sanctum, Queues, Livewire
Laravel 12/13 code that ships: N+1-free Eloquent, correct Sanctum mode, idempotent queued jobs, lean Livewire, and Pest tests.