The most surprising thing about IoT networking protocols is how often they don’t talk to each other, despite the promise of a connected world.

Let’s look at MQTT, a classic. Imagine you have a smart thermostat (thermostat-123) and a mobile app (my-app). The thermostat needs to tell the app when the temperature changes. It doesn’t send this data directly to my-app. Instead, it publishes a message to a central broker. Think of the broker as a post office. The thermostat drops off a letter (the temperature reading) addressed to a specific topic, say home/livingroom/thermostat/temperature.

# On the thermostat:
mosquitto_pub -h mqtt.example.com -t "home/livingroom/thermostat/temperature" -m "22.5"

# On the mobile app, subscribing to the topic:
mosquitto_sub -h mqtt.example.com -t "home/livingroom/thermostat/temperature"
# Output: 22.5

The broker, mqtt.example.com, holds onto this message. If my-app has previously told the broker, "I want to receive messages for home/livingroom/thermostat/temperature," the broker will then deliver that message to my-app. This publish-subscribe model decouples the sender and receiver. The thermostat doesn’t need to know the app exists, and the app doesn’t need to know the thermostat’s IP address. They only need to agree on the broker and the topic.

This works wonders for many scenarios, especially where devices are on unreliable networks or battery-powered. CoAP (Constrained Application Protocol) is another popular choice, often used with UDP. It’s designed for resource-constrained devices and networks. Instead of the message-passing of MQTT, CoAP is more like HTTP. A device can have resources (like a sensor reading) that other devices can GET, POST, PUT, or DELETE.

Consider a smart light bulb (light-456) with a resource for its on/off state.

# Client (e.g., a gateway or app) wanting to turn on the light:
curl 'coap://light-456.local/state' -X POST -d '{"state": "on"}'

# The light bulb's internal logic, upon receiving this:
# (This is conceptual, not actual bulb code)
if (request.method == POST && request.uri == "/state") {
  body = parse_json(request.payload);
  if (body["state"] == "on") {
    turn_on_light();
    response.code = 204; // Changed
  } else {
    turn_off_light();
    response.code = 204; // Changed
  }
}

CoAP uses observe capabilities, similar to MQTT subscriptions, allowing clients to be notified when a resource changes. This is crucial for monitoring.

The real magic, though, is how these protocols can interoperate. Often, a gateway device bridges different protocols. A set of Zigbee sensors might use their own mesh network protocol, but a gateway aggregates their data and publishes it via MQTT to a cloud platform. Or, a CoAP-based sensor network might have its data collected by a gateway that then exposes it via a REST API.

Here’s where it gets subtle: the "Quality of Service" (QoS) levels in MQTT are a prime example of how mechanical choices impact reliability. QoS 0 means "at most once" – fire and forget. QoS 1 guarantees "at least once" delivery by requiring the subscriber to acknowledge receipt. QoS 2 ensures "exactly once" delivery, which is the most robust but also the most overhead. For a critical temperature reading, you might use QoS 1 or 2. For a non-essential status update, QoS 0 is often sufficient and saves battery. The actual implementation of QoS 2 involves a four-way handshake between client, broker, and client again to ensure the message is processed exactly once by the receiver and only once by the sender.

What most people miss is how crucial the broker’s design is for scalability. A single-instance MQTT broker can become a bottleneck. Distributed brokers, often built using consensus algorithms like Raft or Paxos, allow for high availability and massive scale by partitioning topics across multiple nodes. The challenge then becomes managing cross-node subscriptions and ensuring message ordering when a message might be processed by different nodes depending on the client’s connection.

The next step is understanding how to secure these communications, often involving TLS/SSL for encrypted transport and certificate-based authentication to ensure only authorized devices can connect and publish/subscribe.

Want structured learning?

Take the full Computer Networking course →