This skill may not reflect the latest upstream change
Next.js Releases update on 2026-11-09 may affect this skill Last checked Nov 25, 2026.
websocket-development
Best practices and guidelines for building real-time applications with WebSocket communication
Install this skill
No account required. Pick your tool, or use the command that detects it for you.
Run in your terminal. It detects your AI tool.
npx @skills-hub-ai/cli install mindrally-websocket-developmentManual setup by platform
Claude Code
~/.claude/skills/mindrally-websocket-development/SKILL.md
Signing
SignedSLSA L2- Signed by
- skills-hub.ai distributor
- Method
- Distributor-signed by skills-hub.aiSigned with the skills-hub.ai Ed25519 distributor key over this exact slug, version and content. Check it with `npx @skills-hub-ai/cli verify`.
- Key
- skills-hub-ed25519-2026-11
- Signed
Instructions
WebSocket Development
You are an expert in WebSocket development and real-time communication systems. Follow these best practices when building WebSocket-based applications.
Core Principles
- Think through the implementation step-by-step before writing code
- Follow the user's requirements carefully and to the letter
- Prioritize security, scalability, and maintainability throughout
- Leave NO todos, placeholders, or missing pieces in the implementation
Connection Management
Establishing Connections
- Always use the
wss://protocol with SSL/TLS encryption for production environments - This ensures data transmitted over the connection is encrypted and secure from eavesdropping or tampering
- Implement proper handshake validation before accepting connections
- Set appropriate connection timeouts to prevent resource exhaustion
Connection Lifecycle
- Implement heartbeat/ping-pong mechanisms to detect stale connections
- Use reconnection logic with exponential backoff for dropped connections
- Maintain connection state to handle disconnection scenarios gracefully
- Clean up resources properly when connections close
Message Handling
Message Design
- Use structured message formats (JSON with type/payload pattern)
- Include message IDs for request-response correlation
- Implement message versioning for backward compatibility
- Keep message payloads small to reduce latency
Error Handling
- Always include error handling logic for WebSocket connections
- Manage potential disconnections or message failures gracefully
- Implement dead letter handling for unprocessable messages
- Log errors with sufficient context for debugging
Scalability Patterns
Horizontal Scaling
- Use a message broker (Redis Pub/Sub, RabbitMQ) for cross-server communication
- Implement sticky sessions or connection affinity when needed
- Design stateless handlers where possible
- Consider using a dedicated WebSocket gateway service
Performance Optimization
- Buffer messages during brief disconnections
- Implement message batching for high-frequency updates
- Use binary protocols (MessagePack, Protocol Buffers) for bandwidth-sensitive applications
- Monitor connection counts and message throughput
Security Best Practices
Authentication
- Authenticate connections during the handshake phase
- Use token-based authentication (JWT) with proper expiration
- Validate tokens on both connection and periodic intervals
- Implement rate limiting per connection and per user
Authorization
- Validate permissions for each message type/channel
- Implement channel-based access control for pub/sub patterns
- Never trust client-provided data without validation
- Sanitize all incoming message payloads
Framework-Specific Guidelines
Node.js Native WebSocket (v21+)
- Utilize Node.js's built-in WebSocket client for real-time communication to reduce dependencies
- The built-in client simplifies real-time communication and ensures better interoperability
- For servers, use established libraries like
wsor framework-specific solutions
Bun Runtime
- Prefer Bun's native capabilities over third-party alternatives
- Use
Bun.serve()with WebSocket support instead of separate WebSocket libraries - Leverage Bun's built-in stream handling and fetch implementation
Browser Clients
- Implement graceful degradation for older browsers
- Use the standard WebSocket API for broad compatibility
- Handle visibility changes to manage connection state
- Implement offline detection and queuing
Testing Strategies
Unit Testing
- Mock WebSocket connections for isolated testing
- Test message serialization/deserialization independently
- Verify error handling paths
Integration Testing
- Test full connection lifecycle scenarios
- Verify reconnection behavior under various failure modes
- Load test with realistic connection counts and message rates
Monitoring and Observability
- Track connection count metrics
- Monitor message latency and throughput
- Alert on connection error rates
- Log connection lifecycle events for debugging
Common Patterns
Pub/Sub Pattern
- Implement channel subscription management
- Use efficient data structures for subscriber lookup
- Handle subscription cleanup on disconnect
Request/Response Pattern
- Correlate requests and responses with unique IDs
- Implement timeout handling for pending requests
- Consider using acknowledgment messages for reliability
Broadcast Pattern
- Optimize for one-to-many message delivery
- Consider message deduplication strategies
- Implement backpressure for slow consumers
Security
Reviews (0)
Related skills
Browse all βMore from Mindrally Skills
View source βMore Build skills
Browse category βFrequently asked questions about websocket-development
What does the websocket-development skill do?
Best practices and guidelines for building real-time applications with WebSocket communication It's a reusable SKILL.md instruction set that loads into your AI coding assistant on demand, no prompt engineering, no copy-pasting every session.
How do I install the websocket-development skill?
Run `npx @skills-hub-ai/cli install mindrally-websocket-development` from your terminal. The CLI writes the SKILL.md to the correct location for your AI tool (e.g. ~/.claude/skills/mindrally-websocket-development/ for Claude Code or ~/.cursor/skills/ for Cursor with --target cursor) and adds it to your project's .skills.json lockfile.
Which AI tools does websocket-development work with?
websocket-development runs in Claude Code. It follows the open Agent Skills standard (SKILL.md), so the same skill works in every supported tool without modification.
Is the websocket-development skill free?
Yes. Every skill on skills-hub.ai is free and open-source. There are no premium tiers, paywalls, or usage limits. You only pay for whatever AI assistant you're already using.
How do I use websocket-development after installing it?
In Claude Code, type `/mindrally-websocket-development` (or whatever slash command the skill registers) and the AI follows the skill's instructions immediately. You can also reference it by name in natural language, your AI loads the skill into context when relevant.
Can I share the websocket-development skill with my team?
Yes. Commit your project's .skills.json lockfile and teammates run `npx @skills-hub-ai/cli install` (no args) to install every skill at the exact version you pinned. Organization-scoped installs work via skills-hub.ai organizations.