[Discussion] Model Failover Policy #3470
Thenujan-Nagaratnam
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
TL;DR
We need model failover to support three cases: changing only the model, changing the backend or region, and changing to a different provider. When a fallback uses another provider, the gateway must transform the original request again and apply the fallback provider's authentication before sending it.
I have come up with the following feasible approaches:
Approach 2 is the strongest option because Envoy continues to handle retries, timeouts, connections, and health while the upstream processor handles provider-specific transformation and authentication.
Approach 3 is the main alternative when reusing the existing policies is more important than keeping the request path simple.
Approach 4 is simpler, but it provides a weaker guarantee: the request that discovers the problem still fails. Only later requests use a fallback. (All other gateways support retrying in the same failing request)
Summary
The AI Gateway needs to retry a failed model invocation against the ordered fallback list configured for its primary target. A target is more than a model name: it identifies the provider, model, endpoint, credentials and request/response adapter required for one invocation.
The design must support all of these cases:
gpt-4.1asgpt-4.1-miniusing the same OpenAI endpoint and credentials.upstreamDefinition.Ordinary Envoy retries are sufficient only when every attempt sends effectively the same upstream request. They do not, by themselves, change a model in the body, translate the payload to another provider's schema, switch authentication, or normalize a different response format. The central design question is therefore:
Feasible architecture approaches
The following four approaches fit our gateway architecture. Approaches 1, 2, and 3 can transparently apply the three required failover forms to the active request. Approach 4 can route later requests across the same three target combinations after allowing the detecting request to fail. All four can reuse, extract, or invoke the existing provider transformation and upstream-authentication logic. Approaches that move responsibility to clients, rely on hedged duplicate calls, or depend on unreliable route-reselection tricks are intentionally excluded.
Approach 1: Policy engine calls each fallback provider
The policy engine receives the canonical request, performs each outbound provider call itself, transforms and authenticates each attempt, and returns the first accepted response to Envoy.
How it covers the requirements
Advantages
Disadvantages
Approach 2: Envoy retries while an upstream processor prepares each attempt
Compile every failover target into Envoy priority levels. Envoy's router owns the failover decision, retries, and advancement through priorities. A target-specific upstream HTTP filter or upstream
ext_procruns after backend selection, restores the canonical request, performs that backend's transformation, and injects its credentials.Failover is still native Envoy behavior. The policy engine does not maintain the retry loop or choose the next fallback. This separation is important: it keeps the failover state machine in Envoy while making provider transformation attempt-scoped.
For our gateway, two targets may resolve to the same physical address but carry different target identities and model adapters. This represents “same endpoint, different model” while allowing each attempt to rebuild the body correctly.
Advantages
Disadvantages and risks
Approach 3: Policy engine retries through the same Envoy route
The policy engine invokes the same Envoy route again after an eligible upstream failure. The request re-enters through a protected loopback listener or internal address with trusted attempt context indicating that the route should select the next fallback target. This lets the same route execute the provider-specific transformation, authentication, and upstream configuration required for that fallback.
Advantages
Disadvantages and risks
Approach 4: Fail the first request and temporarily skip that target
Allow the request that discovers a failure to fail normally. Record the selected target as suspended for a configured duration. While it is suspended, new requests that select the same primary target start from the first available entry in that target's
fallbackslist.Suspension applies to the resolved target identity, which includes provider, model, and
upstreamDefinition. The implementation may also maintain endpoint-level health so a transport outage can suspend every model target sharing an endpoint, while a model-specific error suspends only that model target.Advantages
POST, avoiding duplicate inference, duplicate billing, and request-body replay complexity.ext_procto run again within one request.Retry-Afteras the suspension duration for provider rate limiting.Disadvantages and risks
Comparison
Recommended direction
Two approaches deserve a focused prototype for transparent per-request failover:
Background material
Questions for the discussion
The decisions should be made in this order:
Should we retry within the same client request, or let that request fail?
If we retry within the same request, should Envoy or the policy engine control the fallback loop?
If the policy engine controls failover, should it call providers directly or invoke the same Envoy route again?
Are we prepared to run transformation and authentication in an upstream processor for every attempt?
Are we willing to depend on Envoy's alpha upstream HTTP filter capability?
All reactions