- Home
- Skills
- Ariegoldkin
- Ai Agent Hub
- Streaming Api Patterns
streaming-api-patterns_skill
- TypeScript
8
GitHub Stars
1
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill ariegoldkin/ai-agent-hub --skill streaming-api-patterns- SKILL.md6.5 KB
Overview
This skill teaches robust real-time streaming patterns using Server-Sent Events (SSE), WebSockets, and the ReadableStream API in TypeScript. It focuses on practical techniques for LLM streaming, backpressure control, reconnection strategies, and production-ready performance tuning. You will get clear patterns for one-way, bidirectional, and high-throughput streaming suited for 2025+ real-time applications.
How this skill works
Implementations show how to expose ReadableStream-based endpoints that push SSE frames, run WebSocket servers for two-way messaging, and produce controlled streams that respect consumer backpressure. The skill demonstrates reading streamed LLM responses, encoding tokens into SSE frames, and client-side readers that decode and process incremental data. It also covers reconnection logic, keepalive heartbeats, and flow control to avoid buffer exhaustion and ensure stable delivery.
When to use it
- Deliver incremental LLM responses to a web UI (token-by-token streaming)
- Broadcast real-time notifications, analytics, or market data from server to many clients
- Support chat or collaborative editors with low-latency bidirectional updates
- Stream progress for long-running tasks and provide live progress bars
- Process large datasets with backpressure-aware pipelines on the server
Best practices
- Use SSE for simple server-to-client streams and WebSockets for bidirectional needs
- Implement exponential backoff reconnection and send periodic keepalive frames
- Respect backpressure via ReadableStream controllers and pause production when consumers are slow
- Compress and batch small messages; prefer binary formats (MessagePack/Protobuf) for heavy payloads
- Validate and sanitize all incoming WebSocket messages and monitor connection counts
Example use cases
- Streaming chat UI that renders tokens as the LLM returns them
- Live dashboard feeding fast telemetry (stock ticks, metrics) to many viewers
- Real-time collaborative text editor syncing changes via WebSockets
- Backend pipeline that streams large file transforms with controlled flow
- Progress streaming for background jobs (builds, data processing) to client UIs
FAQ
Choose SSE for simple, server-to-client event streams with automatic browser reconnection; choose WebSockets when you need true bidirectional, low-latency communication.
How do I avoid overflowing client buffers?
Implement ReadableStream flow control: monitor consumer speed, pause production when queued bytes exceed thresholds, and implement timeouts for slow consumers.
What reconnection strategy is recommended?
Use exponential backoff with a reset on successful message receipt, and include jitter to avoid thundering herd reconnections.