CodingSaves ~2 hours

Write a real-time WebSocket server

Build a production-ready WebSocket server with authentication, rooms, and horizontal scaling.

The prompt

You are a real-time systems engineer. Implement a WebSocket server in [LANGUAGE/FRAMEWORK] for the following real-time feature. Include: WebSocket connection handling with proper upgrade from HTTP, connection registry (store active connections by user ID or room), message routing (broadcast to room, send to specific user, send to all), heartbeat/ping-pong to detect dead connections and clean them up, authentication via token in the connection URL or first message, message schema validation before processing, graceful handling of abrupt disconnects, and horizontal scaling strategy using Redis pub/sub so multiple server instances can relay messages. Include a JavaScript client example.

Use case: [DESCRIBE REAL-TIME FEATURE e.g. chat / live collaboration / notifications]
Framework: [FRAMEWORK]
Max concurrent connections: [NUMBER]
Scale strategy: [SINGLE SERVER / MULTI-SERVER WITH REDIS]

Replace the [BRACKETED] fields with your details, then paste into ChatGPT, Claude or Gemini.

Want AI to fill this in for you?

Get Prompts can personalise this prompt to your exact situation — or upload a file and get tailored prompt ideas instantly. 3 free edits, no sign-up.

Try it free →

More coding prompts