MQTT vs CoAP Debate
MQTT vs CoAP Debate
Scenario: You’re designing a smart agriculture system with 500 soil moisture sensors across a 100-hectare farm. Sensors send readings every 15 minutes. Cellular connectivity is available but expensive.
Debate: Should you use MQTT or CoAP?
Team A (MQTT): Argue for persistent connections, QoS guarantees Team B (CoAP): Argue for lower overhead, UDP efficiency
Consider:
- Power consumption per message
- Handling intermittent connectivity
- Cost per MB of cellular data
- Message delivery guarantees needed
Setup: Study group of 4 students, each assigned a role.
[0-5 min] Context Setting (Facilitator)
Use the same sensor count, message size, rate, price, and target in both cases.
- Scenario: Smart agriculture with 500 soil sensors
- Constraint: Cellular data costs $0.10/MB
- Average message: 20 bytes
- Frequency: Every 15 minutes
- Reliability requirement: 95% delivery
[5-15 min] Position Arguments (5 min each)
Team A (MQTT): Maria presents The MQTT case combines delivery behavior and broker fan-out with the traffic estimate; test whether the full path reaches the stated target.
- QoS 1 supports at-least-once transfer between client and broker; test whether the full path meets the 95% target
- Persistent connection allows instant alerts
- Broker-based fan-out and retained state simplify downstream integrations
- Math: Using the same assumptions from the calculator above, MQTT publish traffic is about 54.9 MiB/month, and a 60-second keepalive adds roughly 618.0 MiB/month more. That is much more expensive on cellular, but Maria argues the extra cost may be worth it when real-time alerts and operational simplicity matter.
Team B (CoAP): Jason presents The CoAP case trades a persistent connection for confirmable exchanges; compare its byte estimate with sleep and retry behavior.
- Confirmable messages provide reliability
- No persistent connection saves battery
- Smaller request/response exchanges keep routine telemetry lightweight
- Math: 500 sensors × 96 msg/day × 20 bytes × 30 days is about 27.5 MiB/month, or $2.75/month at the assumed $0.10/MiB
- BUT: with no connection to keep alive, the radio can sleep completely between reports, which can extend battery life substantially (measure to quantify).
[15-20 min] Cross-Examination (Facilitator moderates)
Q: “Maria, what happens when cellular drops during 15-min sleep?” A: “A configured persistent MQTT session can queue eligible messages while a client is away. The device must retry unconfirmed sends and make duplicates safe; no configuration makes data loss impossible.”
Q: “Jason, how do you handle real-time alerts with CoAP’s request-response model?” A: “CoAP Observe extension allows push notifications. Gateway polls sensors every 5 min for urgent alerts.”
[20-25 min] Role Reversal
One side values battery life; the other values the broker. Compare the cost of each choice.
- Maria argues FOR CoAP battery savings
- Jason argues FOR MQTT’s simplicity
- Learning: Students see both sides’ merits
[25-30 min] Facilitator Synthesis “No right answer. Trade-offs:” Compare alert delivery with battery cost, then consider a split path from CoAP sensors to an MQTT cloud gateway.
- MQTT: Better for real-time alerts, higher data cost
- CoAP: Better for battery life, more complex implementation
- Real projects often use BOTH: CoAP for sensors, MQTT for gateway-to-cloud
Student Feedback: “Switching sides forced me to see why someone would choose the other protocol. Now I understand it’s about project constraints, not ‘better’ vs ‘worse’.”
Time Breakdown Success: 5 min context + 10 min arguments + 5 min questions + 5 min role-switch + 5 min synthesis = exactly 30 min