Skip to content

Blog

Revisiting an IoT ingestion design from 2020

In 2020 I designed a telematics platform: trucks reporting their position from roads across Colombia, Ecuador and Peru. I didn't build it. My part was the architecture, and a proof of concept whose job was to show two things, that it would hold the volume and that it would survive the bad days.

This post looks at the ingestion side: from the tracker in the cab to the data at rest. Apps, maps and reports read from what's described here, and they're out of scope. I'll stick to what existed in 2020, except where a margin note says otherwise.

The volume

Measure Value
Trucks 25,000
Ping interval Every 10 seconds
Peak rate, every truck moving 2,500 pings a second
Per day, ≈14 hours moving, a ping every 5 minutes parked ≈130 million
Per day, every truck moving all day 216 million
Raw volume at ≈300 bytes a ping ≈39 GB a day, ≈14 TB a year

On a normal day, this volume is a solved problem. The design work is in the other days: the hour after an outage, a truck that comes back after three days in the mountains, the same ping arriving twice. That's what this post is about.

The design

The shape of the 2020 design: a data plane that only moves pings, a control plane that only manages trucks. Apps and reports read the two stores and are out of scope.

It ran on Azure, and it had two halves. The data plane is the ingestion pipeline: pings come in through IoT Hub, get processed, and land in two stores, a small one with each truck's latest position and a large one with history. The control plane knows about trucks: who they are, how they're configured, which fleet they belong to. Pings never pass through it.

I no longer remember which databases we chose. The stores in the diagram are what I'd pick from 2020's catalogue.

What held up

The device contract

The trucks carried hardware my client supplied, and the design included a contract for it. Every tracker had to:

  • keep each ping until the cloud acknowledged it,
  • number its pings, so duplicates could be dropped later,
  • retry with backoff instead of hammering a hub that's struggling,
  • know where to connect, and where to go if that failed.
no coveragepings held on the truck
The device contract in one loop: no signal, no loss. Pings wait on the truck, numbered, and go up when coverage returns.

That contract matters more in this region than in most. Roads through the Andes, and down the Amazon side of Ecuador and Peru, run for hours without coverage. With the contract in place, a gap in coverage, or an outage on our side, makes data late. It doesn't make it lost. Almost every decision below gets cheaper because of that one property: the first buffer in the pipeline is the truck.

No Kafka

There was no Kafka, and that held up. IoT Hub's built-in endpoint is already a partitioned log that consumers read at their own pace, with days of retention. Kafka behind it would have been a second log to run, for no gain.

The targets I'd write first

If I did this again, I'd write the ingestion targets down before drawing a single box:

Target Value
Throughput 2,500 pings a second sustained, every truck moving
Freshness 99% of pings stored within 30 seconds of capture, while the truck has coverage
Catch-up Back to real time within 20 minutes of a one-hour outage
Durability No acknowledged ping is ever lost, even if a region is
Late data Pings up to 7 days old are accepted and filed by capture time
Duplicates and order Each ping stored once; each truck's pings in sequence
Retention 30 days fast to query, two years in history

The one I'd argue for hardest is freshness. Because trucks buffer, a ten-minute ingestion outage loses nothing; the data is ten minutes late. An uptime number would call that a breach. Freshness measures what the business feels, and catch-up says how quickly it stops feeling it.

What I'd change

Size for recovery, not for steady state

While ingestion is down, every truck keeps collecting. When it comes back, the pipeline has to carry the live traffic and the backlog at the same time. The time it takes to catch up is:

catch-up = outage × live rate ÷ (capacity − live rate)

At twice the live rate, catching up takes as long as the outage did. That's the number that sizes the pipeline, not the average.

Outage
Headroom
9.0M pings waitingoutagecatching up

At 4× the live rate, the pipeline drains 9.0M pings in 20 min after ingestion is back. Nothing is lost; it’s just late.

It's tempting to size a pipeline from its steady rate. I'd start from this instead: pick the longest outage you want to absorb, pick how quickly you want to be current again, and the headroom falls out.

Make recovery cheap: batch the backlog

There's a second half to the hour after an outage. IoT Hub limits send operations per second, and counts its daily quota in 4 KB chunks. A ping is around 80 bytes in a compact binary format, so a truck sending one ping per message is paying for, and queueing behind, a lot of empty space.

Loading the upload storm simulation…

Play the three runs. With every truck uploading at once and retrying immediately, the hub rejects about a hundred million sends before the backlog is gone, each one a wasted trip over a cellular link. Jitter and backoff, which the contract had, take a little longer but cut the rejections more than twentyfold. Batching the backlog, 50 pings to a message, empties the trucks in about a minute and bills around 280,000 messages instead of eleven million.

Batching doesn't make the pipeline faster. It moves the backlog off the trucks and into the hub in a minute, and from there the headroom in the previous section decides how fast it drains. The two work together. If I wrote the device contract again, I'd make batched catch-up an explicit requirement.

Order, duplicates and late data, on purpose

At this volume, "mostly in order, mostly once" turns into thousands of wrong rows a day. Three decisions handle it, and I'd now write each one down:

  • Order per truck, not globally. Processing is keyed by truck, so each truck's pings are handled in sequence. Nothing needs a global order; a route only needs its own.
  • Duplicates are dropped by (truck, seq). They're not an edge case. IoT Hub's 2020 docs promised ordered, at-least-once delivery, and their own example has 1, 2, 3, 4 arriving as 1, 2, 1, 2, 3, 1, 2, 3, 4. Add device retries and replays on top. Processing keeps, for each truck, the highest sequence number it has stored and a small window of recent ones. With 25,000 trucks, that state is a few megabytes.
  • History is filed by capture time. A truck that spends three days out of coverage uploads three days of pings at once. Filed by arrival time, they'd all land on today. Filed by the time the tracker recorded them, they slot into the right days, and queries by time range stay correct.

Shrinking 14 TB a year

Volume shows up three times: on the cellular link, in the hub's quota, and in storage. The same two decisions shrink all three:

  • A compact binary payload. Around 80 bytes instead of 300 for JSON: about a quarter of the cellular data, and, when the backlog is batched, nearly four times as many pings in every 4 KB the hub counts.
  • Two tiers of history. The last 30 days stay fast to query, because that's what dispatchers and reports ask for. Older pings move to cheaper, slower storage, where an audit or a dispute can still find them.

At 80 bytes, a year of pings is closer to 4 TB than 14, before the history store compresses it.

Losing a region without losing data

Here is the part of IoT Hub's 2020 disaster-recovery guide that matters for ingestion. A failover to the paired region took between 10 minutes and a couple of hours, and device-to-cloud messages the pipeline hadn't read yet were lost.

The fix is the truck again. Trucks keep the last 15 minutes of pings even after the hub acknowledges them. After a failover they reconnect, to the same hostname, and send their backlog plus those 15 minutes. The pipeline drops the duplicates by (truck, seq), as it does every day.

Regional failover in five steps. A truck sends pings to IoT Hub in the primary region, then stream processing, then history. The primary region fails and every ping stays on the truck. The hub is failed over to the paired region, keeping its hostname. The truck reconnects and sends its backlog plus the last 15 minutes again. Stream processing in the paired region drops duplicates by truck and sequence number, and the history replica, which was seconds behind, is complete again.
A regional failover, in five steps. Press Play, or Step through it.

For this to hold, 15 minutes has to be longer than the pipeline's lag plus the replica's lag, so consumer lag becomes an alert, not a dashboard curiosity. Nothing in scope was urgent, so a failover measured in hours made data late and lost none of it. A second live hub would have bought minutes nobody needed.

A proof of concept with pass and fail written down

The proof of concept was meant to show the design would hold the volume and survive the bad days. Volume is the easy half: a load test at a few times the peak is a day's work. If I ran it again, I'd spend most of it on the bad days, with the numbers agreed before the first test:

  • Stop the consumers for an hour, start them again, and time the catch-up against the target.
  • Take a thousand trucks out of coverage for three days, then check history has every ping, on the right day.
  • Replay an hour of pings twice and check nothing is stored twice.
  • Fail over a test hub. Microsoft's guide says not to drill on the production hub, so build one for it.

In 2025

Some of 2020's constraints are gone. IoT Hub now offers zone redundancy in many regions, and Azure Event Grid gained an MQTT broker in 2023.

None of that changes the shape of the design. The truck is still the first buffer, the pipeline still has to absorb the backlog, and on a normal day the volume is still the easy part.

A checklist for the next one

The part of this post I'll come back to:

  • Device contract: buffer until acknowledged, keep a replay window after, number every ping, back off with jitter, batch the backlog, compact payloads.
  • Targets: throughput, freshness, catch-up time, late-data window, retention, written down before the design.
  • Capacity: size for catch-up. At 2× headroom, recovering takes as long as the outage did.
  • Correctness at volume: order per device, dedupe on (device, seq), file by capture time.
  • Storage: a fast window for what people query, cheap storage for the rest.
  • Failure: know what your provider loses in a failover, and cover it with the replay window. Nothing on the ingest path calls the control plane.
  • Proof of concept: pass and fail numbers first, then drills: stopped consumers, coverage gaps, replays, failover on a test hub.

The client, its systems and its real figures stay private. The fleet size and rates here are representative, and the 2020 limits and recovery times come from Microsoft's documentation as it was that year.