This debate gets clearer when you quantify monthly traffic for each protocol strategy.
D m o n t h = N m s g / d a y × S m s g × 30 1024 2 MiB
D_{month}=\frac{N_{msg/day}\times S_{msg}\times 30}{1024^2}\text{ MiB}
D m o n t h = 102 4 2 N m s g / d a y × S m s g × 30 MiB
Worked example : 500 sensors sending every 15 minutes:
N m s g / d a y = 500 × 96 = 48,000
N_{msg/day}=500\times 96=48{,}000
N m s g / d a y = 500 × 96 = 48 , 000
Assume illustrative application-byte budgets, excluding lower-layer overhead and retransmissions: - CoAP message size S m s g = 20 S_{msg}=20 S m s g = 20 bytes - MQTT publish size = 40 =40 = 40 bytes plus a 30-byte allowance for each keepalive exchange every 60 s while the connection is idle
D C o A P = 48,000 × 20 × 30 1024 2 ≈ 27.5 MiB/month D M Q T T , p u b = 48,000 × 40 × 30 1024 2 ≈ 54.9 MiB/month D M Q T T , k e e p a l i v e = 500 × 1440 × 30 × 30 1024 2 ≈ 618.0 MiB/month
\begin{aligned}
D_{CoAP} &= \frac{48{,}000\times 20\times 30}{1024^2} \approx 27.5\text{ MiB/month}\\
D_{MQTT,pub} &= \frac{48{,}000\times 40\times 30}{1024^2} \approx 54.9\text{ MiB/month}\\
D_{MQTT,keepalive} &= \frac{500\times 1440\times 30\times 30}{1024^2} \approx 618.0\text{ MiB/month}
\end{aligned}
D C o A P D MQTT , p u b D MQTT , k ee p a l i v e = 102 4 2 48 , 000 × 20 × 30 ≈ 27.5 MiB/month = 102 4 2 48 , 000 × 40 × 30 ≈ 54.9 MiB/month = 102 4 2 500 × 1440 × 30 × 30 ≈ 618.0 MiB/month
Total MQTT traffic in this deliberately keepalive-heavy model is about 672.9 672.9 672.9 MiB/month. At an illustrative $0.10/MiB, that is about $67.29 versus $2.75 for the CoAP model. Actual billed traffic includes lower-layer framing, security, and carrier policy.
MQTT vs CoAP Data Cost
viewof num_sensors = Inputs. range ([10 , 5000 ], {value : 500 , step : 10 , label : "Number of sensors" })
viewof interval_min = Inputs. range ([1 , 120 ], {value : 15 , step : 1 , label : "Reporting interval (minutes)" })
viewof coap_bytes = Inputs. range ([10 , 100 ], {value : 20 , step : 1 , label : "CoAP message size (bytes)" })
viewof mqtt_pub_bytes = Inputs. range ([20 , 200 ], {value : 40 , step : 5 , label : "MQTT publish size (bytes)" })
viewof mqtt_keepalive_bytes = Inputs. range ([10 , 100 ], {value : 30 , step : 5 , label : "MQTT keepalive size (bytes)" })
viewof cellular_cost = Inputs. range ([0.01 , 1.0 ], {value : 0.10 , step : 0.01 , label : "Illustrative cellular cost ($/MiB)" })
protocol_calc = {
const msgs_per_day = num_sensors * (1440 / interval_min);
const coap_mb = (msgs_per_day * coap_bytes * 30 ) / (1024 * 1024 );
const mqtt_pub_mb = (msgs_per_day * mqtt_pub_bytes * 30 ) / (1024 * 1024 );
const mqtt_keepalive_mb = (num_sensors * 1440 * 30 * mqtt_keepalive_bytes) / (1024 * 1024 );
const mqtt_total_mb = mqtt_pub_mb + mqtt_keepalive_mb;
const coap_cost = coap_mb * cellular_cost;
const mqtt_cost = mqtt_total_mb * cellular_cost;
return {
msgs_per_day : msgs_per_day,
coap_mb : coap_mb,
mqtt_pub_mb : mqtt_pub_mb,
mqtt_keepalive_mb : mqtt_keepalive_mb,
mqtt_total_mb : mqtt_total_mb,
coap_cost : coap_cost,
mqtt_cost : mqtt_cost,
savings : mqtt_cost - coap_cost,
cost_delta_pct : coap_cost === 0 ? 0 : ((mqtt_cost / coap_cost) - 1 ) * 100
};
}
html `<div class="discussion-prompts-calc-shell">
<h4 class="discussion-prompts-calc-title depth-l2">Monthly Data Usage & Cost</h4>
<div class="discussion-prompts-calc-grid">
<div class="discussion-prompts-calc-card">
<span class="discussion-prompts-calc-label">Messages per day</span>
<div class="discussion-prompts-metric-row">
<div class="discussion-prompts-metric">
<span class="discussion-prompts-metric-tag">CoAP</span>
<span class="discussion-prompts-metric-value"> ${ protocol_calc. msgs_per_day . toLocaleString ()} </span>
</div>
<div class="discussion-prompts-metric">
<span class="discussion-prompts-metric-tag">MQTT</span>
<span class="discussion-prompts-metric-value"> ${ protocol_calc. msgs_per_day . toLocaleString ()} </span>
</div>
</div>
</div>
<div class="discussion-prompts-calc-card">
<span class="discussion-prompts-calc-label">Publish data per month</span>
<div class="discussion-prompts-metric-row">
<div class="discussion-prompts-metric">
<span class="discussion-prompts-metric-tag">CoAP</span>
<span class="discussion-prompts-metric-value"> ${ protocol_calc. coap_mb . toFixed (1 )} MiB</span>
</div>
<div class="discussion-prompts-metric">
<span class="discussion-prompts-metric-tag">MQTT</span>
<span class="discussion-prompts-metric-value"> ${ protocol_calc. mqtt_pub_mb . toFixed (1 )} MiB</span>
</div>
</div>
</div>
<div class="discussion-prompts-calc-card">
<span class="discussion-prompts-calc-label">Keepalive data per month</span>
<div class="discussion-prompts-metric-row">
<div class="discussion-prompts-metric">
<span class="discussion-prompts-metric-tag">CoAP</span>
<span class="discussion-prompts-metric-value">0.0 MiB</span>
</div>
<div class="discussion-prompts-metric">
<span class="discussion-prompts-metric-tag">MQTT</span>
<span class="discussion-prompts-metric-value"> ${ protocol_calc. mqtt_keepalive_mb . toFixed (1 )} MiB</span>
</div>
</div>
</div>
<div class="discussion-prompts-calc-card">
<span class="discussion-prompts-calc-label">Total data per month</span>
<div class="discussion-prompts-metric-row">
<div class="discussion-prompts-metric">
<span class="discussion-prompts-metric-tag">CoAP</span>
<span class="discussion-prompts-metric-value"> ${ protocol_calc. coap_mb . toFixed (1 )} MiB</span>
</div>
<div class="discussion-prompts-metric">
<span class="discussion-prompts-metric-tag">MQTT</span>
<span class="discussion-prompts-metric-value"> ${ protocol_calc. mqtt_total_mb . toFixed (1 )} MiB</span>
</div>
</div>
</div>
<div class="discussion-prompts-calc-card">
<span class="discussion-prompts-calc-label">Monthly cost</span>
<div class="discussion-prompts-metric-row">
<div class="discussion-prompts-metric">
<span class="discussion-prompts-metric-tag">CoAP</span>
<span class="discussion-prompts-metric-value">$ ${ protocol_calc. coap_cost . toFixed (2 )} </span>
</div>
<div class="discussion-prompts-metric">
<span class="discussion-prompts-metric-tag">MQTT</span>
<span class="discussion-prompts-metric-value">$ ${ protocol_calc. mqtt_cost . toFixed (2 )} </span>
</div>
</div>
</div>
</div>
<p class="discussion-prompts-calc-note"><strong>Cost difference:</strong> MQTT costs <strong>$ ${ protocol_calc. savings . toFixed (2 )} </strong> more per month ( ${ protocol_calc. cost_delta_pct . toFixed (0 )} % higher than CoAP).</p>
</div>`