EWMA Dynamic Health Scoring Formula for Upstream Routing
Static priority lists keep sending traffic to slow or noisy upstreams until they hard-crash. FuelRouter computes a continuous [0.0, 1.0] dynamic health score per upstream using Exponentially Weighted Moving Averages (EWMA, alpha = 0.25) persisted in SQLite WAL.
Dynamic Health Score Component Weights & Penalties
| Component | Weight / Coefficient | Cold-Start Default | Purpose |
|---|---|---|---|
| base_health_weight | +0.25 prior weight | 0.87 - 0.96 per upstream | Anchors historical reliability across cold starts |
| ewma_success_rate | +0.50 weight (alpha=0.25) | base_health_weight | Dominant signal favoring verified HTTP 2xx outcomes |
| latency_score | +0.15 weight (clamped 0.1-1.0) | 1.0 at expected_p95_ms | Demotes sluggish upstreams exceeding expected p95 latency |
| cleanliness (1 - fake_200_rate) | +0.10 weight | 1.0 (0% fake-200) | Penalizes silent HTML/CAPTCHA/error-JSON emitters |
| consecutive_failures | -0.12 per consecutive step | 0 failures | Immediate score drop after 1st or 2nd failure before OPEN trip |
| soft_banned_active | -0.50 flat penalty | false (0.0) | Pushes CAPTCHA-challenged upstreams to bottom of pool |
Continuous Latency & Cleanliness Normalization
Latency degrades smoothly rather than via cliff edges: latency_score = clamp(1.0 - max(0.0, ewma_latency_ms - expected_p95_latency_ms) / (4.0 * expected_p95_latency_ms), 0.1, 1.0). An upstream running at 2x its expected p95 loses 25% of its latency component immediately.
Cleanliness tracks 1.0 - ewma_fake_200_rate, ensuring an upstream that returns intermittent empty shells drops below cleaner peers even before hitting 3 consecutive failures.
Interaction Between Cost Tier and Dynamic Health Score
FuelRouter sorts by (unit_cost_micros ASC, -round(dynamic_health_score, 4), -round(remaining_free_quota_ratio, 4), priority_rank ASC). Within the $0 free tier, the healthiest fast upstream wins every call.
When a free-tier upstream accumulates 1 or 2 consecutive failures (-0.12 or -0.24 penalty), healthier $0 peers overtake it immediately—often avoiding a full circuit trip altogether.
Exact FuelRouter Health Score Reference Computation
latency_score = clamp(1.0 - max(0.0, ewma_latency_ms - expected_p95_ms) / (4.0 * expected_p95_ms), 0.1, 1.0)
cleanliness = clamp(1.0 - ewma_fake_200_rate, 0.0, 1.0)
raw_score = (0.25 * base_health_weight) + (0.50 * ewma_success_rate) \
+ (0.15 * latency_score) + (0.10 * cleanliness)
penalty = (0.12 * consecutive_failures) + (0.50 if soft_banned_active else 0.0)
health_score = clamp(raw_score - penalty, 0.0, 1.0)
Monitoring Health Score Drift in Production
- Inspect dynamic_health_score per upstream on GET /v1/router/pools to spot latency degradation early.
- Watch for upstreams dropping below 0.50—usually indicating active soft-bans or repeated consecutive failures.
- Verify alpha=0.25 responsiveness: 4 consecutive healthy calls lift a recovering upstream rapidly back toward prior weight.
- Use POST /v1/router/quote to preview how live health scores reorder your pool.
Frequently Asked Technical Questions
Why use alpha = 0.25 for EWMA updates?
An alpha of 0.25 reacts visibly within 2-4 requests to sudden outages or latency spikes while smoothing out single-packet network jitter.
Can a paid wholesale upstream with higher health score preempt a healthy $0 free upstream?
No, unless the caller explicitly specifies prefer or the free upstream is OPEN/quota-exhausted. Cost ascending is always the first sort tuple element.
How is health_score bounded?
It is strictly clamped to [0.0, 1.0] and rounded to 4 decimal places for deterministic tie-breaking.
Live Try-Now Console & Machine Discovery
Test failover routing, dry-run quotes, and circuit breaker metrics on the live gateway or connect via JSON-RPC 2.0 MCP.
Related FuelRouter Architecture Guides
- HTTP 429 Rate Limit & Retry-After Automatic Upstream Failover — HTTP 429 rate limit Retry-After automatic upstream failover
- Hard Budget Lock (max_cost_micros) Guardrails for AI Agents — max_cost_micros hard API budget lock for autonomous agents
- Detecting HTTP 200 Login Walls & Empty SPA Shells in Proxy Responses — detect HTTP 200 login wall and empty SPA shell responses