Understanding how QoS levels work under the hood helps you make informed design decisions for production IoT systems.
QoS 0 Message Flow (2 messages total):
Publisher -> PUBLISH -> Broker -> PUBLISH -> Subscriber
- No acknowledgment, no retry
- Latency: ~5-10ms
- Packet overhead: 2 bytes (minimum MQTT header)
- Battery impact: Minimal (1 transmission)
QoS 1 Message Flow (4 messages total):
Publisher -> PUBLISH (with Message ID) -> Broker
Broker -> PUBACK (acknowledges receipt) -> Publisher
Broker -> PUBLISH -> Subscriber
Subscriber -> PUBACK -> Broker
- Publisher retransmits if no PUBACK within timeout (typically 5 seconds)
- Broker stores message until subscriber acknowledges
- Latency: ~15-30ms
- Packet overhead: 4 bytes (header + Message ID)
- Battery impact: 2x transmissions
- Duplicate detection: Message ID allows subscriber to detect duplicates (but doesnβt prevent them)
QoS 2 Message Flow (6 messages total):
Publisher -> PUBLISH (Message ID) -> Broker
Broker -> PUBREC (receipt confirmed) -> Publisher
Publisher -> PUBREL (release for delivery) -> Broker
Broker -> PUBCOMP (complete) -> Publisher
Broker -> PUBLISH -> Subscriber (same 4-step handshake)
- Four-way handshake guarantees exactly-once delivery
- Broker and publisher maintain state until PUBCOMP
- Latency: ~40-80ms
- Packet overhead: 6 bytes
- Battery impact: 3x transmissions
- State overhead: Both sides store transaction state (memory cost)
Real-World Performance Measurements:
On ESP32 with Wi-Fi (2.4GHz, -60 dBm signal strength):
| Latency (avg) |
8ms |
24ms |
67ms |
| Messages/sec |
5000 |
2000 |
800 |
| Battery life (CR2032, 1 msg/min) |
520 days |
260 days |
173 days |
| Reliability (stable Wi-Fi) |
99.8% |
99.99% |
100% |
| Reliability (unstable Wi-Fi) |
95% |
99.5% |
100% |
When to Use Each QoS:
- QoS 0: Temperature readings every 30 seconds (occasional loss acceptable), device heartbeats, non-critical telemetry
- QoS 1: Door/window open alerts, motion detection events, battery low warnings (duplicates acceptable)
- QoS 2: Financial transactions (vending machine payments), medication dispensing commands, door lock/unlock commands (duplicates dangerous)
Common Misconception: βQoS 2 ensures the subscriber receives the message.β False! QoS guarantees delivery from publisher->broker and broker->subscriber independently. If subscriber is offline, broker queues the message (with Clean Session=0), but subscriber may never reconnect. For true end-to-end confirmation, implement application-level acknowledgments.
Hybrid Approach: Use QoS 0 for periodic telemetry + QoS 1 for critical events. This optimizes both battery life and reliability.