17 MQTT and AMQP: Operational Tradeoffs
Start with the story: MQTT and AMQP are not rivals so much as tools for different parts of the route. MQTT is the lightweight uplink for devices; AMQP is the richer backend broker when routing, queues, and delivery evidence matter.
17.1 Start With the Decision
The mathematical gist. A 5000 mAh label states charge, not energy: multiply 5 Ah by voltage to obtain watt-hours.
17.2 Route Overview
This is part 1 of 2. Continue with MQTT and AMQP: Routing Architectures.
17.3 Part Objectives
- Test putting numbers to it with a concrete scenario and pass criteria.
- Choose a defensible design using protocol selection decision tree.
17.4 Chapter Roadmap
- In 60 Seconds
- Phoebe’s Field Notes: 5000 mAh Is Not One Number of Watt-Hours
- Quick Check: mAh vs. Watt-Hours
- For Beginners: How to Use This Chapter
- AMQP vs MQTT Showdown
- Prerequisites
- Related Chapters
- Knowledge Check: Protocol Selection for Smart City
- Putting Numbers to It
- Cross-Hub Connections
- Common Misconception: “MQTT is Always Better for IoT”
- Quick Check: QoS vs. Transactions
- Protocol Comparison Overview
- Key Concepts
- Quick Check: Protocol Comparison Fundamentals
- Interactive Protocol Calculator
- Protocol Overhead & Cost Calculator
- Protocol Selection Decision Tree
17.5 Learning Objectives
By the end of this chapter, you will be able to:
- Compare AMQP and MQTT: Evaluate the strengths and weaknesses of each protocol for IoT scenarios
- Select Appropriate Protocols: Justify the choice between AMQP, MQTT, and CoAP based on quantified application requirements
- Design Hybrid Architectures: Construct systems that use MQTT for devices and AMQP for backend integration, specifying the protocol bridge configuration
- Evaluate Protocol Overhead: Calculate message size, bandwidth consumption, and cost trade-offs for competing protocol choices
- Distinguish Use Case Patterns: Diagnose which protocol fits specific IoT application requirements by analyzing routing complexity, device constraints, and reliability needs
- Develop Migration Strategies: Assess system requirements and construct a phased transition plan between protocols as system complexity evolves
What is this chapter? Comparison between AMQP and MQTT protocols with use case guidance.
When to use:
- When choosing between messaging protocols
- To understand protocol strengths
- For architecture decision-making
Quick Comparison:
| Aspect | MQTT | AMQP |
|---|---|---|
| Complexity | Simple | Feature-rich |
| Overhead | Low | Higher |
| Best For | Sensors, mobile | Enterprise, complex routing |
| QoS | 0, 1, 2 | Extensive |
Prerequisites:
Recommended Path:
- Study both protocols individually first
- Compare using this chapter
- Apply insights to your use case
“Which is better — AMQP or MQTT?” asked Temperature Terry. the microcontroller shook his head. “Wrong question, Sammy! It’s like asking whether a bicycle or a truck is better. It depends on what you need to carry!”
“MQTT is like a bicycle,” explained the LED. “It’s lightweight, simple, and perfect for quick trips. A tiny temperature sensor with limited battery can use MQTT because the messages are small and the protocol is simple. Publish to a topic, and anyone subscribed gets it.”
“AMQP is like a delivery truck,” added the battery. “It’s heavier and more complex, but it can route packages to dozens of different warehouses using exchange rules. If you need a message to go to exactly three specific systems based on complicated rules — like ‘all temperature alerts above 50 degrees on floor 2’ — AMQP handles that on the server side.”
Max summed it up: “Use MQTT for simple sensor-to-cloud communication where battery life matters. Use AMQP when you need sophisticated routing, guaranteed delivery with transactions, or when you’re connecting enterprise systems. Many real IoT platforms actually use both — MQTT at the edge, AMQP in the backend!”
17.6 Prerequisites
Before diving into this chapter, you should be familiar with:
- AMQP Fundamentals: Understanding AMQP architecture, exchanges, and routing patterns is essential for comparing it effectively with MQTT
- MQTT Fundamentals: Knowledge of MQTT’s publish-subscribe model, QoS levels, and design philosophy provides the foundation for meaningful comparison
- Application Protocols Overview: Familiarity with IoT application protocols and their trade-offs helps you make informed protocol selection decisions
- Networking Fundamentals: Basic understanding of TCP/UDP, bandwidth, and latency is necessary for evaluating protocol overhead and performance
Protocol Deep Dives:
- AMQP Fundamentals - Advanced Message Queuing Protocol details
- MQTT Fundamentals - Message Queue Telemetry Transport concepts
- CoAP Protocol - RESTful alternative for request-response patterns
Protocol Comparisons:
- IoT Protocols Review - Comprehensive comparison of all protocols
- Application Protocols Overview - Protocol landscape overview
Implementation Guides:
- MQTT Labs - Hands-on MQTT implementation
- CoAP Features and Labs - CoAP practical examples
Architecture Decisions:
- Edge Computing - Where protocols fit in edge-cloud architectures
- IoT Reference Models - Protocol placement in IoT stacks
Use Case Examples:
- Application Domains - Industry-specific protocol needs
Learning Tools:
- Simulations Hub - Interactive protocol comparisons
- Quiz Navigator - Test protocol selection knowledge
Scenario: You’re architecting a smart city platform with 50,000 streetlights, 200 traffic cameras, and 10 city-wide dashboards. Each streetlight sends on/off status + energy data every 5 minutes (50 bytes). Cameras stream alerts to 3 emergency services (police, fire, ambulance). Budget: $200K for backend messaging infrastructure over 5 years.
Think about:
- Would you use MQTT or AMQP for streetlight telemetry? Why?
- How would you route camera alerts so only relevant agencies receive them?
Key Insight: Use MQTT for streetlights (simple pub/sub, 50,000 × $0/sensor, minimal overhead) and AMQP for camera alerts (complex routing, “route by jurisdiction and severity”, guaranteed delivery).
MQTT broker handles 50,000 streetlights at approximately 167 messages/second (50,000 ÷ 300 s = 166.7 msg/s, easily managed by a single AWS IoT Core broker at $8/month). AMQP exchanges route camera alerts using bindings like routing_key: "zone.north.fire.critical" ensuring the North Fire Station only sees its relevant emergencies—this complex routing would require custom logic in MQTT.
Let’s quantify the message throughput for streetlights precisely. Each streetlight sends status and energy data every 5 minutes:
With an average message size of 50 bytes plus MQTT’s 2-byte header:
For the hybrid architecture 5-year total cost of ownership:
This compares favorably to pure AMQP (estimated $80K+) or pure MQTT with custom routing ($60K+ in development costs).
Hybrid cost: MQTT broker ($96/year) + RabbitMQ cluster ($15K one-time, $5K/year maintenance) = ~$40K over 5 years vs $80K+ for pure AMQP everywhere or poor routing with pure MQTT.
Verify Your Understanding:
- Why might you bridge MQTT and AMQP at the backend (not choose one exclusively)?
- How does QoS 1 in MQTT compare to transactional guarantees in AMQP?
This chapter connects to multiple learning resources:
Interactive Tools:
First: Simulations Hub: Try the “Protocol Comparison Tool” to interactively compare MQTT, AMQP, and CoAP performance characteristics
Next: Knowledge Map: See how AMQP and MQTT fit into the broader IoT protocol landscape and their relationships with transport and application layers
Self-Assessment:
Then: Quiz Navigator: Test your protocol selection knowledge with scenario-based questions on MQTT vs AMQP trade-offs
After that: Knowledge Gaps: Explore common misconceptions about protocol overhead, QoS guarantees, and when to use each protocol
Multimedia Learning:
Also inspect: Videos Hub: Watch protocol comparison videos showing real-world message flows and performance benchmarks
The Myth: “Since MQTT is designed for IoT and has lower overhead, it’s always the best choice for any IoT application.”
The Reality: Protocol selection depends on specific requirements, not just the “IoT” label:
When MQTT Wins:
First: High-volume telemetry: 50,000 sensors × 1 msg/5min = 166.7 msg/sec easily handled by single broker (50,000 ÷ 300 s)
Next: Mobile clients: 2-byte header saves significant bandwidth on cellular connections (2 bytes vs 8 bytes = 75% savings per message)
Then: Simple pub/sub: Temperature sensors publishing to sensors/room/temp don’t need complex routing
After that: Cost-sensitive: AWS IoT Core charges $1 per million messages; MQTT’s minimal overhead reduces costs
When AMQP Wins:
Also inspect: Complex routing: Camera alerts routed by zone.north.fire.critical using exchange bindings—would require custom broker logic in MQTT
Finally: Transactional guarantees: AMQP transactions provide atomic commit/rollback across multiple operations (MQTT QoS 2 provides exactly-once duplicate-free delivery to the broker, but no atomicity or rollback if processing fails after receipt)
Finally: Backend integration: Enterprise systems expect AMQP’s exchanges, queues, and dead-letter queues for error handling
Finally: Message prioritization: AMQP supports priority queues (0-255); MQTT treats all messages equally
Quantified Example - Smart Factory:
Finally: Shop floor sensors (10,000 devices): MQTT saves $12K/year in bandwidth vs AMQP (2-byte vs 8-byte headers at 1 msg/sec)
Finally: Alert routing (500 actuators): AMQP exchange routing saves 200 dev hours ($30K) vs custom MQTT broker logic for complex rules
Finally: Hybrid solution: MQTT for sensors → broker → AMQP bridge → enterprise systems = best of both worlds
The Key Insight: Use MQTT where simplicity and efficiency matter; use AMQP where sophisticated routing and transactional guarantees are essential. Most production systems use both via protocol bridges.
17.7 Protocol Comparison Overview
Key Concepts
First: AMQP: Advanced Message Queuing Protocol — open standard for enterprise message routing with delivery guarantees
Next: Exchange Types: Direct (exact key), Topic (wildcard), Fanout (broadcast), Headers (metadata) — four routing strategies
Then: Queue: Message buffer between exchange and consumer — durable queues survive broker restarts
After that: Binding: Connection between exchange and queue specifying routing key pattern for message matching
Also inspect: Delivery Guarantee: At-most-once (auto-ack), at-least-once (manual-ack + persistence), exactly-once (transactions)
Finally: Publisher Confirms: Asynchronous broker acknowledgment to producers confirming message persistence in the queue
Finally: Dead Letter Exchange: Secondary exchange receiving rejected, expired, or overflowed messages for error handling
Both AMQP and MQTT are used in IoT, but with different strengths:
| Feature | MQTT | AMQP |
|---|---|---|
| Design Goal | Lightweight telemetry | Enterprise messaging |
| Complexity | Simple | Feature-rich |
| Overhead | 2-byte header minimum | 8-byte frame header |
| QoS Levels | 0, 1, 2 | Extensive reliability options |
| Routing | Topic hierarchy | Exchanges + routing keys |
| Best For | Sensors, mobile apps | Backend integration, complex workflows |
| Typical Use | Device → Cloud telemetry | Service → Service communication |
17.8 Interactive Protocol Calculator
17.9 Protocol Selection Decision Tree
Inspect Figure 17.1 to turn protocol selection into a sequence of constraints rather than a preference contest.
Follow Figure 17.1 from device and link limits into routing complexity and transaction or work-queue needs. The branches lead to MQTT, AMQP, or a hybrid placement for different reasons. The chosen leaf should therefore be recorded with the constraint that caused it and revisited when that constraint changes.
MQTT excels at scale and simplicity, while AMQP provides rich enterprise features like routing and transactions.
17.10 Continue to the Next Part
Carry this evidence into MQTT and AMQP: Routing Architectures, which begins with Architecture Comparison: MQTT vs AMQP Data Flow.
