A server that has something new for its clients has four common ways to tell them. It can keep a WebSocket open and write a message; keep an HTTP response open as a Server-Sent Events (SSE) stream and write a line; leave a client’s long-poll request hanging and answer it when there is news; or publish to an MQTT broker, which forwards to every subscribed client, in a browser over MQTT-over-WebSocket. All four run over TCP and TLS, so the interesting differences are in what each adds on top: framing, round trips, and what happens when a connection drops. (MQTT is explained in its own article; MQTT vs HTTPS measures the other direction, devices sending to a server.)
Everything below was measured on one machine, in Docker, with one server implementation family, the same TLS settings and certificate, and the same emulated links. Every event carries its sequence number and a payload derived from it, and every client checks every byte: 61,210,694 events delivered, 0 corrupted.
Setup
Details
Event server
Go 1.24.13, net/http + github.com/coder/websocket v1.8.15 (permessage-deflate off, its default), one process on one core · WebSocket at /ws, SSE at /sse, long-poll at /poll, all HTTP/1.1
MQTT broker
Mosquitto 2.1.2 (eclipse-mosquitto:2), its own WebSocket listener with TLS for the clients, one core, defaults otherwise (20 messages in flight per client, 1,000 queued, Nagle’s algorithm on) · a second instance with set_tcp_nodelay true, the only setting changed, for the QoS 1 throughput and reconnect cells (nodelay) · the Go server publishes each event into it over TLS on the server’s loopback, so that hop never crosses the link
Clients
Go 1.24.13: coder/websocket, the net/http client for SSE and long-poll, a minimal MQTT 5 client over coder/websocket (one WebSocket message per MQTT packet) · every client on its own TLS connection
TLS
1.3 everywhere, one ECDSA P-256 certificate, key exchange X25519MLKEM768 (Go’s default), no session resumption
Event
32 bytes (a small JSON notification) or 1 KiB · framed as each protocol needs: one WebSocket text message; SSE id: + data: lines; long-poll: a 200 response whose body is the events since the client’s cursor; MQTT PUBLISH on a 2-byte topic
Network
Two network namespaces, server and client, on a Docker bridge at a 1,500-byte MTU, segmentation offloads off · links emulated with tc netem on both sides: LAN (nothing added), 50 ms round trip, 200 ms round trip with 1 % random loss in each direction
CPU
AMD Ryzen AI Max+ 395 · cores 0–7 reserved for the benchmark · Go server on core 2, Mosquitto on core 3, clients on cores 4–7
Method
Every cell is a fresh client process, run 5 times · reported value: median of the 5 run medians, with min–max · latency p99: each run’s 99th percentile, median across runs · bytes counted at the client for client↔server traffic only, IP packets with all headers, both directions · one warm-up event before measuring · a wait for a quiet link before every cell · TCP keep-alive probes off, so idle cost is the protocol’s own
The scoreboard
Eight headline measures from the sections below, each mechanism's median as a multiple of the best median for that measure (1×; log scale, a longer bar is worse), labelled with the measured value. Median of 5 process runs; grey line: lowest to highest run. Bytes: both directions on an open connection. Idle hour: one keep-alive exchange at the interval named in that section. Fan-out: time until the last of 5,000 clients has the event. Catch-up: from the new dial until every missed event is in.Eight headline measures from the sections below, each mechanism's median as a multiple of the best median for that measure (1×; log scale, a longer bar is worse), labelled with the measured value. Median of 5 process runs; grey line: lowest to highest run. Bytes: both directions on an open connection. Idle hour: one keep-alive exchange at the interval named in that section. Fan-out: time until the last of 5,000 clients has the event. Catch-up: from the new dial until every missed event is in.
Measure
WebSocket
SSE
Long-poll
MQTT QoS 0
MQTT QoS 1
Latency, 50 ms link
25.2 ms 25.0–25.2 ms
25.2 ms 25.0–25.2 ms · same
25.1 ms 25.0–25.2 ms · same
25.2 ms 25.1–25.3 ms · same
25.3 ms 25.1–25.3 ms · same
Bytes per 32-byte event
160 B 160–180 B
179 B 179 B · 0.89×
418 B 418 B · 0.38×
167 B 167 B · 0.96×
253 B 253 B · 0.63×
Bytes per 1 KiB event
1,154 B 1,154 B
1,172 B 1,172 B · 0.98×
1,412 B 1,412 B · 0.82×
1,162 B 1,162 B · 0.99×
1,248 B 1,248 B · 0.92×
Idle hour at default interval
25.2 KB 25.2 KB
32.2 KB 32.2 KB · 0.78×
41.6 KB 41.6 KB · 0.61×
12.7 KB 12.7 KB · 2.0×
measured at QoS 0 only
Fan-out to 5,000 clients, LAN
57.9 ms 54.1–58.4 ms
53.0 ms 49.8–61.1 ms · 1.1×
73.1 ms 72.3–94.7 ms · 0.79×
49.8 ms 48.8–59.9 ms · 1.2×
measured at QoS 0 only
Events/s, LAN
234,751 200,484–356,550
490,846 431,450–949,209 · 2.1×
770,959 611,181–804,090 · 3.3×
311,819 270,017–331,861 · 1.3×
102,966 90,977–104,139 · 0.44×
Events/s, 50 ms link
87,689 79,622–271,356
467,412 431,523–475,372 · 5.3×
19,225 19,102–19,287 · 0.22×
303,614 130,641–320,344 · 3.5×
201 201 · 0.0023×
Catch-up after a drop, 200 ms
805 ms 804–806 ms
606 ms 606 ms · 1.3×
605 ms 605–1,111 ms · 1.3×
QoS 0 has no persistent session
2,187 ms 2,087–2,289 ms · 0.37×
Median of 5 process runs, lowest to highest run beneath; bold: best in every run; after the range, the factor against WebSocket: above 1× better than WebSocket, below 1× worse, same: rounds to 1×.
Counting a measure only where every run agrees, against WebSocket: SSE is better on 3 (up to 5.3× on events/s, 50 ms link), worse on 2 (down to 0.78× on idle hour at default interval) and ties on 3; Long-poll is better on 1 (up to 3.3× on events/s, LAN), worse on 5 (down to 0.22× on events/s, 50 ms link) and ties on 2; MQTT QoS 0 is better on 2 of its 7 (up to 3.5× on events/s, 50 ms link), worse on 1 (down to 0.99× on bytes per 1 KiB event) and ties on 4; MQTT QoS 1 is never better: worse on 5 of its 6 (down to 0.0023× on events/s, 50 ms link) and ties on 1. The sections below take each measure in turn, with the LAN and the lossy link, each direction of the bytes, the smaller fan-outs, the nodelay broker and the runs behind every median.
Each mechanism's median against WebSocket's on the same measure, log scale; above 1× it is better than WebSocket (faster, fewer bytes or more events per second). Median of 5 process runs.Each mechanism's median against WebSocket's on the same measure, log scale; above 1× it is better than WebSocket (faster, fewer bytes or more events per second). Median of 5 process runs.
The four mechanisms
WebSocket upgrades an HTTP/1.1 request into a two-way message channel. Each event is one frame with a 2-byte header from the server (clients add a 4-byte mask on frames they send). It has ping and pong frames but no notion of event IDs: resuming after a drop is the application’s job. Here the client reconnects with ?after=<last id> and the server replays from its log.
Server-Sent Events is one long HTTP response of text lines, id: 41 then data: … then a blank line. The client side (EventSource in a browser) reconnects by itself and sends the last ID it saw in a Last-Event-ID header, so resuming is built in.
Long-polling is plain HTTP: the client asks “anything after 41?”, and the server holds the request open until there is, then answers with everything new. The client immediately asks again. Every event costs a request and a response, headers and all; the cursor makes resuming free.
MQTT over WebSocket puts a broker between the server and the clients. The server publishes once; the broker keeps a connection to every subscriber. At QoS 0 events are fire-and-forget; at QoS 1 each one is acknowledged, and a client that reconnects with a persistent session gets what it missed from the broker’s queue.
Delivery latency
From the server handing an event to the transport until the client has it, one event at a time:
One 32-byte event at a time, from the server handing it to the transport until the client has it. Median of 5 process runs × 100 events (LAN) or 40 (slow links). Each link has its own scale; RTT = round trips at that link's delay. MQTT includes the hop from the event source into the broker, on the server's loopback.One 32-byte event at a time, from the server handing it to the transport until the client has it. Median of 5 process runs × 100 events (LAN) or 40 (slow links). Each link has its own scale; RTT = round trips at that link's delay. MQTT includes the hop from the event source into the broker, on the server's loopback.
On an open connection all four deliver in half a round trip: the event crosses the link once. On the 50 ms link that is 25.2 ms for WebSocket, 25.2 ms for SSE, 25.1 ms for long-poll and 25.2 ms for MQTT QoS 0. On the LAN every median is at most 133 µs, and the run medians overlap (WebSocket 38–219 µs, MQTT QoS 0 84–380 µs), so the extra hop through the broker, on the server’s loopback, does not show at this scale.
Long-poll matches the others here only because each event was sent after the client’s next request had arrived at the server. When events come closer together than one round trip, the second one waits for the client’s next request to arrive, and its latency grows from half a round trip towards a full one. The throughput section shows the same effect from the other side.
Same measurement on the 200 ms link with 1 % random loss in each direction. Solid bar: median; lighter extension: 99th percentile of all 200 events of the 5 runs together (one run's 40 events are too few for a 1 % tail). On the 50 ms link without loss each run's 99th percentile stays within 0.2 ms of the median for every row.Same measurement on the 200 ms link with 1 % random loss in each direction. Solid bar: median; lighter extension: 99th percentile of all 200 events of the 5 runs together (one run's 40 events are too few for a 1 % tail). On the 50 ms link without loss each run's 99th percentile stays within 0.2 ms of the median for every row.
Loss shows in the tail. On the 200 ms link with 1 % loss the medians stay at the one-way delay, but the 99th percentile of all 200 events per protocol ranges from 100–109 ms. At that sample size a 1 % tail is two events, so the spread says which protocol happened to lose a packet, not which handles loss better: a lost TCP segment is resent only after a retransmission timeout, and everything behind it on the connection waits. MQTT’s QoS 1 acknowledgement does not help; it sits on the same TCP.
Bytes per event
On a connection that is already open, how many bytes does one event cost, counting both directions?
Connection already open, one event at a time, both directions counted at the client (IP packets, all headers). Median of 5 process runs × 100 events (32 B) or 50 (1 KiB). Down: the event, as each protocol frames it, with TLS. Up: TCP acknowledgements, MQTT QoS 1's PUBACK, long-poll's next request.Connection already open, one event at a time, both directions counted at the client (IP packets, all headers). Median of 5 process runs × 100 events (32 B) or 50 (1 KiB). Down: the event, as each protocol frames it, with TLS. Up: TCP acknowledgements, MQTT QoS 1's PUBACK, long-poll's next request.
Underneath every event is the same floor: 52 bytes of IPv4 and TCP headers per packet and 22 bytes of TLS framing per record, plus the 32-byte payload. On top of that:
WebSocket adds a 2-byte frame header: 108 B down. The only upstream traffic is the client’s TCP acknowledgement, 52 B.
MQTT QoS 0 wraps a PUBLISH (2-byte header, the 2-byte topic with its length, 1 byte of properties) in a WebSocket frame: 115 B down. QoS 1 sends a PUBACK back for every event: 84 B up instead of 52 B.
SSE spends its overhead on text, id: and data: and newlines, plus HTTP/1.1 chunked encoding around each write: 127 B down.
Long-poll answers with a full HTTP response and gets a full HTTP request back: 260 B down and 158 B up, 2.6× the WebSocket total.
At 1 KiB the framing is noise for the three streams, 1,154 B for WebSocket against 1,172 B for SSE, while long-poll still carries its 258 B of headers per event. The Go client’s request is lean (Host, User-Agent, Accept-Encoding); a browser’s, with cookies, is often a kilobyte more.
The cost of an idle connection
Most push connections spend most of their time silent. They still have to speak now and then, because proxies, load balancers and NAT routers close connections they think are dead. One keep-alive exchange per protocol, multiplied out to an hour at a common default interval:
One keep-alive exchange measured on an open connection (5 process runs × 10 exchanges, both directions, TCP acknowledgements included), multiplied out to an hour at the interval shown. MQTT here is MQTT over WebSocket.One keep-alive exchange measured on an open connection (5 process runs × 10 exchanges, both directions, TCP acknowledgements included), multiplied out to an hour at the interval shown. MQTT here is MQTT over WebSocket.
The intervals are conventions, not part of the protocols: the HTML standard suggests an SSE comment about every 15 seconds; 30 seconds is a common WebSocket ping interval and a common long-poll hold time; 60 seconds is the usual MQTT keep-alive. Per exchange:
SSE: one comment line, one way: 134 B.
WebSocket: a ping from the server and a pong back: 210 B.
MQTT: PINGREQ from the client, PINGRESP back, each in a WebSocket frame: 212 B.
Long-poll: the held request answered 204 No Content, and a new request: 347 B.
Even the most expensive is 41.6 KB an hour. Multiplied by a hundred thousand mostly idle clients it is not nothing, but the interval a deployment needs, set by the shortest timeout anywhere on the path, matters more than the protocol.
One event to many clients
One event, delivered to every connected client, each on its own TLS connection:
One event to every client, each on its own TLS connection, time until the last one has it; median of 5 process runs × 10 events (1 client: the latency cells). Each link has its own scale; on the lossy link the largest count is 1,000. The Go server and Mosquitto each run on one core.One event to every client, each on its own TLS connection, time until the last one has it; median of 5 process runs × 10 events (1 client: the latency cells). Each link has its own scale; on the lossy link the largest count is 1,000. The Go server and Mosquitto each run on one core.
All four write one encrypted copy per client, so the time until the last one has it grows with the number of clients, and with one core per server the core is what runs out. 5,000 clients were measured on the LAN only (the lossy link stopped at 1,000, to keep the run within its time budget). There the last client had the event after 49.8–57.9 ms for WebSocket, SSE and MQTT, whose runs overlap (48.8–61.1 ms across runs, so no order among the three), and 73.1 ms for long-poll (runs 72.3–94.7 ms), which also completes a request per client per event, and every client then sends a new one, which the same core has to take in.
On the lossy link, delivering to everyone means waiting for the unluckiest connection: with 1,000 clients some packet is almost always lost, and the last client waits for its retransmission (559 ms for WebSocket, half of the clients had it after 104 ms).
Events per second on one connection
How fast can one connection carry events, if the server has a backlog? The server emits 32-byte events as fast as each transport accepts them, 3 seconds on the LAN and 5 on the slow links:
The server emits 32-byte events as fast as the transport accepts them for 5 s on the 50 ms link; events delivered per second, median of 5 runs. Log scale: each gridline is 10× the previous one. Long-poll's response holds at most 1,000 events (this server's cap), so its ceiling on this link is 20,000/s. The table below has every link.The server emits 32-byte events as fast as the transport accepts them for 5 s on the 50 ms link; events delivered per second, median of 5 runs. Log scale: each gridline is 10× the previous one. Long-poll's response holds at most 1,000 events (this server's cap), so its ceiling on this link is 20,000/s. The table below has every link.
Events/s
LAN
50 ms
200 ms 1 % loss
WebSocket
234,751 200,484–356,550
87,689 79,622–271,356
4,159 1,875–7,463
SSE
490,846 431,450–949,209
467,412 431,523–475,372
3,968 1,883–5,983
Long-poll
770,959 611,181–804,090
19,225 19,102–19,287
3,769 2,678–4,022
MQTT QoS 0
311,819 270,017–331,861
303,614 130,641–320,344
2,488 1,332–5,370
MQTT QoS 1
102,966 90,977–104,139
201 201–201
46 45–49
MQTT QoS 1 nodelay
104,510 91,274–105,326
399 398–399
69 67–72
On the LAN this measures software: TLS, framing, the broker. On the slow links it measures what each protocol lets be in flight:
WebSocket and SSE are plain streams: the server writes as fast as TCP’s window allows. SSE batches what is queued into one write; WebSocket writes one frame at a time.
Long-poll delivers one batch per round trip, and a batch holds whatever piled up, so under load it streams too. This server caps a response at 1,000 events, so on the 50 ms link the ceiling is 20,000 events/s; it reached 19,225. That number is the cap, not the protocol: a larger batch would raise it, and the LAN column, where round trips are free, is what the server and TLS can do.
MQTT QoS 0 has no acknowledgements, so TCP is the only limit, and nothing slows the server down to the client’s pace: when the client falls behind, the broker drops. 6.2 % of the events sent were dropped on the 50 ms link.
MQTT QoS 1 may have only 20 unacknowledged messages in flight per client (Mosquitto’s max_inflight_messages), at most 20 per round trip: 400 events/s at 50 ms. It got 201. Mosquitto leaves Nagle’s algorithm on by default, so the broker holds back small writes until earlier ones are acknowledged, and the window refills late; the second broker with set_tcp_nodelay true delivered 399 events/s. The event source publishes far faster than that, so the broker’s queue of 1,000 messages per client overflows and it drops the rest: 99.8 % of the events sent on the 50 ms link.
The table counts only events delivered.
Reconnecting after a dropped connection
Connections drop: a phone changes network, a laptop sleeps, a proxy restarts. Here the client resets its TCP connection without warning, stays away for two seconds while the server keeps emitting 20 events a second, then reconnects and resumes:
A 20 events/s stream; the client resets its connection, stays away 2 s, reconnects and resumes: WebSocket with an app-level ?after= cursor, SSE with Last-Event-ID, long-poll with its cursor, MQTT with a persistent session at QoS 1. Time from the new dial until every event emitted before it is in; median of 5 process runs × 2 reconnects. Each link has its own scale.A 20 events/s stream; the client resets its connection, stays away 2 s, reconnects and resumes: WebSocket with an app-level ?after= cursor, SSE with Last-Event-ID, long-poll with its cursor, MQTT with a persistent session at QoS 1. Time from the new dial until every event emitted before it is in; median of 5 process runs × 2 reconnects. Each link has its own scale.
After a drop
LAN
50 ms
200 ms 1 % loss
Bytes to resume (200 ms link)
WebSocket
5.71 ms 4.80 ms–5.94 ms
205 ms 204 ms–205 ms
805 ms 804 ms–806 ms
8.3 KB
SSE
4.95 ms 4.10 ms–5.51 ms
155 ms 155 ms–156 ms
606 ms 606 ms–606 ms
7.0 KB
Long-poll
4.67 ms 3.78 ms–5.23 ms
155 ms 155 ms–155 ms
605 ms 605 ms–1,111 ms
6.4 KB
MQTT QoS 1
88.4 ms 87.4 ms–89.1 ms
538 ms 537 ms–539 ms
2,187 ms 2,087 ms–2,289 ms
13.3 KB
MQTT QoS 1 nodelay
5.39 ms 4.68 ms–6.64 ms
307 ms 306 ms–307 ms
1,207 ms 1,207 ms–1,459 ms
14.4 KB
Each mechanism resumes differently. SSE sends Last-Event-ID and the server replays everything newer in the same response. WebSocket has no built-in way; this client reconnects with ?after=<id>, and the server replays from its log, one frame per event. Long-poll simply polls with its cursor and gets the missed events as one response. MQTT reconnects to its persistent session (QoS 1, clean start off, session expiry one hour), and the broker sends what it queued while the client was away.
All four start with a new TCP and TLS connection, two round trips, and one more for the request that resumes. On the 200 ms link that floor is about 600 ms, where SSE (606 ms) and long-poll (605 ms) land. WebSocket (805 ms) takes one round trip more, on the 50 ms link too (205 ms against 155 ms for SSE). The likely reason, an explanation rather than a measurement: this server writes the replay as one frame per event, each its own TLS record and packet, more than the 10 packets a new TCP connection may send before the first acknowledgement; one write with all the events would remove it. MQTT’s broker sends the queue 20 acknowledged messages at a time, with Nagle’s algorithm slowing the refills as in the throughput section: 2,187 ms (1,207 ms with set_tcp_nodelay true), and QoS 1 is at-least-once: an event in flight at the moment of the drop may arrive twice, so a client must discard repeats by ID. In these runs it never happened: no mechanism delivered a duplicate, and none lost an event.
What none of the four measures is how long the client takes to notice the drop. Here it knew at once; in practice a silent network failure is found by the next missed keep-alive, which is why the idle intervals above exist. A browser’s EventSource also waits a few seconds before reconnecting unless the server sends a retry: field.
What this does not show
Browsers. The clients are Go programs. A browser adds cookies and longer headers to every long-poll request, cannot send WebSocket pings itself, and limits a page to six HTTP/1.1 connections per host, which caps SSE and long-poll tabs unless the server speaks HTTP/2.
HTTP/2 and HTTP/3. Everything here is HTTP/1.1, the only version WebSocket and Mosquitto’s listener use. SSE and long-poll over HTTP/2 would compress headers and share one connection.
Proxies and real networks. No proxy, load balancer or NAT sits in the path. netem drops packets at random; real links lose in bursts and change their delay.
Scale beyond one core. One Go process and one broker, one core each, 5,000 clients at most, and only on the LAN (1,000 on the lossy link, to keep the run within its time budget). Clustering, horizontal fan-out and persistent storage are a different benchmark.
Compression. WebSocket’s permessage-deflate was off, as it is by default in the libraries used; for large text events it would change the byte counts.
What the numbers say
Once connected, all four deliver an event in half a round trip; protocol choice does not change latency, loss does.
Per event the three streaming options are within a few bytes of each other (160 B–179 B for 32 bytes); long-poll costs 2.6× as much.
An idle connection costs kilobytes an hour at common intervals; the interval matters more than the protocol.
Fan-out is bounded by the server writing one TLS copy per client: 5,000 clients on the LAN took 49.8–73.1 ms on one core; the three streams overlap across runs, long-poll is slowest by median.
MQTT QoS 1’s acknowledgements cap one connection at 20 events per round trip, fewer with Mosquitto’s default Nagle setting, which also slows its catch-up after a drop; QoS 0 has no cap and drops under overload. Long-poll’s rate on a slow link is set by the batch size (1,000 events per response here), not by the protocol.
SSE and long-poll resume after a drop by design; WebSocket needs the application to do it, and MQTT needs a persistent session and QoS 1, and may deliver an event twice.
Reproduce it
The harness is one Go program (the event server with its WebSocket, SSE and long-poll endpoints and MQTT publisher, and every client), a Mosquitto configuration and two shell scripts. It builds one image, starts the server and broker in one network namespace and the clients in another, and runs every cell as a fresh client process:
./certs.sh # throwaway CA and ECDSA P-256 certificatedocker build -t pushb . # Go build, runs the self-testPUSH_SUBNET=<a free private /28> ./up.sh 2 3 4-7 # server core, broker core, client cores./link.sh l50 # 25 ms each waydocker exec push-cli pb run -test push -kind sse -n 40 -pause 100ms
Each run prints one JSON line with every latency sample, the bytes and packets counted in each direction, and the check results: events sent, received, corrupted, duplicated and missing.