Designs WebSocket real-time systems with scaling strategies, reliability features, and security considerations.
You are a real-time systems architect who builds WebSocket applications. Design a real-time system for this use case.
Use case: [CHAT / NOTIFICATIONS / LIVE UPDATES / GAMING / COLLABORATION]
Expected connections: [CONCURRENT USERS]
Message frequency: [MESSAGES PER SECOND]
Latency requirements: [ACCEPTABLE DELAY]
Infrastructure: [AWS / GCP / SELF-HOSTED]
Framework: [SOCKET.IO / WS / NATIVE WEBSOCKET]
Provide:
**Architecture Diagram**
```
Client <--WS--> Load Balancer <--WS--> WebSocket Servers
|
Pub/Sub (Redis)
|
All Servers
```
**Server Implementation**
```[language]
// WebSocket server setup
// Connection handling
// Message routing
// Room/channel management
// Heartbeat/ping-pong
```
**Client Implementation**
```javascript
// Connection management
// Reconnection logic
// Message handling
// State synchronization
```
**Message Protocol**
```json
{
"type": "message_type",
"payload": {},
"timestamp": "ISO8601",
"messageId": "uuid"
}
```
**Scaling Strategy**
- Horizontal scaling approach
- Session affinity (sticky sessions)
- Pub/Sub for cross-server communication
- Connection distribution
**Reliability Features**
1. Reconnection
```javascript
// Exponential backoff
// State recovery
// Message queue during disconnect
```
2. Message Delivery
- At-least-once delivery
- Message acknowledgments
- Retry mechanism
3. Presence System
- Online/offline detection
- Last seen tracking
- Typing indicators
**Security**
- Authentication on connect
- Message validation
- Rate limiting
- Origin validation
**Monitoring**
- Connection metrics
- Message throughput
- Latency percentiles
- Error rates
**Fallback Strategy**
- Long polling fallback
- Server-sent events
- HTTP pollingYou are a real-time systems architect who builds WebSocket applications. Design a real-time system for this use case.
Use case: [CHAT / NOTIFICATIONS / LIVE UPDATES / GAMING / COLLABORATION]
Expected connections: [CONCURRENT USERS]
Message frequency: [MESSAGES PER SECOND]
Latency requirements: [ACCEPTABLE DELAY]
Infrastructure: [AWS / GCP / SELF-HOSTED]
Framework: [SOCKET.IO / WS / NATIVE WEBSOCKET]
Provide:
**Architecture Diagram**
```
Client <--WS--> Load Balancer <--WS--> WebSocket Servers
|
Pub/Sub (Redis)
|
All Servers
```
**Server Implementation**
```[language]
// WebSocket server setup
// Connection handling
// Message routing
// Room/channel management
// Heartbeat/ping-pong
```
**Client Implementation**
```javascript
// Connection management
// Reconnection logic
// Message handling
// State synchronization
```
**Message Protocol**
```json
{
"type": "message_type",
"payload": {},
"timestamp": "ISO8601",
"messageId": "uuid"
}
```
**Scaling Strategy**
- Horizontal scaling approach
- Session affinity (sticky sessions)
- Pub/Sub for cross-server communication
- Connection distribution
**Reliability Features**
1. Reconnection
```javascript
// Exponential backoff
// State recovery
// Message queue during disconnect
```
2. Message Delivery
- At-least-once delivery
- Message acknowledgments
- Retry mechanism
3. Presence System
- Online/offline detection
- Last seen tracking
- Typing indicators
**Security**
- Authentication on connect
- Message validation
- Rate limiting
- Origin validation
**Monitoring**
- Connection metrics
- Message throughput
- Latency percentiles
- Error rates
**Fallback Strategy**
- Long polling fallback
- Server-sent events
- HTTP pollingThis prompt is released under CC0 (Public Domain). You are free to use it for any purpose without attribution.
Explore similar prompts based on category and tags
Creates comprehensive Architecture Decision Records with options analysis, decision matrices, and consequence documentation.
Conducts thorough code reviews covering security, performance, maintainability, and best practices with specific fix suggestions.
Analyzes complex error stack traces to identify root causes and provide specific code fixes.
Identifies security vulnerabilities with fixes, OWASP analysis, and comprehensive hardening recommendations.