top | item 43808388

(no title)

fefe23 | 10 months ago

This is an astonishingly bad idea. Don't do this.

Use HTTP server-sent events instead. Those can keep the connection open so you don't have to poll to get real-time updates and they will also let you resume from the last entry you saw previously.

https://developer.mozilla.org/en-US/docs/Web/API/Server-sent...

discuss

order

montroser|10 months ago

Yeah, but in real life, SSE error events are not robust, so you still have to do manual heartbeat messages and tear down and reestablish the connection when the user changes networks, etc. In the end, long-polling with batched events is not actually all that different from SSE with ping/pong heartbeats, and with long-polling, you get the benefit of normal load balancing and other standard HTTP things

mikojan|10 months ago

But SSE is a standard HTTP thing. Why would you not be able to do "normal load balancing"?

I would also rather not have a handful of long-polling loops pollute the network tab.

andersmurphy|10 months ago

Never had to use ping/pong with SSE. The reconnect is reliable. What you probably had happen was your proxy or server return a 4XX or 5XX and that cancels the retry. Don't do that and you'll be fine.

SSE works with normal load balancing the same as regular request/response. It's only stateful if you make your server stateful.

xyzzy_plugh|10 months ago

Correct. In the end, mechanically, nothing beats long polling. Everything ends up converging at which point you may as well just long poll.

Alifatisk|10 months ago

Isn't SSE limited to like 12 tabs or something? I remember vividly reading about a huge limitation on that hard limit.

curzondax|10 months ago

6 tabs is the limit on SSE. In my opinion Server Sent Events as a concept is therefore not usable in real world scenarios as of this limitation or error-detection around that limitation. Just use Websockets instead.