14 November 2026
Why MQTT, and not HTTP, for devices
Most developers reach for HTTP first. It works, it is everywhere, and for a phone app it is the right tool. For a fleet of small devices on poor networks, MQTT was designed around different constraints.
Publish/subscribe decouples everyone
With HTTP, a device must know the address of the server that wants its data. With MQTT, a device publishes to a topic on a broker and does not care who listens. Add a second consumer tomorrow, such as an alerting service, and the device does not change.
Topics are hierarchical (site/3/room/12/temperature) and subscribers can use wildcards (site/3/#), so one
subscription can follow a whole building. Wildcards are stage 5 of the course.
One connection, tiny packets
An MQTT client opens a TCP connection once and keeps it. A packet has a header of as little as two bytes, so sending a reading costs far less than a full HTTP request with its headers. On a metered cellular link, that adds up. The same open connection also lets the broker push to the device: a command can reach it without the device polling.
You choose how hard to try
MQTT gives three delivery levels, set per message:
- QoS 0: at most once. Fire and forget. Fine for a reading that will be replaced in a second.
- QoS 1: at least once. The receiver acknowledges, and the sender retries. You may get duplicates.
- QoS 2: exactly once, at the cost of a longer handshake.
Choosing the level per message is a real design decision, and the duplicates of QoS 1 are why the next brick, ingestion, must be idempotent. QoS 1 is stage 6.
Built for flaky networks
Several features exist because devices disappear:
- Keep-alive: if a client is silent for too long, the broker closes the connection.
- Last Will: the client leaves a message with the broker that is published if it vanishes without saying goodbye. This is how "device offline" gets noticed.
- Retained messages: the broker keeps the last value of a topic, so a new subscriber gets the current state immediately instead of waiting for the next publish.
- Persistent sessions: subscriptions and queued messages survive a disconnection.
The trade-off
A broker is one more component to run, and the protocol is stateful, so a broker is harder to scale than a stateless HTTP server. In return you get a protocol whose defaults match the physical world. In this course you will write that broker yourself, from the first TCP connection to Last Will, and test it against real MQTT 3.1.1 packets.
The first stage is free to try: accept a connection and let the tests tell you what to fix.