Physics-based concurrency control for Node.js. Replaces static rate limits with adaptive thresholds, deterministic backpressure, and priority-based load shedding.
"Don't forbid wrong behavior. Make it physically unsustainable."
Atrion models your system as an electrical circuit. Each route has resistance that changes based on telemetry:
R(t) = R_base + Pressure + Momentum + ScarTissue
| Component | Description |
|---|---|
| Pressure | Current load (latency, errors, saturation) |
| Momentum | Rate of change (detects problems before they peak) |
| Scar Tissue | Historical trauma (remembers bad routes) |
This is Conditioned Deterministic Orchestration (CDO) — traffic routing as flow through impedance networks, where erroneous paths become physically inaccessible rather than explicitly forbidden.
Traditional fault tolerance mechanisms fail in predictable ways:
| Mechanism | Failure Mode |
|---|---|
| Circuit Breaker | Binary ON/OFF flapping during recovery |
| Rate Limiting | Static thresholds: night traffic triggers, peak blocked |
| Retry Backoff | Reactive, wastes resources on doomed requests |
| Health Checks | Misses "zombie" services (alive but broken) |
Standard health checks fail when a service is technically alive but behaviorally broken. Atrion measures Service Resistance — even if a node responds (but slowly or incorrectly), resistance spikes and triggers protective measures before cascade begins.
npm install atrionimport { Atrion } from 'atrion'
const atrion = new Atrion()
await atrion.connect()
// Make routing decision
const decision = atrion.route('api/checkout', {
latencyMs: 45,
errorRate: 0.01,
saturation: 0.3,
})
if (!decision.allow) {
return res.status(503).json({ error: decision.reason })
}
// decision.resistance = current Ω
// decision.mode = 'BOOTSTRAP' | 'OPERATIONAL' | 'CIRCUIT_BREAKER'Different baselines for different workloads — a 30-minute ML job should not trigger circuit breaker:
// Short-lived API (default)
atrion.route('api/users', telemetry)
// Heavy computation
atrion.route('ml/inference', telemetry, { profile: 'HEAVY' })
// Long-running task with lease
const lease = await atrion.startTask('genom/sequence', {
profile: 'EXTREME',
abortController: controller, // Required for HEAVY/EXTREME
})
lease.heartbeat({ progress: 0.5 })
await lease.release()| Profile | Baseline Latency | Use Case |
|---|---|---|
LIGHT |
10ms | Health checks, pings |
STANDARD |
100ms | REST APIs |
HEAVY |
5s | Video transcode, ML |
EXTREME |
60s | Genome sequencing, Swarms |
Atrion v2.0 ships with an optional Rust-powered physics core compiled to WebAssembly:
const atrion = new Atrion({
engine: 'auto', // Default: tries WASM, falls back to TypeScript
// engine: 'wasm' // Force WASM (throws if unavailable)
// engine: 'ts' // Force TypeScript
})| Metric | TypeScript | Rust/WASM | Improvement |
|---|---|---|---|
calculateResistance |
~50μs | 2.11 ns | ~25,000x |
| Throughput | ~20k ops/s | 586M ops/s | ~29,000x |
| GC Pauses | Yes | None | Deterministic |
WASM bundle size: 13.2KB gzipped. SIMD support: AVX2 (native), SIMD128 (WASM).
See RFC-0009 for technical details.
Atrion eliminates manual threshold configuration through Z-Score based auto-tuning:
dynamicBreak = μ(R) + 3σ(R)
| Scenario | Static Thresholds | Atrion |
|---|---|---|
| Low traffic | Threshold too loose | Tight threshold (low μ) |
| Peak traffic | Threshold too tight | Relaxed threshold (high μ) |
| New deployment | Manual configuration | Learns within minutes |
Swappable backends for different deployment scenarios:
import { Atrion, InMemoryProvider, RedisStateProvider } from 'atrion'
const atrion = new Atrion({
provider: new InMemoryProvider(), // Default: single-node
// provider: new RedisStateProvider(redis) // Multi-node cluster
})| Provider | Use Case |
|---|---|
InMemoryProvider |
Single-node, development |
RedisStateProvider |
Multi-node cluster (basic sync) |
Configure different SLOs per route. Protect revenue-critical paths while shedding non-essential traffic:
atrion.setRouteProfile('api/checkout', { scarFactor: 2 }) // High priority
atrion.setRouteProfile('api/search', { scarFactor: 20 }) // Lower priorityValidated result: 84% revenue efficiency during Black Friday stress simulation.
Standard circuit breakers remain open until timeout. Atrion exits circuit breaker state automatically when resistance drops below threshold:
R < 50Ω → Exit circuit breaker
| Test | Metric | Result |
|---|---|---|
| Flapping | Transitions during stress | 1 vs 49 (standard CB) |
| Gray Failure | Zombie detection | Detected via R spike |
| CB Recovery | Exit from circuit breaker | At R=49.7Ω |
| Priority Shedding | Revenue protected | 84% efficiency |
| WASM Parity | TS vs Rust differential | 9/9 tests passing |
| RFC | Topic | Status |
|---|---|---|
| RFC-0001 | Core Mathematical Model | Implemented |
| RFC-0007 | Adaptive Thresholds | Implemented |
| RFC-0008 | Pluggable State | Implemented |
| RFC-0009 | Rust/WASM Performance | Implemented |
| RFC-0010 | Workload Profiles | Implemented |
Full RFC index: documentation/rfc/README.md
Real-world scenario simulations in the lab/ directory:
# E-Commerce: VIP priority during DB stress
npx tsx lab/ecommerce/ecommerce-server.ts
npx tsx lab/ecommerce/blackfriday-client.ts
# Circuit Breaker: Recovery validation
npx tsx lab/cb-recovery/cb-server.ts
npx tsx lab/cb-recovery/recovery-client.tsSee lab/README.md for all scenarios.
| Version | Status | Highlights |
|---|---|---|
| v2.0.0 | Released | WASM default, Workload Profiles |
| v2.1.0 | In Progress | AI Swarm, Dynamic Profiles |
| v3.x | Planned | Dashboard, Prometheus, OpenTel |
See ROADMAP.md for details.
See CONTRIBUTING.md for guidelines.
Apache-2.0
