The Database

The database is the data the engine keeps: the records themselves, stored in order. In AltSql it’s one set of records from the sensor to the gateway, and both of the engine’s doors reach every one of them.

One Set of Records, From Sensor to Gateway

A device writes each reading or setting once, as a record with a sequence number and a checksum. The gateway receives those same records byte for byte and files each one under a key: for a reading, which device, what time and its sequence number. The payload stays exactly as the device wrote it. Nothing converts it on the way, so there’s no second copy to keep in step.

A reading stored as an AltSql record takes 26 bytes. The same reading as JSON takes 53.

On the device, a log in flash: records go into five sectors one after another, oldest to newest, with two sectors free. One record is a 12-byte header (the marker A5, its type, its length, its sequence number and a checksum) and then the payload, the reading or setting as written. An arrow: the same records, byte for byte, each batch saved in one transaction and confirmed with one number. On the gateway, the whole fleet in one file, sorted by key: two commit headers, on pages 0 and 1, point to a root page; under it, branch pages and leaf pages hold keys of device, time and sequence number, so device 17 over time is one sorted run of records. get/put takes one walk from the root to a leaf, and SQL takes the same walks and scans along the leaves. One set of records: written once on the device, filed by key on the gateway, reached through both doors.

On the Device: A Log in Flash

The device keeps its records in its own flash, in a log built for chips that wear with every erase and can lose power in the middle of a write. It reads them back to decide on the spot, and it keeps working when the link drops. In one simulated run the power was cut 400,000 times, with nothing saved lost.

On the Gateway: The Whole Fleet in One File

The gateway keeps every device’s records in one file, sorted by key, so any record can be found without reading the rest. One device over a stretch of time is one sorted run of records. A batch from a device is saved in one transaction, a batch sent twice is applied once, and the gateway confirms it with one number. Two commit headers, written in order, mean a power cut leaves the file as it was before a change or after it.

In the Alpha, 100 simulated devices synced a million readings into one file at 279,094 readings a second, with 35.1 bytes of file per reading.

Both Doors, the Same Records

The gateway’s programs fetch what they can name by key, like a device’s latest reading or a command waiting for it. Engineers ask SQL questions of the same records, on the live data, with nothing exported first. Whatever goes in through one door is there for the other the moment it’s committed.

The live demo shows twelve devices syncing into one file in your browser. The engine page says how the two doors work, and AltSql DB has the gateway database in detail.