Instructions
Choose and sketch real-time delivery in Next.js (App Router Route Handlers or a dedicated Node service). Read realtime-transports.md before picking SSE vs WebSocket.
When to Use
- Use when notifications, live logs, progress, chat, or collaborative edits need a push channel.
- Prefer polling /
revalidatefirst if latency tolerance is seconds, not milliseconds. - Prefer
auth-handbookfor session or short-lived ticket minting. - Prefer
api-handbookfor upgrade failure error shapes.
- SSE: one-way server → browser; good for notifications, live logs, progress. CORS if cross-origin; reconnection with
Last-Event-IDwhen you implement resume. - WebSockets: full-duplex; chat, collaborative editing. Prefer a short-lived ticket minted server-side when cookie attachment on handshake is unreliable.
- Where it runs: default Node for long-lived connections; Edge is often wrong for fan-out - justify runtime per deployment.
- Scale: sticky sessions or shared pub/sub for multi-instance; document single-node limits.
- Backpressure: slow clients must not block the server - bounded queues, drop or disconnect policy.
- Abuse: rate-limit connects and messages on user-facing endpoints.
Outcomes
- Bullet decision: SSE vs WS for this feature + auth sketch + scaling note.
Output Rules
No toy chat without rate limits; mention abuse controls when user-facing.
Scope and boundaries
- In scope: protocol choice, handler shape, auth, scaling concepts.
- Out of scope: game netcode, WebRTC media.
Safety
- read-only by default; warn on unauthenticated WS accepting messages.
Troubleshooting
- SSE through proxy: buffering - disable nginx
proxy_bufferingwhere applicable (user infra). - WS 403 on handshake: cookie not sent - move to ticket or same-origin WS URL.
- Multi-instance missed events: missing pub/sub fan-out.
Related skills
auth-handbook- tickets and sessionsapi-handbook- errors and versioningobservability-handbook- connection metrics without PII
GitHub: https://github.com/bh611627/skillcodex/tree/main/skills/realtime-handbook/SKILL.md
npm: https://www.npmjs.com/package/@skillcodex/skills