Why MQTT is the IoT standard in IOT Protocols - Performance Analysis
We want to understand how the time it takes to send messages using MQTT grows as more devices connect.
How does MQTT handle many devices without slowing down too much?
Analyze the time complexity of the MQTT publish-subscribe message delivery.
// Simplified MQTT message delivery
function mqttPublish(topic, message) {
let subscribers = getSubscribers(topic); // list of devices subscribed
for (let device of subscribers) {
sendMessage(device, message); // send message to each device
}
}
This code sends a message to all devices subscribed to a topic.
Look for repeated actions that take most time.
- Primary operation: Loop over all subscribed devices to send messages.
- How many times: Once for each subscribed device.
As the number of subscribed devices grows, the number of send actions grows too.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 sends |
| 100 | 100 sends |
| 1000 | 1000 sends |
Pattern observation: The work grows directly with the number of subscribers.
Time Complexity: O(n)
This means sending a message takes longer as more devices subscribe, growing in a straight line.
[X] Wrong: "Sending one message always takes the same time no matter how many devices listen."
[OK] Correct: Each subscribed device needs its own message, so more devices mean more work.
Understanding how MQTT scales helps you explain real IoT systems and shows you can think about efficiency in networks.
"What if MQTT used a broadcast method that sends one message to all devices at once? How would the time complexity change?"