Software Development

AI WebSocket Service Generator

Architect production-grade real-time backends with automatic scaling, auth, and protocol design

#websocket#real-time#backend-development#scalability#infrastructure
P
Created by PromptLib Team
Published February 11, 2026
4,612 copies
4.3 rating
You are a Principal Software Engineer specializing in distributed real-time systems and WebSocket architecture. Design and implement a complete, production-ready WebSocket service based on the specifications below.

## TECHNICAL SPECIFICATIONS
- **Programming Language**: [PROGRAMMING_LANGUAGE]
- **WebSocket Framework**: [FRAMEWORK] (e.g., Socket.io, ws, FastAPI WebSockets, Gorilla, SocketCluster)
- **Use Case**: [USE_CASE] (e.g., live chat, stock ticker, multiplayer gaming, collaborative editing)
- **Scale Target**: [SCALE_REQUIREMENTS] (e.g., 10k concurrent connections, 1M messages/second)
- **Authentication Method**: [AUTH_METHOD] (e.g., JWT tokens, API keys, OAuth2, session cookies)
- **Persistence Layer**: [PERSISTENCE_REQUIREMENT] (e.g., Redis pub/sub, PostgreSQL message history, none)
- **Infrastructure**: [INFRASTRUCTURE] (e.g., Docker containers, Kubernetes, AWS ECS, bare metal)

## DELIVERABLES (Generate All Sections)

### 1. Architecture Diagram (Text-Based)
Provide an ASCII or markdown representation of the system architecture including load balancers, WebSocket servers, Redis cluster (if applicable), and database connections.

### 2. Project Structure
Show the complete file tree with separation of concerns (handlers, middleware, models, config, tests).

### 3. Core Implementation Code
Generate production-quality code including:
- Server initialization with graceful shutdown handling
- Connection manager with heartbeat/ping-pong mechanisms
- Message protocol schemas (JSON validation)
- Room/namespace management logic
- Event handlers for connect/disconnect/message/error events
- Broadcasting and multicast patterns

### 4. Authentication & Security
Implement:
- Connection upgrade authentication middleware
- CORS configuration for WebSocket origins
- Rate limiting per IP/user
- Input sanitization and message size limits
- Protection against DDoS and connection flooding

### 5. Scaling & High Availability
Detail:
- Horizontal scaling strategy with sticky sessions (or stateless architecture)
- Redis adapter configuration for multi-server synchronization (if applicable)
- Load balancer configuration (nginx/HAProxy/AWS ALB settings for WebSocket support)
- Connection distribution algorithms

### 6. Error Handling & Resilience
Include:
- Automatic reconnection logic with exponential backoff
- Circuit breakers for external service calls
- Memory leak prevention (proper cleanup on disconnect)
- Fallback to long-polling or SSE if WebSocket fails
- Structured logging with correlation IDs

### 7. Database Integration (if applicable)
- Schema for message persistence
- Write strategies (async batching vs immediate)
- Connection pooling configuration

### 8. Monitoring & Observability
- Health check endpoints
- Metrics collection (Prometheus/Grafana compatible)
- Connection count tracking
- Message throughput monitoring
- Error rate alerting

### 9. Testing Strategy
- Unit test examples for event handlers
- Load testing scripts (using Artillery or k6)
- Integration test patterns for WebSocket flows

### 10. Deployment Configuration
- Dockerfile optimized for [PROGRAMMING_LANGUAGE] WebSocket servers
- Docker Compose for local development with dependencies
- Environment variable documentation
- Cloud deployment notes (AWS/GCP/Azure specific gotchas)

## CODE QUALITY REQUIREMENTS
- Use [PROGRAMMING_LANGUAGE] idioms and best practices (async/await, proper typing, error handling)
- Include comprehensive inline comments explaining WebSocket-specific decisions
- Ensure thread-safety and prevent race conditions in connection management
- Optimize for low latency and high throughput
- Follow OWASP security guidelines for real-time applications
Best Use Cases
Building a live chat system for a SaaS platform requiring message persistence and delivery receipts
Creating real-time collaborative editing features similar to Google Docs with operational transformation
Developing a high-frequency trading dashboard pushing market data to thousands of clients simultaneously
Implementing multiplayer game state synchronization with low-latency requirements
Designing a notification system for mobile apps with fallback to push notifications when WebSocket disconnects
Frequently Asked Questions

More Like This

Back to Library

AI Database Migration Planner

This prompt transforms AI into a Principal Database Architect that analyzes your source and target environments to create comprehensive migration blueprints. It addresses schema compatibility, downtime minimization, data integrity verification, and disaster recovery to ensure zero-data-loss deployments.

#database#migration+3
1,418
3.7

AI Cache Strategy Designer

This prompt transforms AI into a distributed systems architect that designs comprehensive caching strategies for your applications. It analyzes your specific constraints—traffic patterns, data characteristics, and infrastructure—to deliver actionable recommendations on cache topology, invalidation strategies, eviction policies, and failure mitigation techniques.

#caching#distributed-systems+3
2,586
4.4

Enterprise API Gateway Architecture Configurator

This prompt transforms the AI into a senior cloud infrastructure architect specializing in API gateway design and edge computing. It helps you create comprehensive gateway configurations that handle routing, security, rate limiting, and observability for any scale, while explaining architectural trade-offs and providing deployment-ready code.

#api-gateway#infrastructure+3
1,461
4.1
Get This Prompt
Free
Quick Actions
Estimated time:12 min
Verified by59 experts