From 137 Bytes to 2.7: How Much Space Does Factory Data Really Take? UNS to Lakehouse — Part 3
From the publisher’s feed, collected in the ZeroLabs newsroom.
One day of a virtual bottling plant, stored eleven different ways. The winner is 51 times smaller than the raw messages, and two of the “optimizations” along the way made things worse.A pressure sensor reports 800.53 mbar. The number takes six characters, but the message carrying it through the Unified Namespace takes 134 bytes.That gap is easy to ignore with one sensor. A plant with a few thousand signals publishes millions of such messages a day. Most teams that decide to “just keep the history” start by writing those messages to disk as they arrive. That is a sensible first step, and an expensive one if it becomes the long-term format.In Part 2 we built a virtual factory: three lines, eight machines, 37 signals, faults, frozen sensors and network outages, all deterministic from a single seed. This post uses one simulated day of that factory to answer a narrow question with real numbers: how much space does this data take, and which storage decisions actually matter?The setupThe experiment simulates 24 hours of the plant, with seed 42 and report-by-exception enabled. That produces 1,158,046 published readings. The same table is then written in eleven formats:Text formats: JSON lines (one raw MQTT message per line, topic plus payload) and CSV, each with and without gzip.Parquet with different codecs: uncompressed, snappy and zstd.Parquet tuned further: a different sort order, delta-encoded timestamps, byte-stream-split floats, and a different way of storing the delivery time.Each variant is written three times, and the median write time is reported. For Parquet, the script also reads the file metadata to see how many bytes each column takes. Everything runs with one command:git clone https://github.com/BuseKaylan/uns-to-lakehouse.gitcd uns-to-lakehousemake installmake bench-storageAll results are committed to the repository under benchmarks/results/01_storage_footprint/ as CSV and JSON, together with the Python and library versions that produced them. My numbers come from a 16-core Intel MacBook running Python 3.14 and pyarrow 26. File sizes are identical on any machine, because the data is deterministic. Write times will differ.Anatomy of one messageBefore comparing formats, it helps to look at what is being stored.Here is one reading as a raw UNS message:{"topic": "acme-plant/filling-area/line-1/filler/pressure", "payload": {"value": 800.53, "unit": "mbar", "timestamp": 1767592800000}}Of its 134 bytes:46 are the topic path, which is the same on every pressure message from this machine.65 are keys, quotes, braces and spaces, which are identical in every message.13 are the timestamp, and 4 are a unit that never changes.6 are the measurement itself.Averaged over the whole day, a message is 137.15 bytes. Raw JSON is not wasteful because JSON is bad. It is wasteful because each message is written to be understood on its own, without knowing what came before. That is exactly right on the wire and exactly wrong on disk.Round 1: text formatsCSV removes the repeated keys but keeps the repeated topic path, so it only saves about 20%. Gzip is the real step: 21 to 22 times smaller than raw JSON. That shows how much repetition there is to remove.The catch is that a gzip file is one opaque stream. To answer “what was the average vibration on line 2 between 14:00 and 15:00”, a query engine has to decompress and parse the whole day. Text plus gzip is a good archive format, not a good analytics format.A note on the write times: the JSON writer is a Python loop that builds one dictionary per row, while CSV and Parquet are written by Arrow’s C++ code. The gap says more about Python vs. C++ than about the formats themselves.Round 2: columns instead of rowsParquet stores each column separately. That one change lets every column use the encoding that suits it.Laid out by column, the hierarchy becomes trivial to compress:A column like machine is just a handful of distinct strings repeated over and over. Parquet stores a small dictionary once (filler, capper, labeler…) and then only small integer indices.A column like event_ts has long runs of the same value, because every sensor publishes in the same second. Runs are encoded once with a count.Uncompressed Parquet, with no compression codec at all, is already 15 times smaller than JSON. Encoding alone does most of the work. With zstd the file is 29 times smaller, beats gzipped text, and stays fully queryable by column. Writing it took about 0.4 seconds.Where the bytes goA file size alone doesn’t say what to fix next. Parquet records the compressed size of every column in its metadata, so we can look inside.In the zstd file:value takes 3.49 MB of the 5.52 MB total.The two timestamps take 0.81 MB.The five hierarchy columns (area, line, machine, metric, unit) still take 1.21 MB.That last number looks like an obvious target. The usual advice for time-series data is to sort by series and then by time, which puts each sensor’s history in one stretch. So that is the next experiment.Surprise 1: sorting made the file biggerSorting by area, line, machine, metric, event_ts did exactly what was expected for the strings: the hierarchy columns went from 1.21 MB to 0.02 MB. The values improved as well, from 3.49 MB to 2.51 MB, because neighbouring values now come from the same sensor and look alike.The file still went from 5.52 MB up to 8.18 MB.The cost moved to the timestamps:In arrival order, dozens of readings in a row share the same second. The timestamp column is long runs of identical values, which dictionary and run-length encoding handle almost for free.Sorted by sensor, every row has a different timestamp. The dictionary now holds 86,400 distinct seconds, every row needs a 17-bit index into it, and the two timestamp columns grow from 0.81 MB to 5.63 MB.The fix is to store timestamps the way a sorted column wants to be stored: as differences. Delta encoding (DELTA_BINARY_PACKED in Parquet) keeps the first value and then only the gaps: +1000, +2000, +3000 milliseconds. Those gaps fit in a few bits.The lesson: a sort order is not an optimization on its own. It changes which columns are cheap and which are expensive, and it only pays off when the encodings follow.Surprise 2: the float encoding that didn’t helpParquet also offers BYTE_STREAM_SPLIT, an encoding designed for floating-point data. It regroups the bytes of each float so the compressor sees similar bytes next to each other. It is often recommended for sensor measurements.On this data it made the value column 65% larger: 2.51 MB → 4.13 MB.The reason is in the data. The simulator rounds to three decimals, the way most PLCs and gateways report, and report-by-exception only publishes when a value moves. As a result there are only 219,174 distinct values among 1.16 million readings. That suits dictionary encoding, which byte-stream-split replaces. On raw high-resolution floats the result could well be the opposite. The result belongs to this data, not to the encoding, and that is exactly why it was measured instead of assumed.Surprise 3: the column that was mostly a copyThe schema carries two timestamps:event_ts: when the value was measured.delivered_ts: when it reached the broker.They differ only for readings that were buffered during a network outage and forwarded later. That is what store-and-forward means, and the late readings are flagged as historical. In this day that is 22,601 readings, about 2%. For the other 98%, delivered_ts is an exact copy of event_ts, and it still cost 0.57 MB, about 15% of the file.Storing the delay in milliseconds instead (delay_ms = delivered_ts - event_ts) loses nothing, because the delivery time can always be recomputed. But the column becomes a long run of zeros, broken only by outages, and it shrinks to 0.03 MB.In this final file, value is 80% of the bytes and event_ts most of the rest. Everything describing where a reading came from costs almost nothing. What remains is mostly the measurements themselves, which is where a storage format should spend its bytes.The full scoreboardFor 37 signals, the difference is 58 GB a year against 1.1 GB a year. Scaled linearly to a plant with 10,000 signals, it is roughly 15.7 TB against 310 GB. That is the difference between a storage project and a rounding error.What report-by-exception saves on diskReport-by-exception publishes a value only when it moves past a deadband, or when a heartbeat interval expires. In this factory, sensors took 2,090,880 samples during the day and published 1,158,046 of them, about 55%.To see what that is worth on disk, the experiment runs the same day a second time with report-by-exception turned off, and writes both runs as raw JSON and as the best Parquet variant.In JSON, the saving follows the message count almost exactly, because every message costs the same. In Parquet the saving is smaller, because the readings that report-by-exception drops are exactly the ones that compress best: values that didn’t change, at regular intervals. A good columnar format already removes much of that redundancy on its own.Report-by-exception still matters, mainly for the broker, the network and every consumer that has to process each message. For storage, the format decision is worth far more than the publishing policy.What this decides for the table designNever keep raw JSON as the history. Even untuned Parquet is 15 times smaller and can be queried by column.Use zstd. On this data it is a third smaller than snappy, at no measurable cost in write time.Sort by sensor, then time, inside each file. The hierarchy columns become nearly free and the values compress better.Delta-encode timestamps whenever data is sorted. Without it, sorting makes things worse.Store the delivery delay, not a second timestamp. The late-data information stays and costs almost nothing.Measure before tuning float encodings. The “right” encoding depends on resolution and on how often values repeat.LimitationsThis is simulated data from one virtual plant, not a real factory. Real signals have more noise, more resolution and more irregular publishing. The relative ordering of the formats should hold, but the exact ratios will not.One day was written as one file. Real ingestion writes many smaller files over time, and each file pays its own overhead. That is a separate problem with its own experiment later in the series.Write times come from one laptop, and they compare a Python JSON writer with Arrow’s native writers.Nothing here includes table-format metadata yet. The numbers are the pure Parquet cost of the data.The next question follows directly: so far every reading has been one row with one value. Part 4 compares that narrow layout with wide and hybrid tables, where one row holds a whole machine.The full code, raw results and charts are in the repository: github.com/BuseKaylan/uns-to-lakehouse.From 137 Bytes to 2.7: How Much Space Does Factory Data Really Take? UNS to Lakehouse — Part 3 was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.