websocket-hub-patterns
Horizontally-scalable WebSocket hub pattern with lazy Redis subscriptions, connection registry, and graceful shutdown. Use when building real-time WebSocket servers that scale across multiple instances. Triggers on WebSocket hub, WebSocket scaling, connection registry, Redis WebSocket, real-time gateway, horizontal scaling.
Why use this skill?
Learn to build horizontally-scalable WebSocket servers using OpenClaw's hub patterns, featuring lazy Redis subscriptions and connection registries for real-time app scaling.
Install via CLI (Recommended)
clawhub install openclaw/skills/skills/wpank/websocket-hub-patternsWhat This Skill Does
The websocket-hub-patterns skill provides a robust architectural template for implementing horizontally-scalable WebSocket servers using a Go-based hub pattern. It solves the classic problem of WebSocket isolation, where users connected to different server instances cannot communicate directly. By leveraging Redis Pub/Sub, the skill acts as a message broker between instances. A key feature is the 'Lazy Redis Subscription' mechanism, which optimizes resource consumption by only initiating a Redis subscription channel when the first local client subscribes to a specific topic. This prevents the server from overwhelming Redis with thousands of idle connections. The skill also includes a centralized connection registry, enabling developers to track which user is connected to which specific instance, facilitating targeted messaging and graceful handling of server shutdowns.
Installation
To integrate this pattern into your project, use the OpenClaw command-line interface:
npx clawhub@latest install websocket-hub-patterns
This will provision the boilerplate hub structure, including the necessary channel orchestration and Redis lifecycle management logic.
Use Cases
- Real-time Collaboration: Ideal for document editing tools (like Google Docs clones) where updates need to be broadcast across multiple server nodes.
- Chat Applications: High-concurrency chat systems that require room-based messaging spanning multiple gateway instances.
- Live Operational Dashboards: Monitoring systems where data updates are pushed to clients in real-time, regardless of which instance they are connected to.
- Multi-tenant Gaming Servers: Managing game state updates across distributed clusters.
Example Prompts
- "OpenClaw, setup a new hub structure for my game server that supports horizontal scaling using the websocket-hub-patterns skill."
- "Can you show me how to trigger a graceful shutdown of the WebSocket hub to ensure no client messages are dropped during a deployment?"
- "Refactor my current local-only WebSocket implementation to use the lazy Redis subscription logic provided by the hub patterns skill."
Tips & Limitations
- Scalability Note: While Redis handles the pub/sub effectively, ensure your Redis cluster is sized correctly to handle the volume of message traffic.
- Consistency: The connection registry relies on external state (Redis). Always handle network partitioning scenarios where the registry might be out-of-sync with actual connections.
- Cleanup: Always ensure that when a local subscriber disconnects, the unsubscribe logic successfully closes the Redis channel to avoid memory leaks. The provided pattern handles this, but custom logic extensions should be audited for potential leaks.
Metadata
Not sure this is the right skill?
Describe what you want to build — we'll match you to the best skill from 16,000+ options.
Find the right skillPaste this into your clawhub.json to enable this plugin.
{
"plugins": {
"official-wpank-websocket-hub-patterns": {
"enabled": true,
"auto_update": true
}
}
}Tags(AI)
Flags: network-access
Related Skills
mermaid-diagrams
Create software diagrams using Mermaid syntax. Use when users need to create, visualize, or document software through diagrams including class diagrams, sequence diagrams, flowcharts, ERDs, C4 architecture diagrams, state diagrams, git graphs, and other diagram types. Triggers include requests to diagram, visualize, model, map out, or show the flow of a system.
api-design-principles
Skill by wpank
auto-context
Automatically read relevant context before major actions. Loads TODO.md, roadmap.md, handoffs, task plans, and other project context files so the AI operates with full situational awareness. Use when starting a task, implementing a feature, refactoring, debugging, planning, or resuming a session.
clear-writing
Write clear, concise prose for humans — documentation, READMEs, API docs, commit messages, error messages, UI text, reports, and explanations. Combines Strunk's rules for clearer prose with technical documentation patterns, structure templates, and review checklists.
track-performance
Track the performance of Uniswap LP positions over time — check which positions need attention, are out of range, or have uncollected fees. Use when the user asks how their positions are doing.