Back to prompts
Implement real-time functionality using WebSockets for the following feature: Feature: [e.g. live chat / real-time notifications / collaborative editing / live dashboard / presence indicators] Backend: [Node.js with ws/Socket.io / Python with FastAPI WebSockets / Go] Frontend: [React / Vanilla JS / Next.js] Scale expectation: [single server / needs horizontal scaling] Implement: 1. Server-side WebSocket handler: - Connection management (store active connections) - Message routing / event types - Broadcasting (to all / to room / to specific user) - Disconnection cleanup - Heartbeat / ping-pong to detect dead connections 2. Client-side connection: - Connection with auto-reconnect and exponential backoff - Event listeners for each message type - Connection state management (connecting / connected / disconnected) - Graceful cleanup on component unmount 3. Authentication: how to authenticate a WebSocket connection 4. Message format: standardised event envelope 5. If scaling beyond one server: how to use Redis pub/sub for cross-instance broadcasting Include error handling for network interruptions.
How to use this prompt
- 1Copy the prompt using the button above.
- 2Open your AI tool (ChatGPT, Claude, Midjourney, etc.)
- 3Paste and customize any variables in the prompt.
- 4Generate your result.