c24165b8bc
에이전트 8종(대화형/프로그래머 C·S/디자이너/설계자/기획자/QA/PD/PM)에게 [공통 기본 능력 + 롤별 Specialty] 2층으로 지식을 주입하기 위한 재분류. 문서 내용·포맷은 무수정, 폴더 이동만 (6,372개 문서 수 보존 확인). - Topic_Programming → Domain_Programming (내부 구조 보존) - Topic_Graphic → Domain_Design - Topic_Business → Domain_Product - Topic_General → Domain_General - _Common 신설: Math(구 Topic_Math_Specialty), Reasoning(구 General/From_Thinking & Reasoning), Reasoning_Creativity(구 General/From_창의성), Communication(Poetic_Blog_Writing + From_writing) - 타 도메인의 From_* 폴더는 유지 (출처 표기일 뿐, 이미 도메인에 맞게 분류된 문서) - 빈 폴더 정리 (memory/procedures) - 에이전트→폴더 매핑은 workspace의 .astra/agent-knowledge-map.json (9개 에이전트) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
5.6 KiB
5.6 KiB
id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, tech_stack
| id | title | category | status | canonical_id | aliases | duplicate_of | source_trust_level | confidence_score | verification_status | tags | raw_sources | last_reinforced | github_commit | tech_stack | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| wiki-2026-0508-websockets-and-realtime | WebSockets and Realtime | 10_Wiki/Topics | verified | self |
|
none | A | 0.9 | applied |
|
2026-05-10 | pending |
|
WebSockets and Realtime
매 한 줄
"매 single TCP connection over HTTP upgrade — 매 full-duplex, low-overhead binary/text framing 의 realtime 표준". 2011 RFC 6455, 2026 WebTransport (HTTP/3) 가 등장했지만 WS 는 여전히 ubiquitous. 매 chat, collaborative editing, live dashboards, gaming 의 backbone.
매 핵심
매 Lifecycle
- HTTP
GET+Upgrade: websocket+Sec-WebSocket-Key. - Server 의
101 Switching Protocols+Sec-WebSocket-Accept. - Frame-based (text=0x1, binary=0x2, ping=0x9, pong=0xA, close=0x8).
- Full-duplex 까지 매 connection 의 close.
매 Scaling challenges
- Sticky session 또는 pub/sub fanout: 매 connection 의 single node binding.
- Backpressure: slow client → memory bloat.
bufferedAmountwatch. - Reconnect + resume: client state 의 server-side snapshot.
- Auth: query token (logged in proxies) vs. first-message handshake (recommended).
매 대안 매트릭스
- SSE: server → client only, simpler, HTTP/2 multiplexed.
- WebTransport: HTTP/3, datagrams + streams, 매 future.
- Long polling: legacy fallback.
매 응용
- Chat / collaborative docs (Yjs, Liveblocks).
- Trading / live odds / dashboards.
- Multiplayer game (low-tick) — 매 보통 UDP/WebTransport 가 더 좋음.
- AI streaming (token-by-token, 매 SSE 가 더 흔함).
💻 패턴
Bun WebSocket server (high perf)
Bun.serve<{ userId: string }>({
port: 3000,
fetch(req, server) {
const userId = verifyJWT(new URL(req.url).searchParams.get('token'));
if (!userId) return new Response('unauth', { status: 401 });
if (server.upgrade(req, { data: { userId } })) return;
return new Response('expected ws', { status: 400 });
},
websocket: {
open(ws) { ws.subscribe(`user:${ws.data.userId}`); },
message(ws, msg) {
const { room, body } = JSON.parse(msg as string);
ws.publish(`room:${room}`, JSON.stringify({ from: ws.data.userId, body }));
},
close(ws) { /* cleanup */ },
},
});
Client with auto-reconnect
class RealtimeClient {
private ws?: WebSocket;
private retry = 0;
connect() {
this.ws = new WebSocket(`wss://api/rt?token=${this.token}`);
this.ws.onopen = () => { this.retry = 0; this.flush(); };
this.ws.onmessage = (e) => this.dispatch(JSON.parse(e.data));
this.ws.onclose = () => {
const delay = Math.min(30_000, 2 ** this.retry++ * 1000) + Math.random() * 500;
setTimeout(() => this.connect(), delay);
};
}
send(obj: unknown) {
if (this.ws?.readyState === 1) this.ws.send(JSON.stringify(obj));
else this.queue.push(obj);
}
}
Redis pub/sub fanout (multi-node)
const sub = redis.duplicate();
await sub.subscribe('room:*', (msg, channel) => {
const room = channel.split(':')[1];
server.publish(`room:${room}`, msg); // 매 local connections 만
});
// publisher (any node)
await redis.publish(`room:${room}`, JSON.stringify(payload));
Heartbeat + dead connection detection
setInterval(() => {
for (const ws of server.publishToSubscribers) {
if (Date.now() - ws.data.lastPong > 60_000) ws.close(1011, 'stale');
else ws.ping();
}
}, 30_000);
Yjs collaborative doc
import * as Y from 'yjs';
import { WebsocketProvider } from 'y-websocket';
const doc = new Y.Doc();
const provider = new WebsocketProvider('wss://yjs.example/sync', `doc:${docId}`, doc);
const text = doc.getText('content');
text.observe(e => render(text.toString()));
text.insert(0, 'Hello'); // 매 CRDT-merged 매 모든 client
Backpressure
ws.send(payload);
if (ws.bufferedAmount > 1_000_000) {
ws.close(1013, 'backpressure'); // drop slow client
}
매 결정 기준
| 상황 | Approach |
|---|---|
| Server → client only stream | SSE (simpler, HTTP/2) |
| Bidirectional, < 10k conn / node | WebSocket on Bun/Node |
| 100k+ conn / node | uWebSockets.js, Go (gobwas/ws), Rust |
| Managed pub/sub | Centrifugo, Ably, Pusher |
| Collab editing | Yjs / Automerge over WS |
| Low-latency game | WebTransport (HTTP/3) |
기본값: WSS + JWT in first message + Redis pub/sub fanout + 30s heartbeat + exponential reconnect.
🔗 Graph
- 부모: Realtime-Communication · HTTP
- 변형: Server-Sent-Events · WebTransport
- Adjacent: Redis-PubSub · CRDT · WebHooks_and_Notifications
🤖 LLM 활용
언제: server scaffolding, reconnect logic, fanout pattern. 언제 X: 매 production-scale tuning (kernel, ulimit, TLS termination) — empirical.
❌ 안티패턴
- No heartbeat: 매 NAT/proxy 의 silent close → zombie connections.
- Token in URL query: 매 server log 의 leak. Use first-message handshake.
- Synchronous DB call in onmessage: blocks event loop.
- Per-connection in-memory state w/o backup: 매 node restart → data loss.
- No backpressure check: slow client OOMs server.
🧪 검증 / 중복
- Verified (RFC 6455, Bun/uWS docs, Yjs/Centrifugo prod patterns).
- 신뢰도 A.
🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — Bun WS + reconnect + Redis fanout 패턴 |