“MQTT is lighter than HTTP” is the one thing most people know about MQTT. It is true, but by how much, and where? Its 2-byte header is not what goes over the network: every message also pays for IP, TCP and TLS, and those layers are the same for both protocols. This benchmark measures what each protocol costs once all of that is counted, on a fast network and on two slow ones.
Everything below was measured on one machine, in Docker, with both protocols sharing the same TLS settings, the same certificate and the same emulated links. Every message carries its sequence number and a payload derived from it, and every receiver checks every byte: 32,733,670 delivered messages, 0 corrupted, 0 duplicated.
Setup
Details
MQTT broker
Mosquitto 2.1.2 (eclipse-mosquitto:2, OpenSSL 3.5), defaults apart from the TLS listener and allow_anonymous true, TLS 1.3 only · a second instance with set_tcp_nodelay true, the only setting changed
HTTPS server
Go 1.24.13 net/http, TLS 1.3, HTTP/1.1 and HTTP/2 on the same port · POST publishes, Server-Sent Events (SSE) push to subscribers, empty poll answers 204
Clients
Go 1.24.13: a minimal MQTT 5 client (CONNECT, PUBLISH at QoS 0/1/2, SUBSCRIBE, PING; one TLS record per packet) and the standard net/http client
TLS
1.3 on both, same ECDSA P-256 certificate, key exchange X25519MLKEM768 (Go’s default, accepted by both servers), no session resumption: every new connection does a full handshake
Network
One network namespace, IPv4 loopback at a 1,500-byte MTU with segmentation offloads off, so packets have real Ethernet sizes · links emulated with tc netem: LAN (nothing added), 50 ms round trip (25 ms each way), 200 ms round trip with 1 % random loss in each direction
CPU
AMD Ryzen AI Max+ 395 · cores 0–7 and their SMT siblings reserved for the benchmark: system services, kernel workqueues and every movable IRQ moved to the other CCD, energy preference performance · servers on core 2 (one active at a time), clients on cores 4–7
Method
Every cell is a fresh client process, run 10 times · reported value: median of the 10 runs (mean of the two middle ones), with min–max · latency p99: each run’s 99th percentile, median across runs · bytes from the interface counters: IP packets, all headers included, before and after · one warm-up message before every latency, throughput and fan-out cell, so both protocols start on an open, used connection · a wait for a quiet link before every cell
Bytes on the wire for one message
The first question is the simplest: on a connection that is already open, how many bytes cross the network to publish one message? Only the publisher’s connection is measured here: the device sending a reading to a server. Start with the smallest message, a 16-byte sensor reading, and where its bytes go:
One 16-byte reading on a connection that is already open, as measured on the interface (median of 10 runs × 200 messages), divided by what every packet and every TLS record costs: 52 B of IPv4 + TCP headers per packet, 22 B of TLS 1.3 framing per record. Both protocols pay those two layers; what differs is the protocol's own bytes.One 16-byte reading on a connection that is already open, as measured on the interface (median of 10 runs × 200 messages), divided by what every packet and every TLS record costs: 52 B of IPv4 + TCP headers per packet, 22 B of TLS 1.3 framing per record. Both protocols pay those two layers; what differs is the protocol's own bytes.
For a 16-byte reading, MQTT at QoS 0 puts 162 B on the wire and HTTP/1.1 386 B, 2.4× as much. Where MQTT’s bytes go:
Protocol: 20 bytes. A 2-byte fixed header, the 15-byte topic with its 2-byte length and 1 byte of properties: with the 16-byte payload, a 36-byte PUBLISH.
TLS: 22 bytes per record: a 5-byte record header, a 1-byte content type and a 16-byte authentication tag.
TCP and IP: 52 bytes per packet, 20 for IPv4 and 32 for TCP with timestamps. The message’s packet carries 58 bytes of data and weighs 110; the receiver’s acknowledgement is a second packet of 52 bytes with no data.
That is 162 B in 2 packets to deliver 16 bytes. MQTT’s 2-byte header is real, but the per-message floor is set by TCP, IP and TLS, which HTTPS pays too. What HTTPS adds on top is text: a request line, Host, User-Agent, Content-Type, Content-Length and Accept-Encoding headers on the way up, a status line and a Date header on the way down. HTTP/2 compresses those headers against a table both ends keep for the connection; its frames and flow-control updates take 4 packets per message instead of 2, but fewer bytes: 328 B.
QoS 1 adds a PUBACK, which rides in the packet that would have carried the TCP acknowledgement anyway: 192 B, almost free. QoS 2’s four-packet handshake costs 347 B. The same picture across three payload sizes:
Median of 10 process runs, each sending 200 messages (50 for a new connection each time) and reading the network interface counters before and after. Each payload size has its own scale; the ratio after a bar compares it with MQTT QoS 0 at the same payload.Median of 10 process runs, each sending 200 messages (50 for a new connection each time) and reading the network interface counters before and after. Each payload size has its own scale; the ratio after a bar compares it with MQTT QoS 0 at the same payload.
As payloads grow, the fixed costs stop mattering. At 4 KiB, HTTP/1.1 sends 8 % more than MQTT QoS 0. What does not shrink is the cost of not keeping the connection open: an HTTPS request on a fresh connection costs 4,721 B for the same 16-byte reading, 29× MQTT’s, because every request pays for TCP’s handshake, a full TLS handshake with the certificate, and the teardown.
The gap that matters is therefore not MQTT against HTTP; it is a kept-open connection against a new one per message. A device that wakes up, connects, posts one reading and disconnects spends almost all of its bytes on the handshake, whichever protocol it speaks.
Opening a connection
That makes the connection itself worth measuring: from nothing to the first message acknowledged, with a full TLS 1.3 handshake.
New connection, TLS 1.3 handshake, then one 256-byte message until its acknowledgement (MQTT: CONNECT, CONNACK, PUBLISH QoS 1, PUBACK; HTTPS: POST until the response). Median of 10 process runs × 5 connections. Each link has its own scale; RTT = round trips across the link at that link's delay.New connection, TLS 1.3 handshake, then one 256-byte message until its acknowledgement (MQTT: CONNECT, CONNACK, PUBLISH QoS 1, PUBACK; HTTPS: POST until the response). Median of 10 process runs × 5 connections. Each link has its own scale; RTT = round trips across the link at that link's delay.
Both pay a similar number of bytes, 5,388 B for MQTT and 4,722 B for HTTPS over HTTP/1.1, almost all of it the TLS handshake. About half of that is new: Go 1.24’s client offers the post-quantum hybrid key exchange X25519MLKEM768 by default, both servers accept it, and its key shares are 1,216 B in the ClientHello and 1,120 B in the ServerHello. In a separate check with it switched off (GODEBUG=tlsmlkem=0, LAN, 3 connections each), the same connections cost about 2.9 KB and 2.2 KB. The time is counted in round trips:
HTTPS: 3 round trips. TCP handshake, TLS 1.3 handshake, then the request and its response: 153 ms on the 50 ms link.
MQTT: 4 round trips. TCP, TLS, then CONNECT and CONNACK, then the PUBLISH and its PUBACK: 204 ms. The extra round trip is the client waiting for CONNACK. The standard allows sending the PUBLISH right after CONNECT without waiting, but most client libraries wait, as this one does.
MQTT with the broker’s defaults: 294 ms. Mosquitto leaves Nagle’s algorithm on unless set_tcp_nodelay is set. During connection setup the broker writes small packets back to back; Nagle holds a later one back until the earlier one is acknowledged, and the client delays its acknowledgements, so the two wait for each other. On the LAN that costs 41.1 ms per connection; on the lossy 200 ms link, 241 ms. One line of configuration removes it.
On a 200 ms mobile-like link with loss, a device spends 803 ms (MQTT) or 603 ms (HTTPS) before its first message is acknowledged. That is the real argument for long-lived connections, and MQTT’s design assumes one.
Delivery latency
Next: once connected, how long from publishing a message until a subscriber has it? For MQTT the subscriber is another MQTT client; for HTTPS it is a client holding a Server-Sent Events stream, which the server writes to when a POST arrives. Messages go one at a time, so nothing queues.
One message at a time, 256 bytes, from the publisher's send until the subscriber has it (MQTT subscriber, or an SSE stream for HTTPS). Median of 10 process runs × 60 messages. Each link has its own scale; RTT = round trips at that link's delay. The slowest 1 % are in the next figure.One message at a time, 256 bytes, from the publisher's send until the subscriber has it (MQTT subscriber, or an SSE stream for HTTPS). Median of 10 process runs × 60 messages. Each link has its own scale; RTT = round trips at that link's delay. The slowest 1 % are in the next figure.
On the LAN everything on an open connection takes tens of microseconds; the protocol barely shows. On the slow links the network decides, and the protocols line up by how many trips across the link a message needs:
MQTT QoS 0 and 1, HTTPS over HTTP/1.1 and HTTP/2: one trip from the publisher to the server and one from the server to the subscriber. 50.4 ms, 50.4 ms, 50.5 ms and 50.4 ms on the 50 ms link. The QoS 1 acknowledgement does not delay delivery: the broker forwards the message before, or while, it acknowledges it.
MQTT QoS 2: 101 ms. Mosquitto forwards an exactly-once message only after the publisher’s PUBREL, a full round trip later.
HTTPS on a new connection: 153 ms, the three round trips of the previous section before the message even leaves.
Same measurement, 200 ms round trip with 1 % random loss in each direction. Solid bar: median; lighter extension: each run's 99th percentile, median across 10 runs. On the 50 ms link without loss the 99th percentile is within 1 ms of the median for every row (MQTT QoS 1 51.0 ms, HTTP/1.1 51.0 ms).Same measurement, 200 ms round trip with 1 % random loss in each direction. Solid bar: median; lighter extension: each run's 99th percentile, median across 10 runs. On the 50 ms link without loss the 99th percentile is within 1 ms of the median for every row (MQTT QoS 1 51.0 ms, HTTP/1.1 51.0 ms).
Loss shows up in the tail. On the 200 ms link with 1 % loss the medians stay at the round trips, 200 ms for MQTT QoS 1 and 201 ms for HTTP/1.1, but the 99th percentile reaches 609 ms and 618 ms: a lost TCP segment is retransmitted only after a timeout of at least 200 ms plus the round trip. Both protocols sit on the same TCP and suffer the same way; neither QoS level nor HTTP version helps with it.
The TCP_NODELAY broker changes nothing here (QoS 1: 50.3 ms on the 50 ms link): with one message in flight there is no second small packet for Nagle to hold back.
Throughput on one connection
How many messages per second can one connection carry from a publisher to a subscriber? The publisher sends as fast as each protocol allows for 3 seconds on the LAN and 10 seconds on the slow links; the rate is messages delivered to the subscriber per second, median and min–max across runs (nodelay: the broker with set_tcp_nodelay; HTTP/1.1 sends one request at a time, HTTP/2 keeps 100 in flight). The 50 ms link first, where the differences are widest:
Publisher sending as fast as the protocol allows for 10 s on the 50 ms link, messages delivered to the subscriber per second, median of 10 runs. Log scale: each gridline is 10× the previous one. The table below has all three links with min–max.Publisher sending as fast as the protocol allows for 10 s on the 50 ms link, messages delivered to the subscriber per second, median of 10 runs. Log scale: each gridline is 10× the previous one. The table below has all three links with min–max.
Messages/s
LAN
50 ms
200 ms 1 % loss
MQTT QoS 0
277k 248k–281k
62k 62k–63k
542 258–844
MQTT QoS 1
129k 128k–131k
197 197–198
45 42–48
MQTT QoS 2
67k 64k–67k
98 98–98
23 21–24
MQTT QoS 1 nodelay
119k 119k–120k
395 393–396
67 61–72
MQTT QoS 2 nodelay
63k 62k–64k
197 196–198
33 30–37
HTTP/1.1
58k 57k–62k
20 20–20
5 5–5
HTTP/2 100 streams
88k 84k–92k
1,957 1,933–1,970
238 205–257
On the LAN this measures software: TLS, the broker, the HTTP stack. On the slow links it measures how many messages each protocol allows in flight at once, and the differences become orders of magnitude:
HTTP/1.1 carries one request at a time per connection: about one message per round trip, 20 per second at 50 ms.
HTTP/2 multiplexes streams on one connection: with 100 concurrent requests, 1,957 per second.
MQTT QoS 1 and 2 may have only as many unacknowledged messages in flight as the broker’s receive maximum, which Mosquitto announces as 20. With set_tcp_nodelay that is 20 per round trip, 395 QoS 1 messages per second at 50 ms. With the broker’s defaults it is 197: Nagle holds back the broker’s small acknowledgements and the window refills late. QoS 2 needs two round trips per message and gets half: 197 and 98.
MQTT QoS 0 has no acknowledgements, so only TCP limits it: 62,035 per second at 50 ms. But nothing slows the publisher down to the subscriber’s pace either. When the broker’s queue for the subscriber filled up, Mosquitto dropped QoS 0 messages: 0.11 % of those sent on the 50 ms link and 13.4 % of those sent on the lossy link. That is what at most once permits. The table counts only messages delivered.
For a sensor sending one reading a minute none of this matters. It matters for a gateway forwarding thousands of devices over one uplink, where the in-flight window, not the protocol’s header size, sets the ceiling.
One message to many subscribers
The publish–subscribe case: one message, delivered to 1, 10, 100 or 1,000 subscribers, each on its own TLS connection. For HTTPS each subscriber holds an SSE stream over HTTP/1.1 and the publisher POSTs once.
One publish reaching every subscriber, each on its own TLS connection; the time until the last one has it, median of 10 process runs × 20 publishes. Each link has its own scale. Not drawn: the 50 ms link, where 1,000 subscribers take 53.6 ms (MQTT QoS 0) and 55.2 ms (SSE), and MQTT QoS 1, which tracks QoS 0 (4.99 ms for 1,000 subscribers on the LAN).One publish reaching every subscriber, each on its own TLS connection; the time until the last one has it, median of 10 process runs × 20 publishes. Each link has its own scale. Not drawn: the 50 ms link, where 1,000 subscribers take 53.6 ms (MQTT QoS 0) and 55.2 ms (SSE), and MQTT QoS 1, which tracks QoS 0 (4.99 ms for 1,000 subscribers on the LAN).
The two behave alike. On the LAN the cost is the server encrypting and writing one copy per subscriber: 3.37 ms for the last of 1,000 subscribers over MQTT QoS 0 and 3.48 ms over SSE, with Mosquitto’s single thread against Go’s server on the same single core. On the wire each extra subscriber costs about the same in both, 403 B and 396 B per subscriber for a 256-byte message.
On the lossy link, delivering to everyone becomes slow: with 1,000 subscribers some packet is almost always lost, and the publish waits for its retransmission. Half of the subscribers have the message after 203 ms (MQTT QoS 0), the last after 620 ms; SSE: 204 ms and 624 ms.
The cost of an idle client
Most IoT clients spend most of their time with nothing to say. They still have to stay reachable, and that costs something.
Measured per exchange on an open connection (10 process runs × 10 exchanges: PINGREQ and PINGRESP, an empty poll answered 204, a one-line SSE comment), all headers and TCP acknowledgements included, then multiplied out to an hour. Log scale: each gridline is 10× the previous one.Measured per exchange on an open connection (10 process runs × 10 exchanges: PINGREQ and PINGRESP, an empty poll answered 204, a one-line SSE comment), all headers and TCP acknowledgements included, then multiplied out to an hour. Log scale: each gridline is 10× the previous one.
One keep-alive exchange, PINGREQ and PINGRESP with TLS and TCP around them, is 204 B in 3 packets; at the common 60-second keep-alive that is 12.2 KB an hour. An SSE heartbeat is cheaper still, 134 B, because it is one-way. An empty HTTP/1.1 poll costs 363 B and HTTP/2 249 B.
The difference that matters is not the bytes per exchange, which are within a factor of three, but what the client gets for them. A client on MQTT or SSE receives a message the moment it is published. A client that polls every 60 seconds learns about it up to a minute late; to get within a second it must poll every second, 1.31 MB an hour, 107× the MQTT keep-alive, and wake its radio 3,600 times.
What this does not show
Real radio. A cellular or LoRa modem pays for waking up, not only for bytes. A message every few minutes can cost more energy in radio state changes than in data, which favours fewer, larger transmissions over either protocol’s fine details.
NAT and carrier timeouts. Mobile networks and home routers silently drop idle TCP connections, often after a few minutes. Keep-alive intervals in practice are set by that, not by bandwidth, and can force pings more often than every 60 seconds.
Real loss.netem drops packets independently at random. Real links lose in bursts and change their round trip, which hurts both protocols more than this test does.
Certificate chains. The test certificate is one small ECDSA certificate. A typical public chain with an intermediate is a few kilobytes larger and makes every new connection, of either protocol, more expensive.
Session resumption. TLS resumption skips most of a handshake’s bytes on a reconnect. Neither client used it, so new-connection numbers are the worst case.
Brokers and servers at scale. One broker process and one server process on one core each. Clustering, persistence to disk and thousands of publishers are a different benchmark.
What the numbers say
On an open connection, MQTT’s advantage is real but bounded: for a small reading HTTP/1.1 puts 2.4× the bytes on the wire, and at 4 KiB the two are within 8 %.
The large cost is opening connections: 4,721 B and 3–4 round trips each. Keeping one open is what matters, and it is what MQTT is built around.
Latency on an open connection is the network’s, for both. QoS 2 costs one extra round trip; a new HTTPS connection per message costs three.
In-flight limits, not header sizes, set throughput on slow links: HTTP/1.1 one message per round trip, MQTT QoS 1 twenty, HTTP/2 as many streams as the client opens, MQTT QoS 0 as many as TCP allows, at the price of drops under overload.
Push beats polling: a pushed message arrives at once for 12.2 KB an hour of keep-alive.
Check your broker’s TCP settings: with Nagle left on, Mosquitto added 241 ms to every new connection on the slow link and halved QoS 1 throughput at 50 ms.
Reproduce it
The harness is a Go program (the MQTT client, the HTTPS client and the HTTPS server, standard library only), two Mosquitto configuration files and a driver script. It builds one image, starts the brokers and the server in the client’s network namespace, and runs every cell as a fresh client process:
./certs.sh # throwaway CA and ECDSA P-256 certificate for localhostdocker build -t mqb . # Go 1.24 build, runs a self-test of the MQTT encoder./up.sh 4-7 2 2 # client cores, broker core, HTTPS server coredocker exec mq-net tc qdisc replace dev lo root netem delay 25ms limit 100000 # the 50 ms linkdocker exec mq-net mb run -test lat -kind mqtt -qos 1 -n 60 -settle 300ms
Each run prints one JSON line with every latency sample, the bytes and packets counted, and the check results: messages sent, received, corrupted, duplicated and missing.