How Server-Sent Events Solved the Long-Running AI Job Problem in the Browser
A developer rebuilding the spectr-ai contract audit tool found that users were refreshing the page after 90 seconds of seeing a spinner, inadvertently cancelling long-running AI audits. To fix this, the pipeline was rebuilt using Server-Sent Events (SSE), which streams real-time updates from server to client over plain HTTP without requiring WebSockets or bidirectional connections. A fixed vocabulary of four typed events — progress, partial-finding, done, and error — replaced an ad-hoc stream of raw model output, giving the frontend a stable, predictable API contract. Individual findings are now streamed to the browser as soon as they are validated server-side, reducing perceived wait time even when total processing time remains unchanged. The architecture also accounts for network interruptions by assigning monotonic IDs to every event and maintaining a replayable server-side log, allowing EventSource's built-in reconnection to resume mid-audit seamlessly.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in