Built on Rust's Async Ecosystem
A deep dive into the technology stack, operating modes, request lifecycle, and the lock-free configuration snapshot model that keeps reloads off the request path.
Core Dependencies
Every dependency was chosen for performance, correctness, and Rust-native design.
Multi-threaded async runtime. Work-stealing scheduler maximizes CPU utilization across all cores.
Production-grade HTTP/1.1 and HTTP/2 implementation. Powers most of Rust's web ecosystem.
Rust TLS protocol implementation. The default crypto provider is ring; the optional FIPS build uses AWS-LC. DTLS uses dimpl. Native dependencies remain in the full gateway build.
gRPC framework for the CP→DP config stream, mesh MeshSubscribe and xDS clients, the SPIFFE Workload API, and gRPC health checks. gRPC proxying itself runs directly on hyper’s HTTP/2.
IETF QUIC and HTTP/3 over UDP. Optional 0-RTT early data for configured replay-safe methods, off by default.
Async SQL with connection pooling for PostgreSQL, MySQL, and SQLite.
Typed deserialization of config, plugin configs, and API payloads. JSON and YAML support.
Structured, contextual logging with per-request spans. OpenTelemetry-compatible.
Atomic reference-counted pointer swaps. Config reads are wait-free. Updates are atomic. The key to zero-downtime reloads.
Sharded concurrent hash maps. Each shard has its own read-write lock, so lookups are O(1) average with no global lock, but they are not lock-free. Used for the route lookup cache, connection pools, and rate limiters.
Global allocator on Linux and macOS. Lower fragmentation and better multi-threaded allocation than the system malloc under high concurrency.
Eight Operating Modes
One binary, selected via FERRUM_MODE. Every topology below is the same executable.
:8000 / :8443
PG / MySQL / SQLite / Mongo
:8000 / :9000
:9000 / :50051
:8000 / :8443
:8000 / :8443
:8000 / :8443
FERRUM_DP_CONFIG_MAX_STALE_SECONDS (one hour by default). Horizontally scalable — add DP instances without touching CP.
MeshSubscribe / xDS ADS
sidecar / waypoint / gateway
one per node
FERRUM_MODE=migrate
Six Mesh Topologies
Mesh mode adapts to the topology each workload needs — all from the same binary and config model.
Sidecar
Per-pod proxy handling inbound mTLS (port 15006) and outbound capture (15001). The classic mesh pattern with the strongest per-workload isolation.
Ambient
Sidecar-less mesh using HBONE (HTTP/2 CONNECT over mTLS, port 15008) with node-level eBPF capture — mesh security without touching pod specs.
Node Waypoint (Experimental)
Per-node Layer 7 policy point for ambient workloads, resolving per-pod identity from node-agent eBPF socket records.
Service Waypoint
Service-scoped waypoint for Istio GAMMA traffic — attach L7 policy to a service without a proxy in every pod.
East-West Gateway
SNI-routed passthrough (port 15443) connecting clusters. Cross-cluster SPIFFE identity validation and trust bundle federation.
Egress Gateway
Controlled exit point for external traffic, materialized from ServiceEntry resources with identity baggage stripped at the boundary.
Request Lifecycle
Connection Accept
tokio accepts the TCP/UDP connection on the configured port. TLS handshake (rustls) if applicable, with ALPN selecting HTTP/1.1 or HTTP/2; plaintext HTTP/2 is detected from the h2c preface, and HTTP/3 arrives over QUIC.
Config Load (Lock-Free)
Atomic ArcSwap load. O(1), no blocking. Returns Arc pointer to current config. All concurrent requests share the same config Arc without copying.
Route Matching
Repeated (host, path) pairs are served from a bounded DashMap cache: O(1) average, one per-shard read lock. On a cache miss the route table, an ArcSwap snapshot rebuilt off the hot path whenever config changes, is searched by host tier (exact host map, then a short scan of wildcard-host patterns, then catch-all) and within a tier by exact path (O(1)), then longest prefix through an indexed walk of the path's segments (O(path depth), independent of route count), then regex routes in a single RegexSet pass. Misses are cached as well, including negative results, so a 404 for an unknown path is O(1) on repeat.
Plugin Chain Execution
Plugins run phase by phase, in priority order within each phase: on_request_received (CORS, IP restriction, termination) → authenticate → authorize (access control, rate limits) → before_proxy (header transforms), then request-body transforms. The plugin list for the proxy comes from an ArcSwap snapshot built at config load. Any phase can short-circuit with a rejection response.
Upstream Selection
Load balancing algorithm selects a healthy upstream from the pool. Health is read from a cached eligibility bitset that is rebuilt only when a health check marks a target unhealthy or recovered. The shared reqwest client for the destination is taken from the connection pool.
Proxy & Response
The request is dispatched over the pooled backend connection (HTTP/1.1, HTTP/2, HTTP/3, gRPC, or WebSocket), with retries and passive health reporting. The response streams back through after_proxy hooks; the body is buffered only when the proxy’s response_body_mode or a plugin requires it.
Logging Phase
log() hooks run in priority order once the response completes: buffered responses await them before returning, and streamed responses run them when the body finishes. Logging plugins hand records to bounded background sinks. The request then drops its config Arc — if config was swapped, the old version is freed here.
Atomic Config Swap
Data Structure Complexity Table
| Operation | Structure | Read | Write | Notes |
|---|---|---|---|---|
| Config access | ArcSwap | O(1) atomic | O(1) atomic swap | Wait-free reads |
| Route lookup (cache hit) | DashMap cache, prefix and regex partitions | O(1) average | O(1) shard-lock on miss insert | Bounded per partition; negative results cached; per-shard read lock, not lock-free; CPU-scaled shard counts (≥64) |
| Route lookup (cache miss) | ArcSwap route table: HashMap indexes + RegexSet | O(path depth) prefix; O(path length) regex | Rebuilt off the hot path on config change | Exact host and exact path are O(1); wildcard-host patterns are scanned linearly (typically few) |
| Consumer lookup | ArcSwap index: a HashMap per credential type | O(1) | Rebuilt off the hot path, swapped atomically on config change | By API key, username, identity, or mTLS certificate identity; lock-free reads |
| Rate limit check | DashMap of per-key windows | O(1) | O(1) under the key's shard write lock | Token bucket for windows up to 5 s, bounded sliding window above; not lock-free |
| Health state | DashMap of unhealthy targets + AtomicU64 generation | O(1) generation check, then a cached bitset | O(1) shard-lock, generation bump | Active-probe state shared per upstream, passive state per proxy; each balancer rebuilds its eligibility bitset only when the generation moves |
| Plugin lookup | ArcSwap snapshot: HashMap of per-proxy plugin lists | O(1) | Rebuilt off the hot path, swapped atomically on config change | Plugin instances are built at config load; unchanged proxies keep theirs across reloads; lock-free reads |
| Load balancing (RR) | Sharded AtomicU64 counters | O(1) | O(1) fetch_add | Cache-padded counter shards, index mod N |
| Load balancing (hash) | Consistent hash ring | O(log V) | O(V log V) rebuild on config change | V = 150 virtual nodes per target × N targets |
| Connection pool | DashMap of per-key reqwest clients + AtomicU64 last-use tick | O(1) | O(1) shard-lock on a new key | One client per destination and TLS identity; the client's own pool takes a short lock to check out a connection; a background task evicts idle clients |
Only the ArcSwap reads (configuration, route-table, consumer-index, and plugin-list snapshots) are lock-free. DashMap reads take a short per-shard read lock. Complexity figures describe the v0.9.20 implementation (src/router_cache.rs, src/consumer_index.rs, src/plugin_cache.rs, src/load_balancer.rs, src/health_check.rs, src/plugins/utils/rate_limit.rs, and src/pool/mod.rs); they bound work per request, not latency under saturation, which also depends on CPU headroom, enabled plugins, and upstream behavior.