DEV Community

mp3sss
mp3sss

Posted on

Where AI Models Actually Belong in an IoT Telemetry Pipeline

Most IoT machine learning projects do not fail because the model is bad. They fail because the model lives in the wrong place.

I have seen a 40 KB gradient-boosted model shipped to a cloud GPU cluster, adding 800 ms of round-trip latency to a vibration alarm that needs to fire in under 50 ms. I have also seen a 90 MB transformer stuffed onto a Cortex-M4 gateway with 256 MB of RAM, where it ran at 0.4 inferences per second and starved the MQTT broker. Both teams had decent models. Both systems were unusable.

This article is about placement: deciding which inference runs on the device, which runs on the gateway, and which deserves the cloud. It is the first post in a ten-part series on AI models for IoT data analysis and alerting, and later posts go deep on edge runtimes, feature pipelines, anomaly detection, rule engines, alert de-duplication, safe rollout, and LLM-assisted triage.

The three tiers, and what each one is actually good at

A modern telemetry architecture has three natural execution tiers. They differ in a way that matters far more than raw compute: what they can see.

Tier Sees Typical budget Best at
Device One sensor stream, microseconds of history 64 MHz–1 GHz, 64 KB–2 MB RAM Per-sample gating, waveform features, hard safety limits
Gateway / edge node Tens of streams, seconds to minutes of history, cross-sensor joins 1–8 cores, 512 MB–8 GB Multi-sensor fusion, short-window anomaly detection, local alarm decisions
Cloud Months of history, the whole fleet, other sites Effectively elastic Fleet-wide baselines, drift detection, retraining, triage, correlation across sites

The device sees a single signal at high rate but almost no context. The cloud sees enormous context but pays a network round trip for every observation. The gateway sits in the sweet spot: enough history to judge "is this normal for this machine right now", and enough locality to act in milliseconds.

The placement error is almost always one of these two:

  1. Pushing high-rate raw data upward so the cloud can do the thinking. You pay bandwidth, latency, and cloud egress, and you still cannot fire a sub-100 ms alarm.
  2. Pushing complex reasoning downward onto hardware that cannot afford the memory or the update cadence. You get a model nobody can retrain and a device that cannot keep up.

Do the bandwidth math before you argue about models

A single vibration sensor sampling at 3.2 kHz, 16-bit, three axes produces roughly:

3,200 samples/s × 3 axes × 2 bytes = 19,200 B/s ≈ 19.2 KB/s per sensor
Enter fullscreen mode Exit fullscreen mode

That is only 154 kbit/s, which sounds survivable — until you multiply by 2,000 sensors across a plant and by the fact that many industrial sites still run on a shared 4G link with metered data.

2,000 sensors × 19.2 KB/s = 38.4 MB/s = 307 Mbit/s of raw telemetry
Enter fullscreen mode Exit fullscreen mode

Now the same fleet after edge feature extraction. Each sensor emits one 48-byte feature vector every 10 seconds:

2,000 × 48 B / 10 s = 9.6 KB/s ≈ 77 kbit/s
Enter fullscreen mode Exit fullscreen mode

That is a 4,000× reduction, and it is the single strongest argument for edge processing. But note what you lose: the raw waveform. If the alarm fires, somebody will want the raw data for diagnosis, so the pipeline still needs a ring buffer on the device that uploads the last N seconds when an alarm triggers. Extract features continuously, retain raw data conditionally.

A placement decision procedure that actually gets used

Rather than debating philosophy, run each candidate model through four questions:

1. What is the deadline? Work backward from the consequence, not the model.

  • Hard real-time (loop closure, trip, overspeed): < 50 ms → must be on the device or the local PLC. Not negotiable, not a neural network in most cases.
  • Operational (bearing degradation, temperature excursion): 1–30 s → gateway is ideal.
  • Analytical (fleet comparison, capacity planning, trend report): minutes to hours → cloud.

2. How much history does the decision need?

A single-sample threshold needs zero history. A "vibration is 3σ above the 30-minute baseline" decision needs 30 minutes of context — and if the device only keeps a 2-second buffer, that decision simply cannot live there. Count the samples the decision requires, multiply by bytes per sample, and compare against the RAM you actually have after the RTOS and the network stack.

3. How often does the decision logic need to change?

This is the most underrated axis. A model that must be retrained monthly belongs where you can ship updates monthly without a truck roll. If your fleet is 5,000 devices behind NAT on cellular, updating a device model is a project; updating a gateway container is a deploy. Put fast-moving logic at the tier with the cheapest update path, and freeze only the logic that genuinely must be frozen.

4. What does a false positive cost at each tier?

A local alarm that pages a technician at 3 a.m. is expensive. A cloud alarm that pages the same technician is equally expensive but arrives with better context. If your false-positive rate is still above ~5%, the reasoning probably belongs one tier up, where you can join more signals before you wake someone.

A concrete tiering policy in code

Here is the shape I use for a gateway-side placement policy. It is deliberately boring: a lookup table plus explicit budgets, so that when a colleague adds a model, the constraints are visible in review rather than discovered in production.

from dataclasses import dataclass

@dataclass(frozen=True)
class Tier:
    name: str
    max_latency_ms: int
    max_model_kb: int
    history_s: int
    update_cadence: str

TIERS = {
    "device":  Tier("device",  max_latency_ms=50,    max_model_kb=256,   history_s=2,       update_cadence="quarterly"),
    "gateway": Tier("gateway", max_latency_ms=1000,  max_model_kb=8192,  history_s=3600,    update_cadence="weekly"),
    "cloud":   Tier("cloud",   max_latency_ms=60000, max_model_kb=1_000_000, history_s=31_536_000, update_cadence="daily"),
}

@dataclass(frozen=True)
class ModelSpec:
    name: str
    latency_ms: int
    size_kb: int
    history_s: int
    needs_raw_waveform: bool

def fits(spec: ModelSpec, tier: Tier) -> bool:
    return (
        spec.latency_ms <= tier.max_latency_ms
        and spec.size_kb <= tier.max_model_kb
        and spec.history_s <= tier.history_s
        and not (spec.needs_raw_waveform and tier.name == "cloud")
    )

def place(spec: ModelSpec) -> str | None:
    for name in ("device", "gateway", "cloud"):  # cheapest tier first
        if fits(spec, TIERS[name]):
            return name
    return None  # needs a redesign, not a bigger tier
Enter fullscreen mode Exit fullscreen mode

Two things make this useful in practice. First, place() searches from the cheapest tier upward, which keeps cloud costs honest. Second, "cheapest tier first" only works because the tiers are ordered by capability, not by cost — the device is cheapest to run and the most constrained, so anything that fits there is also cheap to operate.

Note the needs_raw_waveform clause. It encodes the constraint that most teams learn the hard way: once you have discarded the raw signal, cloud-side models can only reason over features, and some failure modes (transient spikes, mechanical impulses, clipping) are invisible in 10-second aggregates.

The alerting path is not the analytics path

Placement questions get much easier once you accept that detection and explanation have different requirements.

Detection wants to be close to the data and cheap. Explanation wants context and compute. So split them:

sensor → [device: hard limits + feature extraction]
       → [gateway: windowed anomaly model + rule engine]
       → (MQTT, only on state change)
       → [cloud: correlation, dedup, triage, notification]
Enter fullscreen mode Exit fullscreen mode

The gateway publishes on state transitions, not on every sample. A machine that is "normal" for six hours produces one message, not 21,600. The cloud receives a stream of events it can actually reason about, and the device keeps a ring buffer so the raw waveform can follow the event if anyone asks.

This structure also gives you a natural safety story. Hard limits (over-temperature, over-pressure, vibration above mechanical tolerance) live on the device in deterministic code, not in a model. A model can be wrong; a limit switch is auditable. Never put a learned model in the path of a hard safety interlock — put it in the path of maintenance decisions, where being wrong costs money instead of limbs.

Anti-patterns worth naming

  • The cloud round trip for a local decision. If the actuator is 10 meters from the sensor, the decision should not cross the internet.
  • The mega-model on the gateway. If your gateway inference takes longer than the sampling interval, you have built a queue, and queues are how alarm latency becomes unbounded.
  • The unversioned device model. If you cannot tell which model version produced a given alarm, you cannot debug the alarm.
  • Feature-only retention. Keeping aggregates and discarding raw data is right 95% of the time and catastrophic the other 5%. Keep a ring buffer and upload on trigger.
  • One model for all sites. Equipment, ambient conditions, and maintenance culture differ. A model trained on one plant usually transfers badly; see the drift discussion later in the series.

What is coming next

Over the next posts I will build the pieces this architecture implies, in the order you would actually need them:

  1. Choosing an edge inference runtime and shrinking the model to fit the budget above
  2. Building a feature pipeline for sensor data that does not leak future information
  3. On-device anomaly detection — when a statistical baseline beats a neural network
  4. A rule engine that complements the model instead of fighting it
  5. De-duplicating alerts and suppressing flapping
  6. Thresholds, hysteresis, and hold-downs that operators trust
  7. Shadow mode, canary rollout, and rollback for fleet-wide model updates
  8. Using an LLM for triage without giving it the authority to page anyone
  9. Operating the whole thing: drift, metrics, and MLOps for constrained fleets

If you are starting a project, the single most valuable thing you can do this week is write down, per decision, the deadline, the history required, the update cadence, and the cost of a false positive. Most placement arguments dissolve the moment those four numbers are on the same page.

Next in the series: Edge Inference for Sensor Data — Choosing a Runtime and Shrinking the Model.

Top comments (1)

Collapse
 
crtdrops profile image
Israel Negrete Lepe •

The split between detection and explanation is the part that matches what I've measured.

In our lab, two small machines (an Intel N100 and a Raspberry Pi 5) send a heartbeat every 10 seconds. Fixed rules on the N100 decide what failed overnight and write it to a JSON file. A local model, Gemma 3 4B, only writes the 7 a.m. report from that file.

The detection side has been boring, which is what you want: 16 of 16 injected faults found, each with the right type. The explanation side is where the errors live. In 35 nights, the report invented an hour or an incident on 4 of them, and its "possible explanations" sometimes contradicted the evidence two lines above. So every report gets checked against the JSON before anyone trusts it.

Your later posts cover LLM-assisted triage. Will the triage output be checked against the event record, or only read by a person?