<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: David MARTIN</title>
    <description>The latest articles on DEV Community by David MARTIN (@zeekmartin).</description>
    <link>https://dev.to/zeekmartin</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3728806%2Fb7e7b0ad-bbcb-432b-8e19-174932bb89e1.png</url>
      <title>DEV Community: David MARTIN</title>
      <link>https://dev.to/zeekmartin</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/zeekmartin"/>
    <language>en</language>
    <item>
      <title>"Shannon Was Right, But We Can Be Smarter: How ALEC Achieves 22x Compression on IoT Data"</title>
      <dc:creator>David MARTIN</dc:creator>
      <pubDate>Fri, 23 Jan 2026 15:37:57 +0000</pubDate>
      <link>https://dev.to/zeekmartin/shannon-was-right-but-we-can-be-smarter-how-alec-achieves-22x-compression-on-iot-data-3b3m</link>
      <guid>https://dev.to/zeekmartin/shannon-was-right-but-we-can-be-smarter-how-alec-achieves-22x-compression-on-iot-data-3b3m</guid>
      <description>&lt;h2&gt;
  
  
  The Problem That Shouldn't Exist
&lt;/h2&gt;

&lt;p&gt;I was working on an IoT project—temperature sensors reporting values every second. Simple stuff:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;22.5, 22.5, 22.6, 22.5, 22.5, 22.6, 22.6, 22.5, ...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each value takes 8 bytes as a float64. That's &lt;strong&gt;691 KB per sensor per day&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;"No problem," I thought. "Let's compress it with gzip."&lt;/p&gt;

&lt;p&gt;Result: &lt;strong&gt;~400 KB&lt;/strong&gt;. Only 42% compression.&lt;/p&gt;

&lt;p&gt;Wait, what? The data is &lt;em&gt;obviously&lt;/em&gt; redundant. A human can see the pattern instantly. Why can't gzip?&lt;/p&gt;

&lt;h2&gt;
  
  
  Shannon Was Right (Of Course)
&lt;/h2&gt;

&lt;p&gt;Claude Shannon proved in 1948 that you can't compress data below its entropy. Period. No exceptions.&lt;/p&gt;

&lt;p&gt;But here's the key insight Shannon himself noted: &lt;strong&gt;entropy depends on your model of the data&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If gzip treats &lt;code&gt;22.5, 22.5, 22.6&lt;/code&gt; as arbitrary bytes, it sees one entropy. But if we model it as "temperature sensor with 0.1°C precision, typically stable", the entropy is &lt;em&gt;much&lt;/em&gt; lower.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The trick isn't violating Shannon's theorem. It's building a better model.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The IoT Data Model
&lt;/h2&gt;

&lt;p&gt;Real IoT sensor data has properties that generic compressors ignore:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Temporal stability&lt;/strong&gt; - Values change slowly&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Predictability&lt;/strong&gt; - Next value ≈ current value&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bounded range&lt;/strong&gt; - Temperature won't jump from 22°C to 500°C&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Quantization&lt;/strong&gt; - Sensors have finite precision (0.1°C)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;An intelligent compressor that exploits these properties can dramatically outperform generic alternatives.&lt;/p&gt;

&lt;h2&gt;
  
  
  Enter ALEC
&lt;/h2&gt;

&lt;p&gt;I built &lt;a href="https://github.com/zeekmartin/alec-codec" rel="noopener noreferrer"&gt;ALEC&lt;/a&gt; (Adaptive Lazy Evolving Compression) specifically for IoT data. The core ideas:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Delta Encoding
&lt;/h3&gt;

&lt;p&gt;Instead of transmitting &lt;code&gt;22.5&lt;/code&gt;, transmit &lt;code&gt;+0.0&lt;/code&gt; (delta from last value).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Raw:    22.5 → 22.5 → 22.6 → 22.5
Delta:  22.5 →  0.0 → +0.1 → -0.1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Zero delta? That's 2 bits instead of 64.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Pattern Dictionary
&lt;/h3&gt;

&lt;p&gt;Frequent values get short codes. After observing &lt;code&gt;22.5&lt;/code&gt; appear 1000 times, it gets a 4-bit code instead of 64 bits.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Evolving Context
&lt;/h3&gt;

&lt;p&gt;Encoder and decoder maintain synchronized context that improves over time:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Week 1:  "temperature=22.3°C" → 20 bytes
Week 4:  [code_7][+0.3]       → 3 bytes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The Benchmark Results
&lt;/h2&gt;

&lt;p&gt;I ran ALEC against gzip on real IoT data patterns. Here's what happened:&lt;/p&gt;

&lt;h3&gt;
  
  
  On Variable Data (SmartGrid current sensor, only 8.7% unchanged readings)
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Condition&lt;/th&gt;
&lt;th&gt;ALEC&lt;/th&gt;
&lt;th&gt;gzip&lt;/th&gt;
&lt;th&gt;ALEC Advantage&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Cold start&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;10.9x&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;5.1x&lt;/td&gt;
&lt;td&gt;+113%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;With preload&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;22.1x&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;8.0x&lt;/td&gt;
&lt;td&gt;+177%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fplaceholder-benchmark.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fplaceholder-benchmark.png" alt="ALEC vs gzip comparison" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  The Warmup Curve
&lt;/h3&gt;

&lt;p&gt;Here's where it gets interesting. ALEC dominates at &lt;em&gt;every&lt;/em&gt; sample count:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Samples    | gzip   | ALEC
-----------|--------|-------
10         | 0.9x   | 8.0x   ← ALEC wins immediately
100        | 2.4x   | 9.2x
1000       | 6.3x   | 11.4x
5000       | 7.4x   | 18.2x
8640       | 8.0x   | 22.0x
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At 10 samples, gzip can't compress at all (0.9x = expansion!). ALEC achieves 8x because it understands the data model from the start.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Preload Secret
&lt;/h2&gt;

&lt;p&gt;The key insight: &lt;strong&gt;preload eliminates warmup cost&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In production, you:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Generate a preload file from historical data&lt;/li&gt;
&lt;li&gt;Ship identical preload to encoder and decoder&lt;/li&gt;
&lt;li&gt;Achieve near-optimal compression from byte one&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Without preload, ALEC still beats gzip. With preload, it's not even close.&lt;/p&gt;

&lt;h2&gt;
  
  
  When NOT to Use ALEC
&lt;/h2&gt;

&lt;p&gt;ALEC isn't magic. It won't help with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Random data&lt;/strong&gt; - No patterns to learn&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Very short transmissions&lt;/strong&gt; - &amp;lt;100 samples, warmup dominates&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Constant data&lt;/strong&gt; - Trivially compressed by any codec&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The sweet spot: &lt;strong&gt;long-running IoT streams with predictable patterns&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try It Yourself
&lt;/h2&gt;

&lt;p&gt;ALEC is open source (AGPL-3.0) and available on crates.io:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;alec&lt;/span&gt;&lt;span class="p"&gt;::{&lt;/span&gt;&lt;span class="n"&gt;Encoder&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Decoder&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Context&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;encoder&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;Encoder&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;decoder&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;Decoder&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;Context&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// Encode&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;encoder&lt;/span&gt;&lt;span class="nf"&gt;.encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="nf"&gt;.observe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Decode&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;decoded&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;decoder&lt;/span&gt;&lt;span class="nf"&gt;.decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;📦 &lt;strong&gt;Crates.io&lt;/strong&gt;: &lt;a href="https://crates.io/crates/alec" rel="noopener noreferrer"&gt;alec&lt;/a&gt;&lt;br&gt;
🔗 &lt;strong&gt;GitHub&lt;/strong&gt;: &lt;a href="https://github.com/zeekmartin/alec-codec" rel="noopener noreferrer"&gt;zeekmartin/alec-codec&lt;/a&gt;&lt;br&gt;
🌐 &lt;strong&gt;Website&lt;/strong&gt;: &lt;a href="https://alec-codec.com" rel="noopener noreferrer"&gt;alec-codec.com&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The Bottom Line
&lt;/h2&gt;

&lt;p&gt;Shannon's theorem is inviolable. But Shannon also taught us that entropy depends on our model.&lt;/p&gt;

&lt;p&gt;Generic compressors use generic models. Domain-specific compressors use domain-specific models.&lt;/p&gt;

&lt;p&gt;For IoT data, that difference is &lt;strong&gt;22x vs 8x compression&lt;/strong&gt;.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;"Every byte counts. Everywhere."&lt;/em&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Discussion
&lt;/h3&gt;

&lt;p&gt;Have you hit bandwidth limits with IoT data? What compression approaches have you tried? Let me know in the comments!&lt;/p&gt;




&lt;p&gt;&lt;em&gt;ALEC is dual-licensed: AGPL-3.0 for open source, commercial licenses available for proprietary use.&lt;/em&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  iot #rust #compression #embedded #dataengineering
&lt;/h1&gt;

</description>
      <category>iot</category>
      <category>rust</category>
      <category>dataengineering</category>
      <category>shannon</category>
    </item>
  </channel>
</rss>
