Skip to content

Support per-backendRef locality priority (multi-tier failover) via HTTPRouteFilter #10007

Closed

Description

@kkk777-7

Description:

Today the only way to influence Envoy's locality priority from Envoy Gateway's API is Backend.spec.fallback, which is a bool. It lands as ds.Priority = 1 during route translation and reaches Envoy as LocalityLbEndpoints.priority.

That gives us exactly two priority levels, and it is scoped to the Backend resource rather than to the backendRef that references it. Three things fall out of that:

  1. No multi-tier failover. There is no way to express primary -> secondary -> tertiary.
  2. No per-route priority. The same Backend cannot be primary for one route rule and a fallback for another. This is a natural shape for LLM/provider routing (route model A to provider 1 with provider 2 as fallback, and model B the other way around), but it applies to any multi-region or multi-provider setup that reuses backends across routes.
  3. Priority failover cannot be combined with MergeBackends. Cluster deduplication is worth having — smaller xDS, less active health-check traffic — but priority failover only works while a rule's backends share a single cluster. EG gets this right for its own fallback, disqualifying such a rule from deduplication. A priority the translator cannot see gets no such protection: the rule's backends are deduplicated into separate weighted clusters, and the failover silently degrades into weight-based distribution.

Because of (2), downstream projects reach past the API. Envoy AI Gateway exposes AIGatewayRoute.spec.rules[].backendRefs[].priority and applies it from its extension server, after EG's translation has finished, by rewriting LocalityLbEndpoints.priority on the generated clusters in PostTranslateModify.

Describe the solution you'd like

Add a backendPriority filter to HTTPRouteFilter, referenced from HTTPBackendRef.filters via ExtensionRef. EG already supports backendRef-level extension filters, This is the only per-backendRef extension point Gateway API gives us, and it is the granularity the use case needs.

API

type HTTPRouteFilterSpec struct {
	// ... existing fields ...

	// BackendPriority sets the Envoy locality priority of the endpoints belonging to the
	// backendRef this filter is attached to, enabling priority-based failover between the
	// backendRefs of a single HTTPRouteRule.
	//
	// This filter is only valid when referenced from HTTPBackendRef.filters. Referencing it
	// from HTTPRouteRule.filters is rejected: a rule-level filter applies uniformly to every
	// backendRef of the rule, and a uniform priority carries no failover meaning.
	//
	// +optional
	BackendPriority *HTTPBackendPriorityFilter `json:"backendPriority,omitempty"`
}

// HTTPBackendPriorityFilter configures Envoy's priority-based locality failover for a single
// backendRef. Envoy sends traffic to the lowest priority value that has enough healthy
// endpoints, and only spills over to the next value as that health degrades.
//
// This overrides the priority derived from the referenced Backend's `fallback` field.
// For additional details, see
// https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/upstream/load_balancing/priority
type HTTPBackendPriorityFilter struct {
	// Value is the locality priority assigned to this backendRef's endpoints.
	// 0 is the highest priority.
	//
	// Within one HTTPRouteRule, the values used across backendRefs must start at 0 and be
	// contiguous. A rule that skips a value is rejected with a ResolvedRefs=False condition
	// on the route.
	//
	// +kubebuilder:validation:Minimum=0
	// +kubebuilder:validation:Maximum=127
	Value uint32 `json:"value"`
}

Usage

One HTTPRouteFilter per distinct priority value; it is reusable across backendRefs and routes.

apiVersion: gateway.envoyproxy.io/v1alpha1
kind: HTTPRouteFilter
metadata:
  name: priority-1
spec:
  backendPriority:
    value: 1
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: llm
spec:
  rules:
  - matches:
    - headers: [{name: x-model, value: gpt-4}]
    backendRefs:
    - name: primary-provider          # priority 0 (default, no filter)
      group: gateway.envoyproxy.io
      kind: Backend
    - name: secondary-provider
      group: gateway.envoyproxy.io
      kind: Backend
      filters:
      - type: ExtensionRef
        extensionRef:
          group: gateway.envoyproxy.io
          kind: HTTPRouteFilter
          name: priority-1

[optional Relevant Links:]

Activity

  1. self-assigned this
    on Sep 10, 2026
  2. zhaohuabing commented on Sep 11, 2026

    @zhaohuabing
    Member

    This seems reasonable to me. One thing worth calling out: because the priority lands on the backendRef rather than on the backend object, this also gives Service backendRefs priority failover, which Backend.spec.fallback can't reach today.

    cc @arkodg @guydc

  3. zhaohuabing commented on Sep 11, 2026

    @zhaohuabing
    Member

    One more thought: this needs an HTTPRouteFilter object per priority value, and the lookup is same-namespace, so it's per namespace rather than per cluster. That's a lot of ceremony for one integer.

    I don't see a lighter shape at backendRef granularity though — ExtensionRef has no inline params, so an object seems unavoidable. A BackendTrafficPolicy on the rule would cost no new objects since health checking or outlier detection has to be configured anyway, but that means that policy can only target routes, which doesn't feel right either. Is there an option here I'm missing?

  4. kkk777-7 commented on Sep 11, 2026

    @kkk777-7
    MemberAuthor

    this needs an HTTPRouteFilter object per priority value, and the lookup is same-namespace, so it's per namespace rather than per cluster. That's a lot of ceremony for one integer.

    I agree. I initially expected this to be a field in Gateway API side.
    I found some previous discussions on this, and it seems Arko had the same opinion, but upstream doesn't seem to be moving forward on this.
    Ref: #3055

    I considered several options, including using a policy, but for now I personally feel that putting it in ExtensionRef of backendRef is the most appropriate approach. That said, I can definitely see the point that BTP would ultimately be needed for health checking.

    Hi @arkodg , do you have some opinion on this?

  5. kkk777-7 commented on Sep 11, 2026

    @kkk777-7
    MemberAuthor
  6. arkodg commented on Sep 14, 2026

    @arkodg
    Contributor

    yeah fine with backendPriority: int (versus struct) in BackendRef Filter or another priority field in Backend

  7. added this to the v1.10.0-rc.1 Release milestone on Sep 14, 2026
  8. github-actions commented on Oct 14, 2026

    @github-actions
    Contributor

    This issue has been automatically marked as stale because it has not had activity in the last 30 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions