ClawKit Logo
ClawKitReliability Toolkit
Back to Registry
Official Verified

websocket-patterns

Deep WebSocket/SSE workflow—handshake and auth, session lifecycle, heartbeats, ordering, backpressure, scaling, and observability. Use when building realtime dashboards, chat, collaborative editing, or live notifications.

skill-install — Terminal

Install via CLI (Recommended)

clawhub install openclaw/skills/skills/codenova58/websocket-patterns
Or

WebSocket Patterns (Deep Workflow)

Realtime connections add stateful complexity: who is connected, what order messages arrive, and what happens when links flap. Design for at-least-once delivery, explicit heartbeats, and horizontal scaling early.

When to Offer This Workflow

Trigger conditions:

  • Replacing polling with WS or SSE
  • Auth on connect; token refresh mid-session
  • Fan-out to many subscribers; presence and typing indicators
  • Sticky sessions, load balancer timeouts, reconnect storms

Initial offer:

Use six stages: (1) choose transport, (2) connection & auth, (3) protocol & messages, (4) reliability & ordering, (5) scale & ops, (6) security & abuse). Confirm browser vs server clients and proxies (nginx, ALB, Cloudflare).


Stage 1: Choose Transport

Goal: WebSocket vs SSE vs long polling—right tool per direction.

Heuristics

  • Bidirectional, low latency, binary payloads → WebSocket
  • Server → client one-way streams, HTTP-friendly infra → SSE
  • Fire-and-forget notifications with simple infra → consider push services first

Caveats

  • Corporate proxies historically hurt WS—test environments; WSS mandatory
  • HTTP/3 QUIC stacks differ—validate intermediaries

Exit condition: Transport choice documented with why not alternatives.


Stage 2: Connection & Auth

Goal: Authenticated sockets without long-lived secrets in query strings when avoidable.

Patterns

  • JWT in Sec-WebSocket-Protocol or first message after connect—prefer short-lived tokens + refresh flow
  • Cookie sessions with CSRF considerations on same-site policies
  • Re-auth before token expiry; graceful close with code and reason

Authorization

  • Subscribe to topics only after server-side check—never trust client channel names alone

Exit condition: Auth diagram: issue token → connect → authorize subscriptions.


Stage 3: Protocol & Messages

Goal: Versioned message schema; predictable errors.

Design

  • Envelope: { type, id, ts, payload }; correlation ids for RPC-style
  • Version negotiation on connect or feature flags in hello message
  • Binary vs JSON—protobuf/msgpack for bandwidth; JSON for debuggability early

Heartbeats

  • Ping/pong or application-level heartbeat at interval < proxy timeout (often 30–60s)
  • Idle detection and clean disconnect

Exit condition: Protocol doc + example session transcript.


Stage 4: Reliability & Ordering

Goal: Define delivery semantics—usually at-least-once over TCP; ordering per channel.

Practices

Metadata

Stars3453
Views1
Updated2026-03-26
View Author Profile
AI Skill Finder

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 skill
Add to Configuration

Paste this into your clawhub.json to enable this plugin.

{
  "plugins": {
    "official-codenova58-websocket-patterns": {
      "enabled": true,
      "auto_update": true
    }
  }
}
Safety NoteClawKit audits metadata but not runtime behavior. Use with caution.