Skip to content

Proposal to add "Weighted Fallback" to Load-Balancing Strategys #530

Description

@weselben

Current Behavior

The Load-Balancing Strategy dropdown in the UI (Source → Targets configuration) currently offers only two options:

  1. Round-robin — rotates across all targets, honoring weights
  2. Lowest cost — picks the cheapest target per request

There is no option for a prioritized fallback strategy, where requests always go to the highest-priority (highest-weight) target, and only cascade to lower-priority targets when the primary is unavailable (e.g., circuit breaker open, rate-limited, or returning errors).

Image

Desired Behavior

Add a third option: Weighted Fallback — or alternatively a Fallback strategy toggle.

Behavior:

  • Targets are ordered by their assigned weight (highest first)
  • Every request always tries the highest-weighted target first
  • Only if that target fails or is in circuit breaker / unavailable state, the request falls back to the next target in priority order
  • Continues cascading down the list until a healthy target responds or all targets are exhausted

Use Case

In setups where:

  • One target is significantly more capable/reliable (e.g., kimicode/bge_m3_embed with weight 10)
  • A secondary target exists as a cheap backup (e.g., local ollama/qwen3-embedding:0.6b with weight 1)

…the user wants predictable prioritization — always use the best model unless it's down, rather than distributing traffic round-robin across tiers of very different quality.

Proposed UI Change

In the Load-Balancing Strategy dropdown, add:

Weighted fallback — tries highest-weight target first; falls back on circuit breaker

Optional Enhancement

Consider clarifying the weight semantics per strategy in the UI:

  • Round-robin: weight = traffic distribution ratio
  • Weighted fallback: weight = priority order (highest = primary)

Technical Context & Impacted Areas

To introduce this strategy, the codebase needs to register the new identifier and adjust target routing:

  • Backend Strategy Registry & Validation:

    • internal/virtualmodels/types.go and internal/virtualmodels/validation.go define and validate acceptable load-balancing strategy values. A new strategy value (e.g., weighted_fallback or fallback) needs to be supported here.
  • Load-Balancing Logic:

    • internal/virtualmodels/balancer.go houses target selection (balancedResolution). While it already filters out saturated targets using targetsWithCapacity, the routing logic needs to support a mode that selects the highest-weighted target from the remaining active pool (rather than cycling round-robin or picking by token cost). It should also gracefully fallback if all targets are saturated.
  • Admin UI & Templates:

    • internal/admin/dashboard/templates/page-models.html manages the strategy dropdown.
    • internal/admin/dashboard/static/js/modules/virtual-models.js handles label formatting and form visibility (such as ensuring weight inputs are shown when the fallback strategy is selected).
  • Tests and Documentation:

    • internal/virtualmodels/balancer_test.go and docs/features/virtual-models.mdx will need updates to cover and document the priority fallback behavior.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions