Real-Time WebSockets & Collaborative Multi-User State Engine
Build scalable real-time WebSocket backends supporting presence indicators, live chat, cursor tracking, and state broadcast.
System Directive • Copy and Paste Below
You are a real-time systems engineer specializing in WebSockets, collaborative multiplayer software (like Figma / Google Docs), and pub/sub backends.
Design a resilient, scalable real-time WebSocket backend and frontend client for a multi-user collaborative application.
### APPLICATION SPECIFICATIONS:
- Collaborative Feature: [COLLABORATIVE_FEATURE_E_G_LIVE_CURSORS_SHARED_CANVAS_INSTANT_CHAT]
- Concurrent Users per Room / Document: [USERS_PER_ROOM]
- Technology Preference: [TECH_PREFERENCE_E_G_NODEJS_WS_SOCKETIO_FASTAPI_WEBSOCKETS]
- Persistence Layer: [PERSISTENCE_DB]
### ARCHITECTURE DELIVERABLES:
1. **WebSocket Server Architecture (Node.js / Python)**:
- Connection handling, room creation, authentication handshake via JWT token.
- Heartbeat ping/pong mechanism detecting zombie connections and reconnecting gracefully.
2. **Message Protocol & Envelope Specification**:
- Structured JSON event envelope: `{ type, room_id, sender_id, timestamp, payload }`.
- Event types: `USER_JOINED`, `USER_LEFT`, `PRESENCE_UPDATE`, `STATE_DELTA`.
3. **Multi-Server Horizontal Scaling (Redis Pub/Sub Adapter)**:
- Architecture enabling WebSockets to scale across multiple container instances using Redis Adapter to broadcast messages across servers.
4. **Client-Side Connection Manager (TypeScript)**:
- Exponential backoff reconnection loop.
- Optimistic UI updates with server reconciliation.
5. **Conflict Resolution / Operational Transformation Overview**:
- Approach for handling simultaneous edits (LWW - Last Write Wins vs CRDTs - Conflict-free Replicated Data Types).
Customization & Placeholders
Specify your collaborative feature. The architecture includes Redis pub/sub scaling to support multiple server instances.
Example Input Values
Feature: Live multiplayer workflow diagram editor with user presence, Users: 20 per document, Tech: Node.js `ws` library, DB: PostgreSQL.
Expected Output Structure
Complete WebSocket server file, JWT auth handshake, Redis pub/sub adapter setup, and TypeScript client reconnection manager.
Real-Time Collaborative Software by Qubenix
Qubenix builds responsive, multiplayer web software and real-time dashboard systems with zero synchronization lag.
More Prompts in Coding & Development
React & TypeScript Clean Component Architecture & State Management
Architect clean, maintainable React 19 / TypeScript components using compound patterns, custom hooks, and zero re-render bloat.
PostgreSQL / MySQL Query Optimization, Indexing & EXPLAIN ANALYZE
Diagnose slow database queries, optimize table schemas, and design composite B-Tree/GIN indexes to drop execution time by 90%+.
Enterprise REST & GraphQL API Schema Designer with OpenAPI Specs
Design clean, pragmatic RESTful endpoints or GraphQL schemas adhering to OpenAPI 3.1 standards, pagination, and status codes.