Skip to content

Conversation

@dmontagu
Copy link
Contributor

Adds support for load balancing and fallback routing with priority and weight-based provider selection. This enables flexible traffic distribution across multiple providers and automatic fallback when providers fail.

New routingGroups Configuration

Introduces a new routingGroups configuration option that replaces the deprecated routes field. The new format supports two key parameters:

  • priority (optional): Higher priority providers are tried first. If not specified, defaults to the negative index position (0, -1, -2, etc.)
  • weight (optional): Controls traffic distribution among providers with the same priority. If not specified, defaults to 1. Negative weights are normalized to 0.

Features

  1. Priority-based Fallback: Providers with higher priority are attempted first. If they fail, the gateway falls back to lower priority providers.

  2. Weighted Load Balancing: Within the same priority level, traffic is distributed probabilistically based on weights using a weighted random sampling algorithm.

  3. Backward Compatibility: The old routes configuration format is still supported and will continue to work without modification.

Pydantic AI Gateway Console

We'll update the console to support specifying both a weight and priority for routing group members; the logic from this PR will be used to affect runtime behavior.

Copy link
Member

@samuelcolvin samuelcolvin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

deploy/src/db.ts Outdated
}
}

// Then, fall back to the old routes format (backward compatibility)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure we really need this, no one is using the old format AFAIK.

export interface Config<ProviderKey extends string = string> {
/** @param project: record keys are the project ids */
projects: Record<number, Project>
/** @deprecated Use routingGroups instead */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, not sure we need deprecation warnings

@dmontagu dmontagu enabled auto-merge (squash) November 17, 2025 16:08
@dmontagu dmontagu merged commit db0239e into main Nov 17, 2025
3 checks passed
@dmontagu dmontagu deleted the dmontagu/load-balancing branch November 17, 2025 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants