webpapaya
webpapaya

Reputation: 809

Why are Websockets faster than Server Sent Events

Hi I currently came accross this paper and I can't figure out why Server-Sent Events are slower for pushing data from a server to a client.

I can see the point that SSE are slower for bidirectional communication like a chat applikation because of the HTTP overhead for XHR.

Upvotes: 3

Views: 5772

Answers (2)

nowucca
nowucca

Reputation: 474

I think there are two effects combining here to cause the claim that WebSockets are "faster" than SSE.

Effect 1: SSE has a Lower Payload to Message Ratio As you noted, in general, the overhead of HTTP requests/responses is larger, compared to a more compact payload and careful protocol design with WebSockets, in a bi-directional communication pattern.

Effect 2: SSE can involve Session Reconnections As @alexsergeyev points out correctly, SSE sessions can reconnect, but in most modern browsers that simply means SSE sessions do get re-created using pooled TCP connections, so the effect on

Combining these two effects, and defining throughput in bytes/second as the metric, I hope we can see that even for uni-directional server to client communication, throughput is better for WebSockets due to both these effects.

As far as I know, as the adoption of WebSocket-aware intermediaries takes off, the role for SSE will be reduced as time goes on. Right now, if you rely on HTTP for your security story, you might choose SSE unless you have hard-real-time requirements. If you do, the Kaazing Enterprise WebSocket gateway has built-in SSO integration for most security systems.

Upvotes: 4

alexsergeyev
alexsergeyev

Reputation: 535

If you look at charts on page 6, you'll see that the claim is based mostly on "server updates" being slower on SSE.

Which is true since server-side events is a technology of pushing data to client, not for sending data to server! Those require new HTTP requests and, likely, establishing new TCP (sometimes TLS) connection which is quite expensive for satellite link and for mobile devices with slow CPU and memory.

That allows authors of the paper to argue that websocket is faster which is not quite correct conclusion to state universally, regardless of the type of the interactions and transferred data.

I am not comparing features here. Websocket and SSE clearly solving similar but different problems and should be assessed to be applicable for particular project, there should not be an universal answer to use one or another.

Upvotes: 4

Related Questions