MQTT Architecture, QoS, IoT Use Cases, and How It Compares to HTTP & Kafka
MQTT stands for MQ Telemetry Transport.
If you’ve ever worked with IoT devices, sensors, or real-time telemetry, you’ve likely heard of MQTT.
But MQTT is often misunderstood as “just another messaging protocol.”
In reality, MQTT is the backbone of modern IoT communication — lightweight, efficient, and purpose-built for unreliable networks and low-power devices.
This guide goes deep. By the end, you’ll understand:
How MQTT actually works (architecture)
Why QoS levels matter more than you think
When MQTT beats HTTP and Kafka (and when it doesn’t)
Real production IoT use cases
How to write a basic MQTT publisher & subscriber
This article can serve as a pillar resource for IoT and event-driven systems.
What Is MQTT?
MQTT (Message Queuing Telemetry Transport) is a lightweight publish–subscribe messaging protocol designed for:
Low bandwidth networks
High latency or unreliable connections
Devices with limited CPU, memory, and battery
It was originally created for oil pipeline telemetry — today, it powers smart homes, industrial IoT, connected vehicles, and cloud IoT platforms.
Why MQTT?
Lightweight and Efficient
MQTT clients are very small, require minimal resources so can be used on small microcontrollers. MQTT message headers are small to optimize network bandwidth.
Support for Unreliable Networks
Many IoT devices connect over unreliable cellular networks. MQTT’s support for persistent sessions reduces the time to reconnect the client with the broker.
Bi-directional Communications
MQTT allows for messaging between device to cloud and cloud to device. This makes for easy broadcasting messages to groups of things.
Reliable Message Delivery
Reliability of message delivery is important for many IoT use cases. This is why MQTT has 3 defined quality of service levels: 0 – at most once, 1- at least once, 2 – exactly once
Scale to Millions of Things
MQTT can scale to connect with millions of IoT devices.
Security Enabled
MQTT makes it easy to encrypt messages using TLS and authenticate clients using modern authentication protocols, such as OAuth.
MQTT Publish / Subscribe Architecture
MQTT Architecture (How It Works)
Unlike HTTP’s request–response model, MQTT uses publish–subscribe communication.
Core Components
Publisher
Sends messages (sensor data, events)Broker
Central message hub (e.g., Mosquitto, EMQX, HiveMQ)Subscriber
Receives messages by subscribing to topicsTopics
Hierarchical channels (e.g.,factory/line1/temp)
Why MQTT Is Perfect for IoT
MQTT shines because it’s designed for real-world constraints:
Minimal packet size
Persistent sessions
Efficient keep-alive pings
Works over TCP/IP
Supports offline buffering
That’s why cloud platforms like AWS IoT Core, Azure IoT Hub, and Google Cloud IoT rely heavily on MQTT.
MQTT Quality of Service (QoS) Levels Explained
QoS defines delivery guarantees. Choosing the wrong level can either waste bandwidth or lose data.
QoS Level Comparison Table
| QoS Level | Name | Delivery Guarantee | Use Case |
|---|---|---|---|
| QoS 0 | At most once | Fire-and-forget | Live sensor data, metrics |
| QoS 1 | At least once | Guaranteed delivery (may duplicate) | Alerts, telemetry |
| QoS 2 | Exactly once | No duplication | Billing, financial data |
Key Insight
Most IoT systems do NOT need QoS 2.
QoS 1 is usually the sweet spot between reliability and performance.
Real-World MQTT IoT Use Cases
1️⃣ Smart Home Automation
Sensors publish temperature, motion, humidity
Mobile apps subscribe to updates
Low latency + low battery usage
Example topics:
home/livingroom/temperature
home/door/status
2️⃣ Industrial IoT (IIoT)
Factory machines send telemetry
Dashboards subscribe in real time
Alerts triggered on anomalies
MQTT works even with intermittent connectivity.
3️⃣ Connected Vehicles
Vehicles publish location, speed, diagnostics
Fleet systems subscribe
Supports unreliable mobile networks
4️⃣ Healthcare Devices
Wearables stream vitals
Backend systems consume data securely
Lightweight protocol = longer battery life
MQTT vs HTTP vs Kafka (When to Use What)
This is where many teams get confused.
Protocol Comparison Table
| Feature | MQTT | HTTP | Kafka |
|---|---|---|---|
| Model | Pub/Sub | Request–Response | Distributed log |
| Latency | Very low | Medium | Low |
| Bandwidth | Minimal | High | Medium |
| Offline support | Yes | No | Limited |
| IoT friendly | ⭐⭐⭐⭐⭐ | ⭐ | ⭐⭐ |
| Throughput | Medium | Low | Very high |
| Complexity | Low | Low | High |
When MQTT Wins
✔ IoT devices
✔ Low-power hardware
✔ Unreliable networks
✔ Real-time telemetry
When HTTP Is Better
✔ Simple APIs
✔ Browser-based clients
✔ CRUD operations
When Kafka Is Better
✔ Massive event streams
✔ Data pipelines
✔ Event sourcing
✔ High-throughput analytics
MQTT and Kafka often complement each other, not compete.
MQTT Code Examples (Publisher & Subscriber)
Below are simple examples using Python.
MQTT Publisher Example
import paho.mqtt.client as mqtt
client = mqtt.Client()
client.connect("broker.hivemq.com", 1883)
client.publish("iot/sensor/temp", "27.5")
client.disconnect()ccccc
MQTT Subscriber Example
import paho.mqtt.client as mqtt
def on_message(client, userdata, msg):
print(f"Received: {msg.payload.decode()}")
client = mqtt.Client()
client.on_message = on_message
client.connect("broker.hivemq.com", 1883)
client.subscribe("iot/sensor/temp")
client.loop_forever()
Simple, fast, and efficient — exactly what IoT needs.
Security in MQTT (Often Ignored, Always Important)
Production MQTT systems should always use:
TLS encryption
Client authentication (certificates or tokens)
Topic-level access control
Secure brokers (EMQX, HiveMQ, AWS IoT Core)
Never expose an open broker to the internet.
When NOT to Use MQTT
MQTT is powerful, but not universal.
❌ If you need complex message replay (Kafka wins)
❌ If your system is strictly request–response
❌ If you need strong ordering guarantees across streams
❌ If your consumers must query historical data directly
Why MQTT Is a Pillar Technology in IoT
MQTT isn’t just a protocol — it’s an enabler of scalable, resilient, real-time systems.
It:
Reduces network costs
Extends device battery life
Simplifies event-driven design
Scales from 10 devices to millions
That’s why MQTT remains the default choice for IoT messaging in 2025 and beyond.
FAQ
Q: Is MQTT faster than HTTP?
Yes, MQTT has lower overhead and persistent connections, making it faster for real-time messaging.
Q: Can MQTT replace Kafka?
No. MQTT is for edge and IoT messaging; Kafka is for backend event streaming. They solve different problems.
Q: Is MQTT suitable for cloud-native apps?
Yes, especially when combined with cloud IoT platforms and event pipelines.
Final Note
This article can be expanded into a full IoT series:
MQTT vs AMQP
MQTT Security Best Practices
MQTT + Kafka Architecture
MQTT with Spring Boot / AWS IoT Core
Stay Tuned!


Leave a Reply