- Home
- Skills
- APIs & Backend
- Websocket Realtime Sync Manager
Works with the AI Agents you already use
Websocket Realtime Sync Manager
Design and implement resilient, horizontally scalable WebSocket and SSE architectures with Redis synchronization.
$15
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
- Add your token validation logic to the
isValid()placeholder in the handshake. - Configure the
REDIS_URLin your.envfile. - 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
- Initialize the server by defining the WebSocket or SSE handshake and authentication layer.
- Setup state management using Redis to ensure users on different pods can communicate.
- Configure the heartbeat to manage socket lifecycle and prevent resource exhaustion.
- 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
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
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 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
Permissions
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.