Documentation Index
Fetch the complete documentation index at: https://mintlify.com/midudev/mundial-de-clicks/llms.txt
Use this file to discover all available pages before exploring further.
GET /api/stream opens a persistent Server-Sent Events (SSE) connection. The server pushes a serialized WorldSnapshot every STREAM_INTERVAL_MS (default 1 second, configurable via environment variable) whenever the ranking data has changed. When there are no updates — for example, during a lull in voting — the server emits a : ping keep-alive comment every 20 seconds instead, preventing proxies and load balancers from closing the idle connection.
Connection Limits
The server enforces two independent connection limits to protect against resource exhaustion:| Limit | Default | Env Variable | Exceeded Response |
|---|---|---|---|
| Global simultaneous connections | 20,000 | MAX_SSE_CONNECTIONS | 503 with retry-after: 5 |
| Connections per IP | 4 | MAX_SSE_CONNECTIONS_PER_IP | 429 with retry-after: 5 |
Response Format
Content-Type:text/event-streamCache-Control:
no-cache, no-transformConnection:
keep-alivex-accel-buffering:
no (disables nginx proxy buffering, ensuring events are flushed to the client immediately)
Each update is delivered as a standard SSE data: event containing a JSON-serialized WorldSnapshot. Keep-alive pings are delivered as SSE comment lines (: ping), which browsers ignore but which reset proxy idle timers.
WorldSnapshot structure is identical to the body returned by GET /api/ranking. Refer to that page for full field documentation.
Client Usage
The following is the actual implementation fromsrc/scripts/main.ts. The EventSource API handles reconnection automatically — no manual retry logic is needed.
The
EventSource API reconnects automatically on connection drop, using an exponential back-off defined by the browser. The server-side : ping heartbeat (emitted every 20 seconds when idle) keeps the TCP connection alive through intermediate proxies and load balancers that would otherwise close idle keep-alive connections.Broadcast Architecture
The SSE endpoint is designed so that adding more viewers does not increase load on DragonFly:- A single
WorldStateclass runs onesetIntervalloop ticking everySTREAM_INTERVAL_MS. - Each tick triggers exactly one
readWorld()call — a single DragonFly pipeline regardless of how many clients are connected. JSON.stringifyis called once per tick, and the result is encoded into aUint8Arrayonce.- That same
Uint8Arrayis pushed to every subscriber viacontroller.enqueue(payload)— no per-client serialization or allocation. - When there are zero subscribers, the poller skips the DragonFly read entirely, consuming no resources.
Backpressure Handling
If a client’s readable stream queue grows more than 20 frames behind the broadcaster (desiredSize < -20), the current frame is silently dropped for that client. The client does not receive an error or a gap notification.
This is safe because WorldSnapshot values are monotonically increasing (vote counts never decrease). The next frame the slow client receives will contain the correct current state — no reconciliation or replay is required.