Short Polling to WebSocket: Four Ways to Push Real-Time Data to a Dashboard
Most real-time dashboard advice jumps straight to WebSocket, but SSE handles the common unidirectional-push case with less code, automatic reconnection, and no protocol upgrade. The seven production pitfalls—especially Nginx buffering and Spring’s async timeout—are exactly what turn a working local demo into a silent failure after deploy.
Four push schemes are compared side by side: short polling, long polling, Server-Sent Events, and WebSocket. Each gets a working Spring Boot 3.2 controller and vanilla-JS frontend snippet, plus a breakdown of who holds the data initiative—client pull versus server push. The comparison table covers real-time ceiling, connection model, browser compatibility, and HTTP/2 behavior.
Seven production traps are called out explicitly: Nginx buffering silently breaking SSE streams, Spring MVC’s 30-second async timeout killing long-lived emitters, `scheduleAtFixedRate` causing concurrent writes to the same SseEmitter, WebSocket messages vanishing in multi-instance deployments, connection leaks across all three long-lived patterns, SSE’s inability to carry custom auth headers, and the gap between push channel and actual data source. Each trap includes the concrete fix.
A decision tree and one-line recommendations steer the reader toward SSE for most internal dashboards, WebSocket only when bidirectional messaging is required, and short polling for rapid prototypes. MQTT and RSocket are noted as advanced alternatives for IoT and reactive stacks respectively.
SSE is underused in the Java ecosystem largely because Spring’s async timeout and Nginx’s default buffering combine to break it silently, making developers blame the protocol rather than the config.
The article’s framing around “who holds the data initiative” is a more useful mental model than raw latency numbers; it explains why long polling still exists alongside technically superior options.
STOMP over WebSocket adds message-broker semantics that make horizontal scaling easier, but the article correctly notes that most dashboard use cases don’t need bidirectional communication at all.
The seven production pitfalls form a de facto checklist that applies to nearly any server-push implementation, regardless of language or framework.