A device that reconnects successfully can still leave two copies of the same reading, a missing command, and a support ticket nobody budgeted for. I think junior teams spend too long pricing the connection and too little time pricing uncertainty after a failure. The expensive mistake is treating “connected” as a completed transaction when neither the device nor the server can prove that it is.
Retrying a message is cheap; deciding whether it already worked is not
Consider a device that sends a reading, loses its connection before receiving the acknowledgement, and sends the reading again. With MQTT 5.0 QoS 1, at-least-once delivery permits that duplicate; the protocol cannot decide whether two copies should create one database row. HTTP/1.1 has the same application-level problem when a POST succeeds but its response never reaches the device. If your handler inserts both copies, the cost is more than storage: someone must decide which reading a dashboard, alert, or export should trust.
Give each reading an identity that survives a retry: a device ID plus a sequence number persisted across reboots. Then enforce uniqueness where the record is written, rather than relying on an in-memory “recent messages” set that disappears when a worker restarts. Python’s sqlite3 module makes the failure visible in a small runnable example; SQLite documents support for this ON CONFLICT form from version 3.24.0.
import sqlite3
db = sqlite3.connect(":memory:")
db.execute("CREATE TABLE readings (device TEXT, seq INTEGER, value REAL, PRIMARY KEY (device, seq))")
events = [("a", 7, 21.1), ("a", 7, 21.1), ("a", 8, 21.2)]
for event in events:
db.execute("INSERT INTO readings VALUES (?, ?, ?) ON CONFLICT(device, seq) DO NOTHING", event)
print(db.execute("SELECT COUNT(*) FROM readings").fetchone()[0])
print(db.total_changes)
Both lines print 2: three deliveries produced two stored readings. This is a demonstration, not a complete ingestion service. A real device must retain its counter through power loss, and the server must define what to do if the same identity arrives with a different value. Silently discarding that conflict would hide a device bug or an identity collision, so record it separately for investigation.
The bill appears when identity is missing. Suppose a planning model has 600 devices sending one reading every 30 seconds; those are example inputs, not observed fleet statistics. That produces 1,728,000 deliveries per day before retries. Even a hypothetical 0.5% duplicate rate would leave 8,640 extra deliveries to classify daily. You need not inspect each one by hand for the design to be costly: every downstream query and correction script now needs a rule for what counts as one event. I would not buy a larger broker to solve this first, because more broker capacity does not give an ambiguous reading a stable identity.
Teams mistake an acknowledgement for a finished operation
A transport acknowledgement says less than it appears to say. A device can receive an MQTT acknowledgement while the service that ultimately uses its reading is unavailable; an HTTP client can time out after the server commits a row. If code treats either response as proof that the entire operation finished, it can report success too early or retry an operation that already happened. Write down the exact point at which your system promises durability: broker acceptance, database commit, or completion of a downstream action. Each promise has a different recovery cost because each requires different evidence after a crash.
Read IoT Connectivity Mistakes That Blow Up Your Roadmap Cost after counting ambiguous writes, because reconnect handling can generate a support bill before a connectivity choice looks expensive. I disagree with making the connection decision the main unit of cost: a cheap or costly link can carry the same unresolved transaction. For a junior developer, the practical test is to interrupt the process between receiving a message and committing it, then interrupt it again between committing and acknowledging it. If the resulting records differ from what the device believes it sent, you have found work that belongs in the estimate.
Commands make this sharper than readings. Repeating “set target to 21” can be safe if the command means “make the target equal 21”; repeating “increase target by 1” can change the result twice. Attach a command ID, retain its outcome, and return that outcome for a retry. In PostgreSQL 15, a unique constraint plus INSERT … ON CONFLICT can help claim an ID, but the database constraint alone cannot undo an external action that ran before the claim was committed. Put the claim and outcome in a deliberate state model, and test a worker restart at every transition.
For offline devices, choose a retention rule instead of promising eventual delivery without a limit. A command to change a target may still be useful after a short outage; a command to sound an alarm at a particular moment may be dangerous when delivered hours late. An expiry timestamp and a recorded “expired without execution” outcome cost implementation time, but they prevent an operator from mistaking a stale action for a fresh one.
The cheaper protocol depends on which failure your team can afford
Compare HTTP/1.1 POST over TLS 1.3 with MQTT 5.0 QoS 1 for a device that sends occasional readings. HTTP wins when devices connect infrequently and your team already operates an HTTP service, because a request, response, and server log are straightforward to inspect. Its cost is reconnect and TLS overhead on each new session unless the device can reuse a connection, plus client-side work to retry timed-out requests safely. MQTT wins when devices hold a connection and the application needs frequent messages or server-to-device delivery, because the broker handles subscriptions and transport-level acknowledgements. Its cost is operating and observing broker sessions, subscriptions, and delivery state while still implementing application-level deduplication.
Neither option wins merely because a prototype sends one message successfully. Test the workload you expect: planned device count, message frequency, payload size, outage duration, and the number of devices that reconnect together. If a lab test measures a 42-second p95 reconnect time, keep the device firmware, network conditions, and sample count beside that measurement; without them, the number cannot justify a fleet-wide promise. Set an initial 120-second offline alert threshold as a value to tune against those observations, rather than presenting it as a property of either protocol.
Use Prometheus counters for duplicate deliveries, expired commands, and rejected writes, and use OpenTelemetry trace IDs to follow a message across a gateway and API. A counter is cheaper to retain than a full payload and can show whether a firmware release changed failure rates; a trace is more useful for diagnosing one incident but costs more to collect and store at high volume. Keep device ID and message ID in structured logs while avoiding unbounded high-cardinality Prometheus labels, because creating a time series for every message can make monitoring itself expensive.
I would not declare either protocol “production-ready” from a median latency chart, because the median hides the disconnected device whose retries occupy the support queue. Price the protocol decision with an outage replay and a human question: when a device reports success but the server disagrees, how many minutes will it take a developer to reconstruct the truth?
A small pilot hides costs when it avoids simultaneous failures
Twenty devices on a desk rarely reproduce a site power interruption, because a desk test usually reconnects devices one at a time under a developer’s supervision. Read Cheap IoT rollouts break at 20 devices – what to fund instead after running a fleet replay, because I disagree that one device count marks the break: the costly threshold is when a shared failure exceeds the recovery capacity you actually built. A five-device pilot with a poor cellular link can cross it sooner; a larger pilot with bounded retries and observable outcomes may not.
Make the shared failure reproducible. Use Linux tc netem to add delay and packet loss to a test gateway, or Toxiproxy to cut the connection between an ingestion service and its database. Stop and restart the broker or API while devices have unacknowledged messages. Then record four outcomes: how many readings were accepted, how many identities were duplicated, how many commands expired, and how long it took to establish what happened. Those counts turn “the rollout felt unreliable” into defects a developer can fix and a project lead can price.
Test retry timing as carefully as throughput. If every device retries immediately after a shared outage, the recovery path can face a sharper peak than normal operation; exponential backoff with jitter spreads attempts because devices do not all choose the same next instant. A retry cap has a cost too: some devices will stop trying and need a visible failure state. Decide who owns that state before deployment, since a silent stopped device turns a bounded software retry into an unbounded investigation.
Finally, count the work that never appears in a cloud bill. Record the minutes spent matching a field report to a device ID, locating its last accepted sequence number, and deciding whether to resend a command. This is a measured support cost, unlike an assumed per-device price. If your logs cannot answer those questions, improve the evidence before increasing the pilot: multiplying poorly explained failures gives the team more tickets, not more knowledge.
The first budget estimate should come from one interrupted message
Tomorrow, take one device and interrupt its connection immediately after it sends a reading. Capture the device sequence number, server row, acknowledgement, retry, and final outcome in one timeline. Repeat after restarting the ingestion worker. If you cannot tell whether one reading became zero, one, or two records, file that as the first rollout cost to fix before pricing more connections.


