[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M792KYY4QFNMY4ZR8H2H8CJJ":3,"skill-same:01M792KYY4QFNMY4ZR8H2H8CJJ":61},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":26,"commitSha":27,"skillDirectory":28,"forksCount":14,"repositoryHtmlUrl":29,"repositoryHomepageUrl":30,"ownerHtmlUrl":31,"ownerBlogUrl":32,"ownerDescription":33,"updatedAt":34,"install":35,"resources":48},"01M792KYY4QFNMY4ZR8H2H8CJJ","realtime-systems",null,"Build WebSocket, SSE and pub\u002Fsub features: presence, fan-out, reconnection and backpressure. Use when building WebSockets, SSE, pub\u002Fsub, presence, or live feeds.","poorvith-mp\u002Fskills-developer","poorvith-mp","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F277478855?v=4","01M78Z5K0YH1Z3PX815PGQ96ND","Poorvith M P","01M792ACSFXT45RJ69SSGKTVJN",0,"MIT","https:\u002F\u002Fgithub.com\u002Fpoorvith-mp\u002Fskills-developer\u002Fblob\u002Fmain\u002Fskills\u002Frealtime-systems\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: realtime-systems\nlast_reviewed: 2026-09-06\ngroup: Build\ndescription: >-\n  Build WebSocket, SSE and pub\u002Fsub features: presence, fan-out, reconnection and backpressure. Use\n  when building WebSockets, SSE, pub\u002Fsub, presence, or live feeds.\n---\n\n# realtime-systems\n\n## Core Philosophy\nRealtime systems are not simply regular HTTP request-response APIs wrapped in an infinite polling loop. True realtime architectures maintain persistent bidirectional or streaming connections (WebSockets, Server-Sent Events, gRPC streaming) governed by connection lifecycle management, heartbeat health checks, exponential backoff reconnection, horizontal pub\u002Fsub fanout, and strict backpressure handling to prevent server memory exhaustion.\n\n---\n\n## 4-Step Realtime Architecture Framework\n\n### Step 1: Protocol Selection Matrix\n1. **WebSockets vs Server-Sent Events (SSE) vs WebTransport**:\n   - *Server-Sent Events (SSE)*: Best for unidirectional server-to-client streaming (LLM token generation, live stock feeds, notification feeds). Operates over standard HTTP\u002F2, automatic reconnection, simple browser native API (`EventSource`).\n   - *WebSockets (WS\u002FWSS)*: Mandatory for low-latency bidirectional communication (collaborative editors, multiplayer games, interactive chat).\n   - *WebTransport \u002F UDP*: Extreme low-latency audio\u002Fvideo streaming and gaming.\n\n### Step 2: Connection Lifecycle & Heartbeat Management\n1. **Ping\u002FPong Heartbeat Protocol**:\n   - Fire server-side ping every 30 seconds:\n     ```javascript\n     ws.ping(); \u002F\u002F Expect pong response within 5 seconds\n     ```\n   - If 2 consecutive pongs are missed, terminate socket (`ws.terminate()`) to prevent ghost\u002Fzombie connection accumulation.\n2. **Client Reconnection with Jitter**:\n   - Never reconnect with fixed intervals (avoids the \"thundering herd\" problem when servers restart).\n   - Enforce Exponential Backoff with Jitter:\n     $$T_{text{wait}} = \\min(T_{text{max}}, T_{text{base}}  imes 2^{text{attempt}}) \\pm text{random_jitter}$$\n\n### Step 3: Horizontal Scaling & Pub\u002FSub Fanout\n1. **The Single-Node Bottleneck**:\n   - Sockets are stateful connections pinned to a single server process.\n2. **Redis \u002F NATS Pub\u002FSub Message Bus**:\n   - Decouple connection management from message broadcasting.\n   - When User A sends a message on Server 1:\n     - Server 1 publishes event to Redis channel `room:123`.\n     - Servers 2, 3, and 4 subscribe to `room:123` and broadcast the message to their locally connected sockets.\n\n### Step 4: Backpressure & Buffer Defense\n1. **Client Slow-Consumer Protection**:\n   - If a client connection throttles (e.g. mobile device in tunnel), the server output buffer will swell, leading to Out-Of-Memory (OOM) crashes.\n2. **Backpressure Controls**:\n   - Monitor socket buffer size (`ws.bufferedAmount`). If buffer exceeds 1MB, drop ephemeral messages (e.g. cursor positions) or pause ingestion until buffer drains.\n\n---\n\n## Deliverable Format: Realtime Architecture Spec (`REALTIME-SPEC.md`)\n\n```markdown\n# Realtime Communication System Specification: [Feature Name]\n\n## 1. Protocol & Infrastructure Architecture\n- **Selected Protocol**: WebSockets (`wss:\u002F\u002F`) \u002F Server-Sent Events (`text\u002Fevent-stream`)\n- **Transport Security**: TLS 1.3 enforced\n- **Pub\u002FSub Broker**: Redis Cluster \u002F NATS Core\n- **Target Concurrency**: 50,000 simultaneous active connections\n\n## 2. Horizontal Fanout Topology\n```mermaid\ngraph TD\n    Client1[Client A] \u003C-->|WSS| EdgeNode1[WebSocket Node 1]\n    Client2[Client B] \u003C-->|WSS| EdgeNode2[WebSocket Node 2]\n    EdgeNode1 \u003C-->|Pub\u002FSub| Broker[(Redis \u002F NATS Cluster)]\n    EdgeNode2 \u003C-->|Pub\u002FSub| Broker\n```\n\n## 3. Resilience & Heartbeat Specs\n- **Heartbeat Interval**: Ping every 30s | Pong timeout: 5s\n- **Client Backoff**: Base: 500ms, Max: 30s, Jitter: $\\pm 20\\%$\n- **Slow Consumer Policy**: Disconnect socket if `bufferedAmount` > 2MB for 10s.\n\n## 4. Message Framing Schema\n```json\n{\n  \"event\": \"room:message\",\n  \"room_id\": \"c1248\",\n  \"sender_id\": \"usr_99\",\n  \"sequence_id\": 14208,\n  \"payload\": {\n    \"text\": \"Hello world\"\n  }\n}\n```\n```\n\n---\n\n## Worked Example: Collaborative Document Presence Engine\n\n- **Challenge**: 1,000 engineers viewing the same document generated 1,000,000 cursor updates per minute, crashing Node.js servers.\n- **Solution**:\n  - Downsampled cursor broadcasts from 60Hz to 15Hz client-side.\n  - Implemented backpressure checking on socket buffer before pushing.\n  - Switched from JSON strings to compact binary Protobuf payloads.\n- **Outcome**: Server CPU dropped by 72%; memory usage stabilized under 300MB at 25,000 active connections.\n\n---\n\n## Verification Checklist\n\n- [ ] Ping\u002Fpong heartbeat terminates dead connections within 35 seconds.\n- [ ] Client reconnection implements exponential backoff with randomized jitter.\n- [ ] Horizontal scaling is backed by Redis or NATS pub\u002Fsub message broker.\n- [ ] Backpressure safeguards drop or throttle messages when client buffers overflow.\n- [ ] Connections operate strictly over encrypted protocols (`wss:\u002F\u002F` or HTTPS).\n\n---\n\n## Anti-Patterns\n\n- **Short-Polling pretending to be Realtime**: Hitting an API endpoint every 500ms from the browser.\n- **Memory Leaks from Event Listeners**: Forgetting to remove event listeners on socket disconnect, crashing the Node.js process.\n- **Broadcasting Everything to Everyone**: Sending all global events to all connected clients and filtering on the frontend.\n","# realtime-systems\n\n## Core Philosophy\nRealtime systems are not simply regular HTTP request-response APIs wrapped in an infinite polling loop. True realtime architectures maintain persistent bidirectional or streaming connections (WebSockets, Server-Sent Events, gRPC streaming) governed by connection lifecycle management, heartbeat health checks, exponential backoff reconnection, horizontal pub\u002Fsub fanout, and strict backpressure handling to prevent server memory exhaustion.\n\n---\n\n## 4-Step Realtime Architecture Framework\n\n### Step 1: Protocol Selection Matrix\n1. **WebSockets vs Server-Sent Events (SSE) vs WebTransport**:\n   - *Server-Sent Events (SSE)*: Best for unidirectional server-to-client streaming (LLM token generation, live stock feeds, notification feeds). Operates over standard HTTP\u002F2, automatic reconnection, simple browser native API (`EventSource`).\n   - *WebSockets (WS\u002FWSS)*: Mandatory for low-latency bidirectional communication (collaborative editors, multiplayer games, interactive chat).\n   - *WebTransport \u002F UDP*: Extreme low-latency audio\u002Fvideo streaming and gaming.\n\n### Step 2: Connection Lifecycle & Heartbeat Management\n1. **Ping\u002FPong Heartbeat Protocol**:\n   - Fire server-side ping every 30 seconds:\n     ```javascript\n     ws.ping(); \u002F\u002F Expect pong response within 5 seconds\n     ```\n   - If 2 consecutive pongs are missed, terminate socket (`ws.terminate()`) to prevent ghost\u002Fzombie connection accumulation.\n2. **Client Reconnection with Jitter**:\n   - Never reconnect with fixed intervals (avoids the \"thundering herd\" problem when servers restart).\n   - Enforce Exponential Backoff with Jitter:\n     $$T_{text{wait}} = \\min(T_{text{max}}, T_{text{base}}  imes 2^{text{attempt}}) \\pm text{random_jitter}$$\n\n### Step 3: Horizontal Scaling & Pub\u002FSub Fanout\n1. **The Single-Node Bottleneck**:\n   - Sockets are stateful connections pinned to a single server process.\n2. **Redis \u002F NATS Pub\u002FSub Message Bus**:\n   - Decouple connection management from message broadcasting.\n   - When User A sends a message on Server 1:\n     - Server 1 publishes event to Redis channel `room:123`.\n     - Servers 2, 3, and 4 subscribe to `room:123` and broadcast the message to their locally connected sockets.\n\n### Step 4: Backpressure & Buffer Defense\n1. **Client Slow-Consumer Protection**:\n   - If a client connection throttles (e.g. mobile device in tunnel), the server output buffer will swell, leading to Out-Of-Memory (OOM) crashes.\n2. **Backpressure Controls**:\n   - Monitor socket buffer size (`ws.bufferedAmount`). If buffer exceeds 1MB, drop ephemeral messages (e.g. cursor positions) or pause ingestion until buffer drains.\n\n---\n\n## Deliverable Format: Realtime Architecture Spec (`REALTIME-SPEC.md`)\n\n```markdown\n# Realtime Communication System Specification: [Feature Name]\n\n## 1. Protocol & Infrastructure Architecture\n- **Selected Protocol**: WebSockets (`wss:\u002F\u002F`) \u002F Server-Sent Events (`text\u002Fevent-stream`)\n- **Transport Security**: TLS 1.3 enforced\n- **Pub\u002FSub Broker**: Redis Cluster \u002F NATS Core\n- **Target Concurrency**: 50,000 simultaneous active connections\n\n## 2. Horizontal Fanout Topology\n```mermaid\ngraph TD\n    Client1[Client A] \u003C-->|WSS| EdgeNode1[WebSocket Node 1]\n    Client2[Client B] \u003C-->|WSS| EdgeNode2[WebSocket Node 2]\n    EdgeNode1 \u003C-->|Pub\u002FSub| Broker[(Redis \u002F NATS Cluster)]\n    EdgeNode2 \u003C-->|Pub\u002FSub| Broker\n```\n\n## 3. Resilience & Heartbeat Specs\n- **Heartbeat Interval**: Ping every 30s | Pong timeout: 5s\n- **Client Backoff**: Base: 500ms, Max: 30s, Jitter: $\\pm 20\\%$\n- **Slow Consumer Policy**: Disconnect socket if `bufferedAmount` > 2MB for 10s.\n\n## 4. Message Framing Schema\n```json\n{\n  \"event\": \"room:message\",\n  \"room_id\": \"c1248\",\n  \"sender_id\": \"usr_99\",\n  \"sequence_id\": 14208,\n  \"payload\": {\n    \"text\": \"Hello world\"\n  }\n}\n```\n```\n\n---\n\n## Worked Example: Collaborative Document Presence Engine\n\n- **Challenge**: 1,000 engineers viewing the same document generated 1,000,000 cursor updates per minute, crashing Node.js servers.\n- **Solution**:\n  - Downsampled cursor broadcasts from 60Hz to 15Hz client-side.\n  - Implemented backpressure checking on socket buffer before pushing.\n  - Switched from JSON strings to compact binary Protobuf payloads.\n- **Outcome**: Server CPU dropped by 72%; memory usage stabilized under 300MB at 25,000 active connections.\n\n---\n\n## Verification Checklist\n\n- [ ] Ping\u002Fpong heartbeat terminates dead connections within 35 seconds.\n- [ ] Client reconnection implements exponential backoff with randomized jitter.\n- [ ] Horizontal scaling is backed by Redis or NATS pub\u002Fsub message broker.\n- [ ] Backpressure safeguards drop or throttle messages when client buffers overflow.\n- [ ] Connections operate strictly over encrypted protocols (`wss:\u002F\u002F` or HTTPS).\n\n---\n\n## Anti-Patterns\n\n- **Short-Polling pretending to be Realtime**: Hitting an API endpoint every 500ms from the browser.\n- **Memory Leaks from Event Listeners**: Forgetting to remove event listeners on socket disconnect, crashing the Node.js process.\n- **Broadcasting Everything to Everyone**: Sending all global events to all connected clients and filtering on the frontend.\n",{"name":5,"group":24,"description":7,"last_reviewed":25},"Build",1788652800000,"main","f6a053c46d4bf0f779ea766c929b6f6f92c51765","skills\u002Frealtime-systems","https:\u002F\u002Fgithub.com\u002Fpoorvith-mp\u002Fskills-developer","https:\u002F\u002Fgithub.com\u002Fpoorvith-mp\u002Fskillary","https:\u002F\u002Fgithub.com\u002Fpoorvith-mp","poorvithmp.com","Shipping tools for problems people notice too late.","2026-10-02 21:32:22",{"source":8,"skillName":5,"commands":36,"prompt":46,"zipAvailable":47},[37,40,43],{"tool":38,"command":39},"npx","npx skills add poorvith-mp\u002Fskills-developer --skill realtime-systems",{"tool":41,"command":42},"bunx","bunx skills add poorvith-mp\u002Fskills-developer --skill realtime-systems",{"tool":44,"command":45},"pnpm","pnpm dlx skills add poorvith-mp\u002Fskills-developer --skill realtime-systems","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fpoorvith-mp\u002Fskills-developer\u002Fblob\u002Fmain\u002Fskills\u002Frealtime-systems\u002FSKILL.md",true,[49,55],{"path":50,"resourceType":51,"resourceTypeDesc":52,"sizeBytes":53,"sourceHtmlUrl":54},"evals\u002Frouting.yaml","REFERENCE","参考文档",840,"https:\u002F\u002Fgithub.com\u002Fpoorvith-mp\u002Fskills-developer\u002Fblob\u002Fmain\u002Fskills\u002Frealtime-systems\u002Fevals\u002Frouting.yaml",{"path":56,"resourceType":57,"resourceTypeDesc":58,"sizeBytes":59,"sourceHtmlUrl":60},"realtime-systems.skill","OTHER","其他",3288,"https:\u002F\u002Fgithub.com\u002Fpoorvith-mp\u002Fskills-developer\u002Fblob\u002Fmain\u002Fskills\u002Frealtime-systems\u002Frealtime-systems.skill",[62,69,76,83,90,97],{"skillNo":63,"name":64,"nameZh":6,"description":65,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":66,"categories":67,"keywords":68,"publishedAt":19},"01M792Q79X14YD94WXEEJY9GCW","workflow-optimizer","Moved to workflow-mapping in skills-agents. Removed in v4.1.","https:\u002F\u002Fgithub.com\u002Fpoorvith-mp\u002Fskills-developer\u002Fblob\u002Fmain\u002Fskills\u002Fworkflow-optimizer\u002FSKILL.md",[],[],{"skillNo":70,"name":71,"nameZh":6,"description":72,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":73,"categories":74,"keywords":75,"publishedAt":19},"01M792Q387DNC91VKEVM07SJM3","webhooks","Build webhook receivers with signature verification, idempotency, retries and dead letter queues. Use when implementing, verifying, or signing incoming\u002Foutgoing webhooks.","https:\u002F\u002Fgithub.com\u002Fpoorvith-mp\u002Fskills-developer\u002Fblob\u002Fmain\u002Fskills\u002Fwebhooks\u002FSKILL.md",[],[],{"skillNo":77,"name":78,"nameZh":6,"description":79,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":80,"categories":81,"keywords":82,"publishedAt":19},"01M792PZW0SM71X7V9709ZWHCR","webhook-handler-builder","Moved to webhooks in skills-developer. Removed in v4.1.","https:\u002F\u002Fgithub.com\u002Fpoorvith-mp\u002Fskills-developer\u002Fblob\u002Fmain\u002Fskills\u002Fwebhook-handler-builder\u002FSKILL.md",[],[],{"skillNo":84,"name":85,"nameZh":6,"description":86,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":87,"categories":88,"keywords":89,"publishedAt":19},"01M792PW7XPB7J9S0QSS52JXZV","voice-ai-integration-engineer","Moved to speech-pipelines in skills-developer. Removed in v4.1.","https:\u002F\u002Fgithub.com\u002Fpoorvith-mp\u002Fskills-developer\u002Fblob\u002Fmain\u002Fskills\u002Fvoice-ai-integration-engineer\u002FSKILL.md",[],[],{"skillNo":91,"name":92,"nameZh":6,"description":93,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":94,"categories":95,"keywords":96,"publishedAt":19},"01M792PRZ5GSAQ1P2999V9XAJ5","typescript-migrator","Moved to port-code in skills-developer. Removed in v4.1.","https:\u002F\u002Fgithub.com\u002Fpoorvith-mp\u002Fskills-developer\u002Fblob\u002Fmain\u002Fskills\u002Ftypescript-migrator\u002FSKILL.md",[],[],{"skillNo":98,"name":99,"nameZh":6,"description":100,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":101,"categories":102,"keywords":103,"publishedAt":19},"01M792PQDARKP00V8Z3GYD4QZP","trigger-dev","Moved to trigger-dev in skills-agents. Removed in v4.1.","https:\u002F\u002Fgithub.com\u002Fpoorvith-mp\u002Fskills-developer\u002Fblob\u002Fmain\u002Fskills\u002Ftrigger-dev\u002FSKILL.md",[],[]]