MQTT QoS Levels Animation
Interactive Comparison of QoS 0, 1, and 2 Message Delivery
animation
mqtt
protocols
reliability
MQTT Quality of Service Comparison
This interactive animation demonstrates the three MQTT QoS (Quality of Service) levels side-by-side. Watch how each level handles message delivery differently, from fire-and-forget to exactly-once delivery.
Animation Overview
This animation shows the three MQTT QoS levels:
- QoS 0 (At-most-once): Fire-and-forget, no acknowledgment
- QoS 1 (At-least-once): PUBLISH followed by PUBACK acknowledgment
- QoS 2 (Exactly-once): Four-way handshake (PUBLISH, PUBREC, PUBREL, PUBCOMP)
How to Use This Animation
- Click “Play All” to see all three QoS levels animate simultaneously
- Use “Step Through” to advance one message at a time
- Click “Simulate Loss” to see how each QoS handles network failures
- Watch the packet counters to understand delivery guarantees
QoS Level Comparison Table
| Feature | QoS 0 | QoS 1 | QoS 2 |
|---|---|---|---|
| Name | At-most-once | At-least-once | Exactly-once |
| Guarantee | Best effort | Message delivered at least once | Message delivered exactly once |
| Packets | PUBLISH only | PUBLISH, PUBACK | PUBLISH, PUBREC, PUBREL, PUBCOMP |
| Network Overhead | Lowest (1 packet) | Low (2 packets) | Highest (4 packets) |
| Latency | Lowest | Low | Highest |
| Duplicates Possible? | No (but loss possible) | Yes (on retry) | No |
| Use Case | Sensor telemetry, frequent updates | Commands, alerts | Financial transactions, billing |
| Storage Required | None | Message until PUBACK | Message + state until PUBCOMP |
Message Flow Details
QoS 0: Fire-and-Forget
Publisher Broker
| |
|-------- PUBLISH -------->|
| |
(done - no confirmation)
Characteristics:
- Fastest, lowest overhead
- No guarantee of delivery
- Used for non-critical data where occasional loss is acceptable
- Ideal for high-frequency sensor readings
QoS 1: Acknowledged Delivery
Publisher Broker
| |
|-------- PUBLISH -------->|
| | (stores message)
|<-------- PUBACK ---------|
| |
(delete message from queue)
Characteristics:
- Publisher retries until PUBACK received
- May result in duplicate messages if PUBACK is lost
- Subscriber should handle duplicates (idempotent operations)
- Good balance of reliability and performance
QoS 2: Exactly-Once Delivery
Publisher Broker
| |
|-------- PUBLISH -------->|
| | (stores message, state = RECEIVED)
|<-------- PUBREC ---------|
| |
|-------- PUBREL --------->|
| | (delivers to subscribers)
|<-------- PUBCOMP --------|
| |
(transaction complete)
Characteristics:
- Most complex, highest overhead
- Guarantees exactly-once delivery (no duplicates, no loss)
- Uses packet identifiers and state tracking
- Required for critical transactions (billing, commands)
When to Use Each QoS Level
Decision Guide
Choose QoS 0 when:
- Data is sent frequently (temperature every second)
- Missing a value is not critical
- Network is reliable
- Battery life is important
Choose QoS 1 when:
- Messages must be delivered
- Duplicates can be handled (idempotent)
- Commands or alerts that need confirmation
- Most common choice for IoT
Choose QoS 2 when:
- Duplicates would cause problems
- Financial or billing data
- Critical state changes
- Compliance requirements
Real-World Examples
| Application | Recommended QoS | Reason |
|---|---|---|
| Temperature sensor (1/sec) | QoS 0 | High frequency, loss acceptable |
| Smoke detector alert | QoS 1 | Must be delivered, retry OK |
| Door lock command | QoS 1 | Critical, idempotent operation |
| Payment transaction | QoS 2 | No duplicates allowed |
| Energy meter reading | QoS 2 | Billing accuracy required |
| Location updates | QoS 0 | Frequent, superseded by next update |
| Firmware update trigger | QoS 1 | Must arrive, retry safe |
What’s Next
- MQTT Pub/Sub Animation - See the publish-subscribe pattern in action
- MQTT Fundamentals - Deep dive into MQTT protocol
- MQTT Session Management - Persistent sessions and retained messages
- CoAP vs MQTT - Compare with CoAP’s confirmable messages
- Simulations Hub - More interactive visualizations
Animation Technical Notes
This animation is implemented in approximately 450 lines of Observable JavaScript. Key features:
- Parallel timelines: Three independent QoS flows shown side-by-side
- Step-through mode: Manual advancement for teaching
- Loss simulation: Toggle to demonstrate reliability differences
- Statistics tracking: Real-time counters for sent/received/lost
- D3 transitions: Smooth packet animations with easing
- IEEE color palette: Consistent visual design
The animation demonstrates the fundamental trade-off between reliability and overhead in MQTT QoS levels.