All insights

Inference economics

How Hysteresis Prevents an AI Router from Flapping Between Providers

Hysteresis reduces AI router flapping by using separate decision boundaries: switch away when latency exceeds an upper threshold, but switch back only after latency falls below a lower threshold. The gap creates a dead band where the router retains its current provider instead of reacting to every small latency change.

Hysteresis reduces AI router flapping by using separate decision boundaries: switch away when latency exceeds an upper threshold, but switch back only after latency falls below a lower threshold. The gap creates a dead band where the router retains its current provider instead of reacting to every small latency change.

The short answer: use separate thresholds for switching away and switching back

Router oscillation, also called provider flapping, is repeated switching caused by noisy or variable latency measurements near a decision boundary. If a router uses one threshold for both leaving and returning, each minor crossing can reverse the previous decision.

Hysteresis replaces that single boundary with two conditions:

  • Upper threshold: the condition for moving traffic away from the current provider.
  • Lower threshold: the condition for returning traffic to the preferred provider.
  • Dead band: the range between the two thresholds, where the router preserves its current state.

For example, a router might move from Provider A to Provider B only after A's measured latency exceeds an upper threshold. Once on B, it would not return merely because A drops just below that same boundary. It would wait until A's latency falls below a separate, lower threshold.

This pattern can reduce unnecessary switching, but it does not eliminate every source of oscillation. Provider failures, abrupt capacity changes, correlated measurement noise, policy updates, and competing routing signals can still change the selected destination.

Why a single latency threshold causes provider flapping

Consider a router with one latency threshold. Its observations might move from just below the boundary to just above it, then below it again. If every crossing triggers a decision, the route can alternate repeatedly even though the underlying performance difference is small.

A simplified sequence looks like this:

  1. Provider A is selected and its observed latency is below the threshold.
  2. The next observation moves slightly above the threshold, so the router selects Provider B.
  3. A later observation moves slightly below the same threshold, so the router returns to A.
  4. Continued variation repeats the cycle.

This is especially likely when the metric is based on individual requests, sparse traffic, or a short observation window. A temporary queue, network variation, cold execution path, or unusually long generation can move one observation across the boundary without indicating a durable provider-level change.

Flapping may also create operational churn. It can complicate attribution, distribute caches unevenly, interrupt batching opportunities, and make provider behavior harder to interpret. The actual effect depends on the serving architecture and workload, so switch frequency should be measured rather than assumed to be harmful in every case.

Workload context matters as well. Token Forge Cloud treats latency-sensitive chat, batch enrichment, and agentic workflows as different serving-policy problems. An interactive request path may value fast response to degradation, while a batch workflow may tolerate slower routing changes in exchange for greater stability.

How a stateful dead band stabilizes routing decisions

Hysteresis is stateful because a decision depends on both the latest measurement and the provider currently selected. The same observed latency can therefore produce different actions in different routing states.

Suppose the observed value lies between the lower and upper thresholds:

  • If Provider A is currently selected, the router remains on A.
  • If the router previously moved to Provider B, it remains on B.

That middle range is the dead band. It prevents marginal measurements from immediately reversing an earlier switch. Only a more decisive movement beyond the relevant boundary changes the state.

This is different from smoothing. A rolling average or percentile changes how latency is measured; hysteresis changes how a measurement is converted into a routing decision. The two techniques can be used together, but they solve different problems. Smoothing reduces sensitivity to short-term measurement noise, while hysteresis reduces decision reversals near a boundary.

A useful implementation also defines the scope of state. Depending on the system, state might be maintained per model, workload class, region, tenant, route, or provider pair. Very broad state can hide meaningful differences between workloads, while highly granular state may produce too little traffic for stable measurements.

Illustrative two-provider routing logic

The following pseudocode is a general design pattern, not a universal configuration or product-specific algorithm. It assumes Provider A is preferred when healthy and Provider B is an eligible fallback.

if current_provider == A:
    if measured_latency_A > upper_threshold
       and B is eligible under health, capacity, quality, cost, and policy rules:
        current_provider = B
    else:
        current_provider = A

else if current_provider == B:
    if measured_latency_A < lower_threshold
       and A is eligible under health, capacity, quality, and policy rules:
        current_provider = A
    else:
        current_provider = B

The lower threshold must be below the upper threshold for a dead band to exist. No fixed threshold values are appropriate for every deployment; they should reflect the workload's objectives and observed latency distribution.

This example also reveals an important recovery requirement: the router needs a way to evaluate Provider A while most production traffic is going to B. Depending on the architecture, that might involve controlled probes, a limited traffic share, or another representative observation source. Recovery should not be inferred from stale measurements.

Latency should not be the only eligibility test. A low-latency provider might still be unsuitable because of errors, insufficient capacity, model-quality requirements, cost constraints, data-handling policy, or fallback restrictions. Hysteresis governs when a latency-related state changes; it does not replace the rest of the routing policy.

Choose measurements and thresholds around workload SLOs

Before selecting thresholds, define what the router is measuring. One request is rarely representative of an entire provider. Possible observation methods include a rolling statistic, a windowed percentile, or a requirement for several consistent observations. The metric may also need to distinguish time to first token, end-to-end response time, queue delay, or another workload-relevant latency measure.

Threshold width creates a practical tradeoff:

  • A wider dead band generally favors stability because a larger recovery is required before switching back.
  • A narrower dead band generally favors responsiveness but may allow more reversals when measurements are noisy.

The appropriate balance depends on the workload SLO, latency distribution, traffic volume, cost of switching, and expected recovery behavior. Thresholds should also account for measurement uncertainty. A quiet route with few observations may require different treatment from a high-volume route with a stable rolling distribution.

Connect the policy to admission decisions as well. If no eligible provider can satisfy the relevant operating conditions, the router may need to queue, reject, degrade, or otherwise handle the request according to application policy. Hysteresis should not keep sending traffic to a provider that has become ineligible merely because latency remains inside the dead band.

Test the policy against recorded or simulated sequences that include gradual degradation, brief spikes, sustained failure, partial recovery, and alternating provider conditions. This makes the stability-versus-responsiveness tradeoff visible before it affects a production route.

Combine hysteresis with dwell times, health checks, and circuit breakers

Hysteresis is one routing control, not a substitute for every safeguard. Complementary mechanisms address different failure modes:

  • Rolling statistics or smoothing reduce the influence of isolated measurements.
  • Consecutive-sample requirements wait for repeated threshold crossings before acting.
  • Minimum dwell times keep a selected provider active for a minimum period before another ordinary switch is considered.
  • Cooldowns delay reevaluation after a routing event.
  • Health checks determine whether a provider is eligible to receive traffic.
  • Circuit breakers temporarily stop requests after sustained failures or another defined failure condition.

These controls need explicit precedence. A minimum dwell time, for example, should not necessarily block an urgent failover when a provider becomes unhealthy. Likewise, hysteresis should not override a policy restriction or make an ineligible fallback available.

Avoid layering controls without examining their combined effect. A wide dead band, long observation window, consecutive-sample rule, and cooldown can collectively make recovery too slow even if each setting appears reasonable in isolation. Evaluate the complete state machine, including exceptional paths and operator overrides.

Evaluate hysteresis in a multi-provider LLM inference control plane

With more than two providers, hysteresis becomes more than a pair of latency thresholds. A control plane may need to determine which providers are eligible, how candidates are scored, when state is retained, and what conditions permit recovery. General design options include provider-specific thresholds, relative scoring, preferred fallback sets, and policy constraints by model or workload.

Evaluation questions should include:

  • Is routing state maintained at a scope appropriate for each workload?
  • Can thresholds differ by provider, model, route, or workload class?
  • How are providers assessed when they are not receiving normal traffic?
  • Do errors and health status override latency hysteresis?
  • How do capacity, cost, model-quality requirements, and organizational policy affect eligibility?
  • What happens if the preferred provider recovers only partially?
  • Is routing state preserved consistently when control-plane components restart or scale?

Operational monitoring should cover switch frequency, time spent in the dead band, provider latency distributions, error rates, and recovery behavior. Teams should also inspect why each switch occurred and whether the selected fallback remained eligible. These signals help determine whether the dead band is too narrow, too wide, or interacting poorly with other controls.

Token Forge Cloud offers Private LLM Inference for enterprise AI workloads, with a focus on private LLM inference and serving-layer optimization. Our serving-layer focus includes routing alongside caching, batching, quantization, and GPU scheduling. Teams can consider hysteresis when defining model-routing policies within a private inference control plane; the appropriate design depends on workload behavior, SLOs, provider options, and governance needs.

For teams first validating model demand, Token Forge Cloud offers Managed Model APIs as an API-first path before private deployment becomes the preferred operating model.

Contact Token Forge Cloud to discuss API access, private deployment, and LLM inference cost control.

Contact us