MQTT, HTTP or CoAP: Choosing an IoT Messaging Protocol
Once a device can reach the network, it needs a way to exchange messages with the services behind it. Three protocols cover most IoT products. HTTP is universal and request-response. MQTT keeps a connection open to a broker and moves messages by publish and subscribe. CoAP brings a compact, HTTP-like model to UDP for constrained devices. This article compares them on the points that decide real projects.
At a glance
- 8883
- The registered port for MQTT over TLS. Unencrypted MQTT uses 1883.
- 3 levels
- MQTT quality of service: at most once, at least once and exactly once.
- 5683
- The default UDP port for CoAP. CoAP over DTLS uses 5684.
- 2 bytes
- The smallest MQTT fixed header, one reason its packets are compact.
The problem
HTTP is the default because every developer knows it, but it suits devices that send occasional reports and rarely need to be told anything. A device that must react to commands has to poll, which wastes energy and adds delay.
MQTT solves that with a persistent connection, but the connection needs periodic keep-alive traffic. For a device that sleeps for long periods, reconnecting and repeating the TLS handshake can cost more than the data itself.
Match the protocol to who starts the conversation and how often. That decides more than message size does.
Reading the three
MQTT runs over TCP and suits devices that stay connected and must receive commands promptly. MQTT 5 adds reason codes, message expiry and user properties, which make error handling clearer than in 3.1.1. QoS 1 suits most telemetry if handlers tolerate duplicates; QoS 2 adds a four-packet exchange few applications need.
CoAP runs over UDP with a 4-byte fixed header and suits constrained devices on lossy or low-power networks, including Thread. It offers confirmable messages for reliability and an observe option for subscriptions. Cloud support for CoAP is narrower than for MQTT and HTTP, so check the platform first.
What good looks like
Describe the traffic: who initiates, how often, payload size, and whether the device sleeps between messages.
Check what the cloud platform and network support natively. A protocol that needs a translation proxy adds a component to operate.
Prototype on the real network and measure energy and data per message, including connection setup, keep-alives and handshakes.
| Protocol | Transport | Default ports | Pattern |
|---|---|---|---|
| HTTP/1.1 and HTTP/2 | TCP | 80; 443 with TLS | Request and response |
| HTTP/3 | QUIC over UDP | 443 | Request and response |
| MQTT | TCP | 1883; 8883 with TLS | Publish and subscribe via a broker |
| CoAP | UDP | 5683; 5684 with DTLS | Request and response, plus observe |
| packets | |
|---|---|
| QoS 0 | 1 |
| QoS 1 | 2 |
| QoS 2 | 4 |
What it changes
Responsiveness
Commands reach devices without polling where the product needs it.
Energy Use
Connection overhead suits how often the device wakes and talks.
Data Cost
Header and handshake overhead are known before a cellular plan is chosen.
Reliability
Delivery guarantees match what the application can tolerate.
Where to go next
Whichever protocol you choose, secure it: TLS for MQTT and HTTP, DTLS or OSCORE for CoAP. Plain-text ports belong only on isolated test benches.
Define topic or resource naming and payload formats as carefully as the protocol. They outlive the first version of the product.
Problems this prevents
- Devices polling for commands that rarely arrive
- Handshake costs that dwarf the payload
- QoS 2 used where duplicates were harmless
- A protocol the cloud platform cannot ingest
Discuss your project
Email support@aavico.com or use Get in Touch when the website finishes loading.