Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Real-time communication patterns for live updates, collaboration, and presence. Use when building chat applications, collaborative tools, live dashboards, or streaming interfaces (LLM responses, metrics). Covers SSE (server-sent events for one-way streams), WebSocket (bidirectional communication), WebRTC (peer-to-peer video/audio), CRDTs (Yjs, Automerge for conflict-free collaboration), presence patterns, offline sync, and scaling strategies. Supports Python, Rust, Go, and TypeScript.
.claude/skills/ancoleman-implementing-realtime-sync/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-02 | ✗→✓ | ▲ Improved | 106% | 0% |
| case-01 | ✓→✓ | = Same ✓ | 87% | 0% |
| case-11 | ✓→✓ | = Same ✓ | 44% | 0% |
| case-03 | ✓→✓ | = Same ✓ | 63% | 0% |
| case-04 | ✓→✓ | = Same ✓ | 365% | 0% |
Implement real-time communication for live updates, collaboration, and presence awareness across applications.
Use this skill when building:
Choose the transport protocol based on communication pattern:
ONE-WAY (Server → Client only)
├─ LLM streaming, notifications, live feeds
└─ Use SSE (Server-Sent Events)
├─ Automatic reconnection (browser-native)
├─ Event IDs for resumption
└─ Simple HTTP implementation
BIDIRECTIONAL (Client ↔ Server)
├─ Chat, games, collaborative editing
└─ Use WebSocket
├─ Manual reconnection required
├─ Binary + text support
└─ Lower latency for two-way
COLLABORATIVE EDITING
├─ Multi-user documents/spreadsheets
└─ Use WebSocket + CRDT (Yjs or Automerge)
├─ CRDT handles conflict resolution
├─ WebSocket for transport
└─ Offline-first with sync
PEER-TO-PEER MEDIA
├─ Video, screen sharing, voice calls
└─ Use WebRTC
├─ WebSocket for signaling
├─ Direct P2P connection
└─ STUN/TURN for NAT traversal| Protocol | Direction | Reconnection | Complexity | Best For | |----------|-----------|--------------|------------|----------| | SSE | Server → Client | Automatic | Low | Live feeds, LLM streaming | | WebSocket | Bidirectional | Manual | Medium | Chat, games, collaboration | | WebRTC | P2P | Complex | High | Video, screen share, voice |
Stream LLM tokens progressively to frontend (ai-chat integration).
Python (FastAPI):
pythonfrom sse_starlette.sse import EventSourceResponse @app.post("/chat/stream") async def stream_chat(prompt: str): async def generate(): async for chunk in llm_stream: yield {"event": "token", "data": chunk.content} yield {"event": "done", "data": "[DONE]"} return EventSourceResponse(generate())
Frontend:
typescriptconst es = new EventSource('/chat/stream') es.addEventListener('token', (e) => appendToken(e.data))
Reference references/sse.md for full implementations, reconnection, and event ID resumption.
Bidirectional communication for chat applications.
Python (FastAPI):
pythonconnections: set[WebSocket] = set() @app.websocket("/ws") async def websocket_endpoint(websocket: WebSocket): await websocket.accept() connections.add(websocket) try: while True: data = await websocket.receive_text() for conn in connections: await conn.send_text(data) except WebSocketDisconnect: connections.remove(websocket)
Reference references/websockets.md for multi-language examples, authentication, heartbeats, and scaling.
Conflict-free multi-user editing using Yjs.
TypeScript (Yjs):
typescriptimport * as Y from 'yjs' import { WebsocketProvider } from 'y-websocket' const doc = new Y.Doc() const provider = new WebsocketProvider('ws://localhost:1234', 'doc-id', doc) const ytext = doc.getText('content') ytext.observe(event => console.log('Changes:', event.changes)) ytext.insert(0, 'Hello collaborative world!')
Reference references/crdts.md for conflict resolution, Yjs vs Automerge, and advanced patterns.
Track online users, cursor positions, and typing indicators.
Yjs Awareness API:
typescriptconst awareness = provider.awareness awareness.setLocalState({ user: { name: 'Alice' }, cursor: { x: 100, y: 200 } }) awareness.on('change', () => { awareness.getStates().forEach((state, clientId) => { renderCursor(state.cursor, state.user) }) })
Reference references/presence-patterns.md for cursor tracking, typing indicators, and online status.
Queue mutations locally and sync when connection restored.
TypeScript (Yjs + IndexedDB):
typescriptimport { IndexeddbPersistence } from 'y-indexeddb' import { WebsocketProvider } from 'y-websocket' const doc = new Y.Doc() const indexeddbProvider = new IndexeddbPersistence('my-doc', doc) const wsProvider = new WebsocketProvider('wss://api.example.com/sync', 'my-doc', doc) wsProvider.on('status', (e) => { console.log(e.status === 'connected' ? 'Online' : 'Offline') })
Reference references/offline-sync.md for conflict resolution and sync strategies.
WebSocket:
websockets 13.x - AsyncIO-based, production-readyFastAPI WebSocket - Built-in, dependency injectionFlask-SocketIO - Socket.IO protocol with fallbacksSSE:
sse-starlette - FastAPI/Starlette, async, generator-basedFlask-SSE - Redis backend for pub/subWebSocket:
tokio-tungstenite 0.23 - Tokio integration, production-readyaxum WebSocket - Built-in extractors, tower middlewareSSE:
axum SSE - Native support, async streamsWebSocket:
gorilla/websocket - Battle-tested, compression supportnhooyr/websocket - Modern API, context supportSSE:
net/http (native) - Flusher interface, no dependenciesWebSocket:
ws - Native WebSocket server, lightweightSocket.io 4.x - Auto-reconnect, fallbacks, roomsHono WebSocket - Edge runtime (Cloudflare Workers, Deno)SSE:
EventSource (native) - Browser-native, automatic retryhttp (native) - Server-side, no dependenciesCRDT:
Yjs - Mature, TypeScript/Rust, rich text editingAutomerge - Rust/JS, JSON-like data, time-travelSSE: Browser's EventSource handles reconnection automatically with exponential backoff. WebSocket: Implement manual exponential backoff with jitter to prevent thundering herd.
Reference references/sse.md and references/websockets.md for complete implementation patterns.
Authentication: Use cookie-based (same-origin) or token in Sec-WebSocket-Protocol header. Rate Limiting: Implement per-user message throttling with sliding window.
Reference references/websockets.md for authentication and rate limiting implementations.
For horizontal scaling, use Redis pub/sub to broadcast messages across multiple backend servers.
Reference references/websockets.md for complete Redis scaling implementation.
SSE for LLM Streaming (ai-chat):
typescriptuseEffect(() => { const es = new EventSource(`/api/chat/stream?prompt=${prompt}`) es.addEventListener('token', (e) => setContent(prev => prev + e.data)) return () => es.close() }, [prompt])
WebSocket for Live Metrics (dashboards):
typescriptuseEffect(() => { const ws = new WebSocket('ws://localhost:8000/metrics') ws.onmessage = (e) => setMetrics(JSON.parse(e.data)) return () => ws.close() }, [])
Yjs for Collaborative Tables:
typescriptuseEffect(() => { const doc = new Y.Doc() const provider = new WebsocketProvider('ws://localhost:1234', docId, doc) const yarray = doc.getArray('rows') yarray.observe(() => setRows(yarray.toArray())) return () => provider.destroy() }, [docId])
For detailed implementation patterns, consult:
references/sse.md - SSE protocol, reconnection, event IDsreferences/websockets.md - WebSocket auth, heartbeats, scalingreferences/crdts.md - Yjs vs Automerge, conflict resolutionreferences/presence-patterns.md - Cursor tracking, typing indicatorsreferences/offline-sync.md - Mobile patterns, conflict strategiesWorking implementations available in:
examples/llm-streaming-sse/ - FastAPI SSE for LLM streaming (RUNNABLE)examples/chat-websocket/ - Python FastAPI + TypeScript chatexamples/collaborative-yjs/ - Yjs collaborative editorUse scripts to validate implementations:
scripts/test_websocket_connection.py - WebSocket connection testing| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-01 | pass→pass | 21,840 | 9,839 | -55% | 1 | 1 | 0% | 2,100 | 3,937 | +87% | 0 | 0 | — |
case-02 | fail→pass | 10,870 | 9,971 | -8% | 1 | 1 | 0% | 1,940 | 4,001 | +106% | 0 | 0 | — |
case-11 | pass→pass | 19,307 | 10,075 | -48% | 1 | 1 | 0% | 2,688 | 3,870 | +44% | 0 | 0 | — |
case-03 | pass→pass | 14,270 | 8,179 | -43% | 1 | 1 | 0% | 2,276 | 3,713 | +63% | 0 | 0 | — |
case-04 | pass→pass | 3,780 | 5,944 | +57% | 1 | 1 | 0% | 700 | 3,256 | +365% | 0 | 0 | — |
case-05 | pass→pass | 14,660 | 9,243 | -37% | 1 | 1 | 0% | 2,243 | 3,884 | +73% | 0 | 0 | — |
case-06 | pass→pass | 6,899 | 4,391 | -36% | 1 | 1 | 0% | 1,158 | 2,994 | +159% | 0 | 0 | — |
case-07 | pass→pass | 13,389 | 13,546 | +1% | 1 | 1 | 0% | 2,363 | 4,458 | +89% | 0 | 0 | — |
case-08 | pass→pass | 20,259 | 11,743 | -42% | 1 | 1 | 0% | 2,599 | 4,217 | +62% | 0 | 0 | — |
case-09 | pass→pass | 18,042 | 16,202 | -10% | 1 | 1 | 0% | 2,864 | 4,974 | +74% | 0 | 0 | — |
case-10 | pass→pass | 6,383 | 6,684 | +5% | 1 | 1 | 0% | 1,095 | 3,436 | +214% | 0 | 0 | — |
case-12 | pass→pass | 8,097 | 5,773 | -29% | 1 | 1 | 0% | 1,571 | 3,283 | +109% | 0 | 0 | — |
case-13 | pass→pass | 5,832 | 5,521 | -5% | 1 | 1 | 0% | 883 | 3,235 | +266% | 0 | 0 | — |
case-14 | pass→pass | 12,355 | 8,486 | -31% | 1 | 1 | 0% | 2,001 | 3,557 | +78% | 0 | 0 | — |
case-15 | pass→pass | 6,510 | 5,975 | -8% | 1 | 1 | 0% | 1,323 | 3,304 | +150% | 0 | 0 | — |
case-16 | fail→fail | 14,678 | 14,344 | -2% | 1 | 1 | 0% | 2,403 | 4,534 | +89% | 0 | 0 | — |
case-17 | pass→pass | 3,500 | 4,525 | +29% | 1 | 1 | 0% | 532 | 2,993 | +463% | 0 | 0 | — |
case-18 | pass→pass | 6,505 | 6,342 | -3% | 1 | 1 | 0% | 1,110 | 3,250 | +193% | 0 | 0 | — |
case-19 | pass→pass | 12,479 | 9,783 | -22% | 1 | 1 | 0% | 2,076 | 4,029 | +94% | 0 | 0 | — |
case-20 | pass→pass | 18,640 | 14,155 | -24% | 1 | 1 | 0% | 3,106 | 4,560 | +47% | 0 | 0 | — |
case-21 | pass→pass | 9,429 | 10,095 | +7% | 1 | 1 | 0% | 1,506 | 4,007 | +166% | 0 | 0 | — |
case-22 | pass→pass | 14,302 | 15,711 | +10% | 1 | 1 | 0% | 2,145 | 4,766 | +122% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted. The headline lift of +5 percentage points is the difference between those two pass rates over the 22 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.