Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIMuseMuseDotsDots+21 more

    Websocket Realtime Sync Manager

    1

    Design and implement resilient, horizontally scalable WebSocket and SSE architectures with Redis synchronization.

    $15

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned
    Websocket Realtime Sync Manager

    Websocket Realtime Sync Manager

    Example session with this skill installed

    Implement a secure WebSocket server in TypeScript that uses Redis for scaling and handles connection heartbeats.

    • Read your context and instructions
    • Compiled the websocket realtime sync

    I have implemented a resilient WebSocket server architecture. The solution includes a Redis Pub/Sub adapter for horizontal scaling, a ping/pong heartbeat mechanism to prune dead connections, and token-based authentication for the initial handshake.

    WebSocket Server Implementation

    import { WebSocketServer, WebSocket } from 'ws';
    import { createClient } from 'redis';
    import { createServer } from 'http';
    
    const server = createServer();
    const wss = new WebSocketServer({ noServer: true });
    
    // Redis Clients for Pub/Sub Scaling
    const pubClient = createClient({ url: process.env.REDIS_URL });
    const subClient = pubClient.duplicate();
    
    async function setupScaling() {
      await Promise.all([pubClient.connect(), subClient.connect()]);
      
      subClient.subscribe('broadcast_channel', (message) => {
        wss.clients.forEach((client) => {
          if (client.readyState === WebSocket.OPEN) {
            client.send(message);
          }
        });
      });
    }
    
    // Heartbeat Logic
    function heartbeat() {
      this.isAlive = true;
    }
    
    const interval = setInterval(() => {
      wss.clients.forEach((ws: any) => {
        if (ws.isAlive === false) return ws.terminate();
        ws.isAlive = false;
        ws.ping();
      });
    }, 30000);
    
    server.on('upgrade', async (request, socket, head) => {
      // Token Authentication Handshake
      const token = new URL(request.url!, 'http://localhost').searchParams.get('token');
      if (!token || !isValid(token)) {
        socket.write('HTTP/1.1 401 Unauthorized\r\n\r\n');
        socket.destroy();
        return;
      }
    
      wss.handleUpgrade(request, socket, head, (ws: any) => {
        ws.isAlive = true;
        ws.on('pong', heartbeat);
        wss.emit('connection', ws, request);
      });
    });
    
    wss.on('connection', (ws) => {
      ws.on('message', async (data) => {
        // Broadcast via Redis for multi-node sync
        await pubClient.publish('broadcast_channel', data.toString());
      });
    });
    
    setupScaling();
    

    Next steps

    1. Add your token validation logic to the isValid() placeholder in the handshake.
    2. Configure the REDIS_URL in your .env file.
    3. Implement the client-side exponential backoff logic to match this server's heartbeat frequency.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    Building real-time features often leads to ghost connections, memory leaks from dead TCP sockets, and messages lost between server nodes. Handshaking is easy, but maintaining a resilient connection at scale is difficult. This skill implements the architectural patterns required for production-grade WebSocket and SSE systems.

    What it does

    • Heartbeat protocols implements ping/pong mechanisms to detect and prune stale TCP connections.
    • Horizontal scaling configures Redis Pub/Sub adapters to synchronize messages across multiple server instances.
    • Resilient reconnection generates client-side logic using exponential backoff with jitter to prevent thundering herd problems.
    • Secure handshaking enforces token-based authentication during the initial connection phase.
    • Broadcasting logic structures event-driven patterns for targeted or global message delivery.

    How it works

    1. Initialize the server by defining the WebSocket or SSE handshake and authentication layer.
    2. Setup state management using Redis to ensure users on different pods can communicate.
    3. Configure the heartbeat to manage socket lifecycle and prevent resource exhaustion.
    4. Deploy client logic with robust retry strategies to handle network instability.

    Frameworks & tools

    The skill produces TypeScript code optimized for Node.js environments. It utilizes Redis for the Pub/Sub layer and follows standard protocols for WebSockets and Server-Sent Events.

    Why this beats prompting it yourself

    Generic prompts often miss the edge cases of distributed real-time systems, such as cross-node synchronization and socket pruning. This skill follows a deterministic workflow to ensure connection security and infrastructure scalability are built-in, not added as afterthoughts.

    Use cases

    • Build a chat system that scales across multiple Kubernetes pods.
    • Implement live data dashboards with automatic client reconnection.
    • Create collaborative editing tools requiring low-latency state sync.
    • Design secure real-time notification services with token auth.

    Known limitations

    Outputs are focused on TypeScript implementations. Requires an existing Redis instance or cluster for cross-instance broadcasting features.

    Focused on TypeScript. Requires a Redis instance for horizontal scaling features. Restricted to project workspace file operations.

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before any payment.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    Money-back guarantee

    Doesn't do what its page promises? You get your money back.

    Trust & safety

    Security scan

    Security scan passed 3 days ago

    Requires

    File System Read/Write (strictly scoped to current project workspace `./`).
    Zero global installation or elevated privileges required.

    Permissions

    Read Files

    Target Use Cases: - Build a scalable WebSocket server with Redis pub/sub. - Implement heartbeat ping/pong and reconnection for WebSockets. - Create a real-time event broadcasting architecture.

    Listed3 days ago

    What's inside

    Frequently Asked Questions

    It eliminates common production issues like 'ghost connections' (stale TCP sockets), memory leaks, and message loss when users are connected to different server nodes in a distributed environment.

    The skill delivers a complete architectural blueprint and TypeScript implementation, including server-side Redis Pub/Sub logic, heartbeat protocols, and client-side reconnection scripts.

    Yes, while optimized for Node.js and TypeScript, the skill is designed to work with any standard Redis instance or cluster to facilitate horizontal scaling across multiple pods.

    This skill is compatible with most advanced AI agents capable of generating structured TypeScript code and can be integrated into your existing development workflow via the marketplace interface.

    The skill includes logic for token-based authentication during the initial handshake, ensuring that only verified clients can establish and maintain a persistent connection.

    New in APIs & Backend