- Nov 19, 2026
- 4 min read
The Boring Architecture That Works: MQTT, One Ingester, SQLite
When people hear “IoT platform” they picture a time-series database, Kafka, Grafana and something on Kubernetes. What I run fits in one container:
- EMQX as the MQTT broker. It was already in my homelab.
- One ingester that subscribes and writes to SQLite.
- One Next.js dashboard that opens the same SQLite file read-only.
- Both in one Docker container, as two separate processes.
Why SQLite? One site, one operator, a handful of devices, about a million rows. SQLite in WAL mode handles that without effort, backs up as a single file, and needs no operations work at all.
Rule one: exactly one writer
The ingester is the only process that writes to the database. The dashboard,
the operator CLI and any ad-hoc sqlite3 query only read. That removes a whole
class of problems: no lock contention, no two services disagreeing about the
schema, no “which process wrote this row?”.
One gotcha: I first mounted the data folder read-only for the dashboard, and it
couldn’t open the database. In WAL mode SQLite creates a -shm file even for
readers, so the mount has to be writable. The dashboard still opens the file
with readonly: true; the protection is in the connection, not the mount.
Rule two: routes are config, not code
Every MQTT route lives in config/ingest.json: the topic filter, the payload
format, the device it belongs to, the JSON path, the metric, the unit and an
optional multiplier. Three more files describe the rest:
config/signals.json what a signal is: label, unit, precision, chart type, bands
config/devices.json the fleet: device ids, location, signals, capabilities
config/layout.json which panels appear, in what order
config/ingest.json MQTT filters, payload format, device mapping, fields
Edit, restart, done. No rebuild. Panel types are code; panel instances, devices, signals, labels and thresholds are data.
This paid off twice. When I added a Zigbee sensor and smart plug, one route on
zigbee2mqtt/+ fanned the JSON fields out into normal readings (temperature,
humidity, battery, link quality, power), and non-numeric fields like state
went to an events table. When I added a Shelly energy meter, it was config
entries again. Its keys contain colons (params.em1:0.act_power), and the
dotted path lookup handles them.
The mapping does real work
Two examples from the signals file:
env.temperaturematchesmetric = 'temperature' AND topic NOT LIKE '%internal%'. The ESP32 and Pico report their own chip temperature too, and this keeps it out of the room-temperature chart. It gets its own signal,system.chip_temperature.- Old rows carry device names like
esp32orpico, and some carry an empty string. The mapping turns them into real device ids. Anything it can’t map shows up in the Devices panel as unregistered instead of quietly disappearing.
One generic API
The API has no per-device or per-metric routes:
GET /api/series?signals=env.temperature,env.humidity&range=24h&splitBy=device
GET /api/analytics?kind=typical-day&signals=env.temperature&range=30d
GET /api/analytics?kind=bins&x=env.temperature&y=env.humidity&range=30d
GET /api/summary GET /api/health GET /api/pump POST /api/pump
A signal in a disabled domain is rejected by the API, not just hidden in the UI. Feature flags gate panels, routes and background jobs together, and with the weather and forecast flags off the deployment makes zero outbound requests.
Small things that mattered
- Use a production build and keep one database handle. Reopening SQLite on
every panel poll had the container using a full CPU core. After the fix,
docker statsshows it close to idle. - Host networking exposes port clashes.
network_mode: hostmakes the LAN broker easy to reach, but a helper I wanted on one port collided with another container’s published port, even though mine only listened on loopback. - The Makefile is the manual.
make health,make mqtt-live,make db-latest,make db-hourly-diff DAYS=7,make pump-status.make helplists them all.
Takeaways
- SQLite is enough for one site and a million rows. Back it up properly (that’s the last post).
- One writer keeps the data layer simple.
- Put topic parsing in config, not in UI components. Every new device after that was cheap.
Next in this series: Migrating 395,931 Rows and a Zigbee Network Without Re-Pairing
Part 1 of 8. Start with the series overview.