lietzsche;stokes

updated 2026-11-26·5 min read

Architecture Vision & Design Tradeoffs

Why forcing Protobuf or gRPC onto ClickHouse, Python, and Rust breaks down, and how Stokes checks boundaries without codegen.

Whenever two services drift out of sync, the standard textbook reflex is forcing Protobuf, gRPC, or FlatBuffers across the whole stack. On an analytical pipeline feeding a low-latency edge proxy, that cure is kind of miserable: ClickHouse speaks SQL catalog views (system.columns), generated IDL wrappers replace cache-aligned Rust structs with heap strings and pointer indirection, and repeated Feature items = 1; still doesn’t cap array length on the wire anyway.

I built Stokes around a smaller bet: keep idiomatic SQL, Python, and Rust untouched, and catch cross-language cardinality mismatches (emitted_columns > buffer_capacity) at the untyped seam in CI before TryFromSliceError hits production.

How Three Clean Repos Still Crash Together

A three-tier production cascade doesn’t look broken in any single repository:

  1. Analytical Data Layer (SQL DDL)

    A team provisions internal shard tables (signals_shard_r0, signals_shard_r1) for offline experiments. Valid ANSI SQL passes sqlfluff and sqllineage without warnings.

  2. Feature Extraction Pipeline (Python ETL)

    A worker executes SELECT name FROM system.columns WHERE table LIKE 'signals%', reflecting 280 columns instead of 200 canonical signals and serializing dict[str, Any] payloads to KV storage. mypy and pytest report green.

  3. Edge Ingress Proxy (Rust L7 Engine)

    To stay within tight microsecond budgets, the proxy decodes into a fixed stack array [Feature; 200]. Calling .try_into().unwrap() on 280 items triggers TryFromSliceError and worker crash loops.

Why Single-Language Linters Provide False Confidence

Every compiler or linter only proves things inside its own closed world:

Compiler / ToolVerification DomainBlind Spot
sqlfluffSQL AST, lexical grammar, dialect syntaxIgnores which downstream services consume query result sets.
mypy / pyrightPython type hints, class signaturesTreats external network payloads and serialized dicts as unchecked Any.
rustc / clippyRust borrow checker, memory safety, local monomorphizationAssumes external wire inputs conform to declared stack buffer lengths.
buf / protocProtobuf schema syntax, backward field numberingDoes not govern dynamic SQL tables or KV payload boundaries without IDL rewrites.

The bug isn’t inside the SQL, Python, or Rust repo by itself, albeit each local linter passes. It lives purely in the mismatch between upstream emitted columns (280) and downstream stack buffer capacity (200).

Design Tradeoffs

1. Declarative Manifests vs. Intrusive IDLs

Databases like ClickHouse, PostgreSQL, and Snowflake speak relational algebra and catalog views (system.columns), not gRPC. Worse, IDL codegen replaces zero-copy #[repr(C, align(8))] structs with generated wrappers full of heap allocations. Stokes skips codegen and pairs static AST/regex extraction with a lightweight stokes.toml manifest, keeping your existing DDL, Python extractors, and Rust structs intact.

Example stokes.toml Boundary Manifest
# stokes.toml: Declarative non-intrusive boundary definition
[workspace]
name = "cloudflame-l7-proxy"
version = "1.0.0"
strict = true

[[channels]]
id = "analytics_to_edge_l7"
wire_format = "json"
transport = "kv_store"

[channels.producer]
sql_schema = "migrations/001_bot_signals.sql"
python_source = "services/feature-pipeline/catalog_sync.py"
symbol = "extract_features"
cardinality_limit = 200

[channels.consumer]
rust_source = "crates/cloudflame-proxy/src/engine/feature_ingest.rs"
symbol = "[FeatureDescriptor; 200]"
capacity_limit = 200
core_reserved_slots = 128
adaptive_slots = 72

See Channel Manifests for binding rules.

2. Zero-Runtime Overhead in Production

Edge proxies evaluate packets in microseconds, so they can’t afford runtime eBPF probes or schema validator sidecars on the hot path. Stokes keeps verification strictly in CI and pre-commit:

PhaseRuntime EnvironmentExecution BehaviorVerification Mechanism
Pull Request (CI Gate)GitHub Actions / GitLab CIStatic AST/regex scan (no containers or rustc)Boundary traversal, cardinality bounds, stokes.lock check
Data Plane (Production)Edge Reverse Proxy (Rust / C++)0 ns Stokes overheadNative Dual-Zone stack buffers, zero dynamic heap allocations

3. Tolerant Readers & Staged Rollout Coordination

If you wire a naive cross-repo CI check between two repos that ship separately, you get an instant circular deadlock: upstream can’t add columns until downstream grows its buffer, and downstream won’t merge until upstream changes. Stokes breaks that cycle by expanding downstream buffers first (buffer_capacity >= emitted_columns at every step):

  1. Step 1
    Downstream Buffer Expansion

    Edge proxy PR expands stack buffer to 512 slots ([Feature; 512]) while upstream emits 200. Merges and deploys first.

  2. Step 2
    Upstream Emission Expansion

    Analytics PR expands ClickHouse DDL and worker emission to 280 items inside a 512-slot fleet. Deploys with zero downtime.

  3. Step 3 (Optional)
    Buffer Compaction

    Edge proxy compacts buffer from 512 down to exact target 280 once rollout settles.

For the full multi-repository protocol and 2-Phase Semantic Staging, see Poly-Repo Protocol.

Architectural Comparison Matrix

CapabilityTraditional LintersTraditional IDLsDynamic Taint AnalysisStokes Platform
Analysis ScopeSingle translation unitWire schema definitionsInterprocedural source-to-sinkPolyglot cross-boundary interface graphs
Execution CostSecondsCode generation timeMinutes to hoursSingle-pass static scan (no containers)
Runtime Overhead0 nsMicroseconds (serialization)15% to 40% if instrumentedExactly 0 ns (zero binary injection)
SQL Schema VisibilityNoneNoneLimited / heuristicDirect AST / regex DDL introspection
Multi-Repo SafeNoNo (shared schema repos)NoYes (staged consumer-first verification)
AI Agent InterfaceNoneNoneNoneNative JSON-RPC MCP Server (stokes mcp)

Keep sqlfluff for SQL formatting, ruff and mypy for Python idioms, and cargo clippy for Rust linting. Stokes only steps in at the cross-boundary gate where single-language tools lose visibility.

Next, follow Quickstart & CLI Guide to initialize a workspace or read Untyped Seams Across Compilers for a concrete breakdown of how cross-tier drift breaks production.

Search wiki and portfolio

type to search across all entries.