---
title: "Real-Time ML Inference on Live Sensor Data: Architecture with CrateDB and FastAPI"
url: https://daily.dev/posts/real-time-ml-inference-on-live-sensor-data-architecture-with-cratedb-and-fastapi-j22gsdkkn
source_url: https://cratedb.com/blog/real-time-ml-inference-cratedb-fastapi
type: article
source: "CrateDB"
published: 2026-06-16T07:09:32.649Z
updated: 2026-06-16T07:09:57.704Z
tags: ["iot", "fastapi", "xgboost", "cratedb"]
reading_time: 8
upvotes: 0
comments: 0
language: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Real-Time ML Inference on Live Sensor Data: Architecture with CrateDB and FastAPI

**[CrateDB](https://daily.dev/sources/cratedb)** · 8 min read · 0 upvotes · 0 comments

## Summary

Batch ML scoring fails for industrial IoT when maintenance windows are measured in minutes. This post presents an architecture using CrateDB and FastAPI to deliver real-time ML inference on live sensor data in under 20 ms. The key insight is that CrateDB's CLUSTERED BY (device_id) table design ensures per-device history queries hit a single shard regardless of cluster size, making feature retrieval — not the model — the performance bottleneck to optimize. An XGBoost classifier and Isolation Forest are combined to produce fault_probability and anomaly_score. The FastAPI service exposes four endpoints for single-device scoring, batch scoring, and fleet-wide risk views, with predictions written back to CrateDB and immediately JOINable against live sensor data in SQL. Production trigger patterns (SCADA alarms, scheduled sweeps, per-insert scoring) and their tradeoffs are also discussed.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://cratedb.com/blog/real-time-ml-inference-cratedb-fastapi>

## Similar posts on daily.dev

- [Powering Real-Time Streaming Analytics with CrateDB and Apache Flink](https://daily.dev/posts/powering-real-time-streaming-analytics-with-cratedb-and-apache-flink-gxtwkzoz0) · CrateDB · 2 upvotes · 0 comments
- [Predictive Maintenance Database Architecture: From Sensor Data to Maintenance Trigger in SQL](https://daily.dev/posts/predictive-maintenance-database-architecture-from-sensor-data-to-maintenance-trigger-in-sql-vtiycryha) · CrateDB · 0 upvotes · 0 comments
- [The IoT Database Built for Real Time Analytics at Scale](https://daily.dev/posts/the-iot-database-built-for-real-time-analytics-at-scale-xwpn14axz) · CrateDB · 0 upvotes · 0 comments
- [IoT Analytics at Scale: Architecture Guide for Industrial Data](https://daily.dev/posts/iot-analytics-at-scale-architecture-guide-for-industrial-data-8kd1ptpdo) · CrateDB · 0 upvotes · 0 comments
- [Inside CrateDB’s Real-Time Query Engine: Aggregations, Ad-Hoc Queries, Hybrid Search, and AI](https://daily.dev/posts/inside-cratedb-s-real-time-query-engine-aggregations-ad-hoc-queries-hybrid-search-and-ai-sl7jvqmbr) · CrateDB · 1 upvotes · 0 comments

---

Tags: [#iot](https://daily.dev/tags/iot), [#fastapi](https://daily.dev/tags/fastapi), [#xgboost](https://daily.dev/tags/xgboost), [#cratedb](https://daily.dev/tags/cratedb)

[View this post on daily.dev](https://daily.dev/posts/real-time-ml-inference-on-live-sensor-data-architecture-with-cratedb-and-fastapi-j22gsdkkn)
