EWMA alpha=0.25 · 4 Weighted Factors · Penalty Decay

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

ComponentWeight / CoefficientCold-Start DefaultPurpose
base_health_weight+0.25 prior weight0.87 - 0.96 per upstreamAnchors historical reliability across cold starts
ewma_success_rate+0.50 weight (alpha=0.25)base_health_weightDominant signal favoring verified HTTP 2xx outcomes
latency_score+0.15 weight (clamped 0.1-1.0)1.0 at expected_p95_msDemotes sluggish upstreams exceeding expected p95 latency
cleanliness (1 - fake_200_rate)+0.10 weight1.0 (0% fake-200)Penalizes silent HTML/CAPTCHA/error-JSON emitters
consecutive_failures-0.12 per consecutive step0 failuresImmediate score drop after 1st or 2nd failure before OPEN trip
soft_banned_active-0.50 flat penaltyfalse (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

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