← Back to projects

Tiny AMPS: Zero-Allocation IoT Edge Gateway & Telemetry Router

2026-06-20 · research · Amsterdam, NL / Remote ★ Featured
#odin#systems-programming#networking#iot#protocols#telemetry

Stop Paying the "Subscriber Tax"

Distributed edge systems (drones, industrial sensors, robotics) are overwhelmed by telemetry ingestion costs and client-side processing overhead. Traditional messaging protocols (MQTT, ZMQ, RabbitMQ) broadcast raw telemetry data to all subscribers, forcing resource-constrained edge devices to ingest, deserialize, and discard up to 99% of irrelevant updates on their local CPU. This is the Subscriber Tax.

Tiny AMPS is an edge telemetry gateway and high-frequency message broker written in Odin designed to eliminate this tax. By evaluating user-defined logic filters directly on the broker at the edge socket layer, Tiny AMPS reduces network bandwidth and subscriber CPU usage by over 98% with sub-millisecond latencies.

Key Innovations & Architecture

#### 1. Server-Side Content-Based Filtering Edge subscribers register queries like `temp > 85.0 OR vib > 0.8`. The Odin-based broker parses these expressions and evaluates them on incoming packet streams, forwarding only matching events to the network wire.

#### 2. Zero-Allocation Circular Replay Buffer To support offline tolerance without garbage collection spikes, we implemented a thread-safe circular ring buffer. Evictions and additions occur in constant $O(1)$ time, eliminating all memory allocations on the hot path.

#### 3. Lightweight Header-Only C++ Client (`TinyAMPSClient.h`) Tailored for POSIX workstations and microcontrollers (ESP32/Arduino), the client includes:

  • Endian Independence: Custom bit-shift operations serialize packet headers (`[2-byte topic_len] [4-byte body/filter_len]`) safely across diverse host architectures.
  • Thread-Safe Socket Teardown: Uses POSIX `::shutdown` in its teardown sequence to prevent block-recv thread hangs.
  • #### 4. Lightweight KMS & Dynamic Session Rekeying To keep data transport fast while securely establishing session-specific keys, we built a dual-stage connection handshake. Clients initially establish a temporary context encrypted using a static bootstrap key, authenticate with a ticket issued by the KMS portal, and transition to a cryptographically unique ephemeral session key derived on-the-fly.

    #### 5. Lock-Free Concurrency & Readers-Writer Locks To resolve shared state bottlenecks in high-frequency message routing, we replaced global mutex locks with atomic statistics counters (`sync.atomic_add`) and a Readers-Writer Mutex (`sync.RW_Mutex`) for subscription tables. The HTTP dashboard thread and the routing loop concurrently acquire shared read locks, avoiding lock contention on the hot path.

    #### 6. Instant Revocation & Blacklisting The admin portal exposes a secure, token-protected revocation REST endpoint. When an administrator blacklists a device ID, the broker immediately closes all its active TCP socket connections, terminates subscriber channels, and rejects future ticket handshakes.

    ---

    Quantitative Performance Gains

    Under a benchmark workload of 20,000 high-frequency messages comparing Mode A (traditional opaque pub/sub) against Mode B (Tiny AMPS content-filtered routing), the performance gains are empirical:

    | Metric | Traditional Opaque Pub/Sub (Mode A) | Tiny AMPS Filtered Pub/Sub (Mode B) | Impact | | :--- | :--- | :--- | :--- | | Messages Delivered to Client | 19,903 | 201 | 98.99% network traffic cut | | Subscriber Thread CPU Time | 0.2911 seconds | 0.0213 seconds | 92.68% CPU recovered | | Python GC Gen 0 Runs | 5 collections | 0 collections | Eliminated heap churn / latency spikes |

    ---

    Swarm Simulation Integration

    We built a Pygame-based swarm intelligence simulation to visually demonstrate these gains. It models a coordinate-chase duel between two teams:

  • RED (Tiny AMPS): Receives coordinate updates instantly, allowing zero-lag Brain transitions (`SunflowerBrain`, `ZMQBrainLike`).
  • BLUE (Legacy): Suffers from a 2.5-second bufferbloat delay due to queue saturation (the Subscriber Tax).
  • Because RED reacts instantly to dynamic flag coordinates and coordinates swarming behavior in real-time, RED consistently defeats BLUE (e.g. scoring 5-0 rounds).

    ---

    Interactive Web Showcase

    We have built a single-page interactive showcase featuring a live industrial edge gateway simulator. Explore the live canvas waveform rendering, trigger a simulated WAN network outage to watch the gateway cache alarms to disk, and watch the cost-savings accrue in real-time:

    👉 Click here to try the Interactive Live Simulation