secondsky avatar

Websocket Implementation

This is a production-ready WebSocket setup using Socket.IO with Redis pub/sub for horizontal scaling. It covers authentication middleware, room-based messaging, connection management, and includes both server and client implementations plus a React hook. The code handles reconnection logic, message queuing when offline, and provides monitoring endpoints for tracking active connections. What I like here is the scaling guidance table that tells you exactly when to add Redis (10K+ connections) versus staying single-server. It's opinionated about real concerns like rate limiting and not storing unlimited messages in memory, which saves you from learning those lessons the hard way in production.

skills.sh installs
440
GitHub stars
248
last updated
Aug 21, 2026

Install

$ npx -y skills add secondsky/claude-skills --skill websocket-implementation --agent claude-code

Installs into .claude/skills of the current project.

Files

WebSocket Implementation

Build scalable real-time communication systems with proper connection management.

Server Implementation (Socket.IO)

const { Server } = require('socket.io');
const { createAdapter } = require('@socket.io/redis-adapter');
const { createClient } = require('redis');

const io = new Server(server, {
  cors: { origin: process.env.CLIENT_URL, credentials: true }
});

// Redis adapter for horizontal scaling
const pubClient = createClient({ url: process.env.REDIS_URL });
const subClient = pubClient.duplicate();
Promise.all([pubClient.connect(), subClient.connect()]).then(() => {
  io.adapter(createAdapter(pubClient, subClient));
});

// Connection management
const users = new Map();

io.use((socket, next) => {
  const token = socket.handshake.auth.token;
  try {
    socket.user = verifyToken(token);
    next();
  } catch (err) {
    next(new Error('Authentication failed'));
  }
});

io.on('connection', (socket) => {
  users.set(socket.user.id, socket.id);
  console.log(`User ${socket.user.id} connected`);

  socket.on('join-room', (roomId) => {
    socket.join(roomId);
    socket.to(roomId).emit('user-joined', socket.user);
  });

Sponsors

Details

Repository
github.com/secondsky/claude-skills
Category
Backend & APIs
First seen
Jun 3, 2026

More from secondsky/claude-skills

All 146
1secondsky avatarapi-filtering-sortingsecondsky/claude-skillsBuilds flexible API filtering and sorting systems with query parameter parsing, validation, and security. Use when implementing search endpoints, building data 432skills.sh installs
2onewave-ai avatardatabase-schema-designeronewave-ai/claude-skillsDesign optimized database schemas for SQL and NoSQL databases including tables, relationships, indexes, and constraints. Creates ERD diagrams, migration scripts426skills.sh installs
3vercel avatarai-gatewayvercel/vercel-pluginai gateway423skills.sh installs
4sickn33 avatarcc-skill-backend-patternssickn33/antigravity-awesome-skillscc skill backend patterns421skills.sh installs
5sickn33 avatardatabase-migrations-sql-migrationssickn33/antigravity-awesome-skillsdatabase migrations sql migrations408skills.sh installs
6insforge avatarinsforge-backend-advisorinsforge/agent-skillsinsforge backend advisor400skills.sh installs