用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/mikailustuner/OmniRule --skill real-time-patterns命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | real-time-patterns |
| description | Real-time: WebSockets, SSE, polling, rooms, presence, reconnection |
| triggers | {"keywords":["real-time","WebSocket","SSE","Socket.io","live","streaming","presence","room","broadcast"]} |
| auto_load_when | Implementing real-time features |
| agent | infra-specialist |
| tools | ["Read","Write","Bash"] |
Focus: Choosing real-time strategy, implementation patterns, scaling
Use WebSockets when:
├── Bidirectional communication needed
├── Low-latency updates (chat, games)
├── High frequency messages
└── State synchronization
Use SSE when:
├── Server-to-client only
├── Simple one-way updates
├── Works with HTTP/2
└── Firewall-friendly
Use Polling when:
├── Infrequent updates
├── Simple implementation
├── No server state needed
└── Budget constraints
Connection lifecycle:
├── Handshake: HTTP upgrade
├── Connected: persistent
├── Ping/Pong: keep-alive
└── Close: graceful or error
Message patterns:
├── Text: JSON payloads
├── Binary: protocol buffers
└── Control frames: ping, pong, close
Scaling:
├── Sticky sessions or Redis pub/sub
├── Message brokers (Redis, Kafka)
└── Horizontal scaling
Room structure:
├── userId + roomId: private chat
├── roomId only: group channel
└── projectId: collaborative doc
Implementation:
├── Map roomId to subscriber set
├── Pub/sub to room channels
└── Add/remove on join/leave
State management:
├── In-memory: fast, single instance
├── Redis: distributed, persistent
└── Database: slow, last resort
Presence tracking:
├── Online/offline status
├── Last seen timestamp
├── Currently viewing (optional)
Implementation:
├── Heartbeat: every 30-60s
├── Expire: 2-3x heartbeat
└── Broadcast on join/leave
Use cases:
├── Show "user is typing"
├── Online indicators
└── Active user list
Reconnection strategy:
├── Exponential backoff: 1s, 2s, 4s, 8s, 32s max
├── Max retries: 5-10 then give up
└── User notification after max
State recovery:
├── Replay missed messages (with cursor)
├── Full state refetch
└── Optimistic UI, reconcile
Edge cases:
├── Network switch (wifi/cellular)
├── Sleep/wake
└── Tab backgrounding
Delivery guarantees:
├── At-most-once: fire and forget
├── At-least-once: ack + retry
└── Exactly-once: complex, rarely needed
Implementation:
├── Sequence numbers
├── Client ack
└── Server retry until ack
Offline queue:
├── Queue locally while disconnected
├── Sync on reconnect
└── Handle conflicts
❌ Polling every second from client
✅ Server-Sent Events for server→client; WebSocket for bidirectional
❌ Broadcasting every event to every connected client
✅ Room/channel-based routing — clients subscribe to relevant streams
❌ No backpressure handling on fast publishers
✅ Implement flow control; drop/buffer when consumer is slow
❌ Storing real-time state only in memory (lost on restart)
✅ Persist to Redis / DB; reconnecting clients can catch up
❌ WebSocket without heartbeat/ping-pong
✅ Send heartbeat every 30s; disconnect silent clients
| Pattern | Transport | Use case |
|---|---|---|
| Chat / collaboration | WebSocket | Bidirectional |
| Notifications | SSE | Server→client only |
| Live dashboards | SSE | Server→client only |
| Game state | WebSocket | Low latency |
| Presence | WebSocket + Redis | User online/offline |
| Event stream | Kafka / Redis Streams | Durable replay |