When designing IoT systems, transmission frequency determines the optimal transport strategy. This framework helps you choose:
| < 30 seconds |
UDP or UDP+CoAP |
Connection overhead exceeds data; keep-alive wastes battery |
Environmental sensors (temp every 10s) |
| 30 sec - 2 min |
UDP+CoAP CON |
Balance reliability with low overhead |
Smart meters (readings every minute) |
| 2 min - 10 min |
Short-lived TCP |
Connection cost amortizes over fewer transmissions |
Parking sensors (state change every 5 min) |
| 10 min - 1 hour |
Short-lived TCP |
Handshake overhead negligible compared to sleep time |
Agricultural sensors (hourly readings) |
| > 1 hour |
Short-lived TCP or MQTT/TLS |
Security handshake cost becomes acceptable |
Monthly firmware updates |
| Continuous stream |
Persistent TCP |
Connection cost paid once, used continuously |
Video surveillance, audio streaming |
Overhead Calculation Formula:
Cost per message (short-lived TCP) = Handshake + Data + Teardown
Cost per message (persistent TCP) = Data + (Keep-alive bytes / messages_per_keep-alive_interval)
Break-even: short-lived wins when keep-alive cost exceeds reconnection cost
i.e., when: (keep-alive bytes / interval) > (handshake + teardown bytes / msg_interval)
Example with 50ms RTT, 60-second keep-alive interval, 1 message per second:
Short-lived: 3 RTT overhead = 3 × 50ms = 150ms extra latency + ~480 bytes per message
Persistent: keep-alive = 54 bytes / 60 messages = 0.9 bytes overhead per message
Persistent wins for high-frequency (many messages per keep-alive interval).
Short-lived wins for very infrequent messages (e.g., 1 per 30+ minutes).
Decision Tree:
- Is data loss acceptable?
- YES → Consider UDP
- NO → TCP or UDP+CoAP CON
- What is transmission frequency?
- Every < 30s → UDP (keep-alive overhead too high)
- Every 30s-10min → Short-lived TCP (balance point)
- Continuous → Persistent TCP (amortize handshake)
- What is network RTT?
- < 50ms (local) → TCP overhead acceptable
- 50-200ms (Internet) → UDP preferred for frequent transmissions
200ms (satellite) → UDP strongly preferred
- What is packet loss rate?
- < 1% → TCP works well
- 1-10% → TCP acceptable with tuning
10% → UDP + app-layer retry (TCP retransmission storm)
Real-World Example:
Scenario: Smart building with 500 sensors, 100ms RTT, 2% packet loss
Option A: Persistent TCP (Keep-alive every 60s)
Per sensor overhead:
- Keep-alive: 54 bytes every 60s = 0.9 bytes/sec
- Connection state: 4 KB RAM per sensor
Total gateway RAM: 500 × 4 KB = 2 MB
Throughput: No wait for handshake on each message
Battery impact: Wake for keep-alive 12×/day = 12× radio-on events
Option B: Short-lived TCP (New connection per message, every 10s)
Per sensor overhead:
- Handshake: 150ms every 10s = 1.5% time overhead
- No connection state between messages = 0 bytes RAM
Total gateway RAM: Only active connections (~5 concurrent)
Throughput: 150ms latency added per message
Battery impact: Radio-on for handshake + data = 6× readings/min
Option C: UDP + CoAP CON (Confirmable message every 10s)
Per sensor overhead:
- No handshake, single round-trip for ACK = 100ms
- No connection state = 0 bytes RAM
Total gateway RAM: Application state only
Throughput: 100ms latency for ACK wait
Battery impact: Radio-on for send + wait ACK = minimal
Verdict: For this scenario, UDP+CoAP CON wins because: - 500 sensors × 4KB = 2MB RAM saved (no persistent state) - 100ms vs 150ms latency (33% faster than short-lived TCP) - Fewer battery wake events than keep-alive - Handles 2% packet loss with selective retry (no TCP cascade)