AI State of the Art
MLOps/LLMOps/25 min
Section 202

Gateways and Load Balancing: One Place Everything Passes Through

Listen as a podcast →

The problem: several providers, as many interfaces

In production you rarely use one model. A capable model for requests needing reasoning, another for long documents, a self-hosted open model for simple volume. Every provider has its own application programming interface (API), its own request and response formats, its own rate limits and its own price list (see product and API comparison).

The consequence in code is mechanical: a per-provider branch everywhere a model is called, separate adapters, and a change to propagate everywhere on every interface revision. Adding a provider becomes a project.

A gateway solves this by sitting in between: it stands between applications and providers, exposes one interface, and translates behind the scenes.

The real argument is not translation, it is the choke point

Interface unification is what gets advertised, but it is not what matters most. What matters is that all traffic now passes through one place. That single point is the only one where an organisation-wide policy can actually be enforced: caching, rate limits, spend caps, automatic fallback, exhaustive logging, bans on sending certain data to certain providers.

Without a gateway, each of those rules has to be reimplemented in every application, and one application forgetting it is enough for the rule to stop being a rule.

What a gateway does

Translate

One call function, one message format, whatever the destination. Changing model becomes changing a string.

from litellm import completion

# The same call, whatever provider sits behind
response = completion(
    model="mistral-large",  # or any other model identifier
    messages=[{"role": "user", "content": "Explain transformers to me"}],
    temperature=0.7
)

The format used as common denominator is almost always OpenAI's, not because it is better but because it arrived first and everyone aligned on it. A de facto standard, not a specification.

Flow diagram. On the left, two senders, Client application and Backend workload, send their requests into a yellow note reading Common request slash response format. Those requests arrive in the centre at a LiteLLM box. A PostgreSQL database is linked by dotted line above LiteLLM, with a yellow note saying it stores configuration (users, keys, teams), usage and cost metrics via Prometheus in enterprise, and optionally prompts and responses. To the right of LiteLLM, a yellow note Model-specific request format leads to three destinations: OpenAI Model, Bedrock-hosted model and Self-hosted model on KServe. A second yellow note below LiteLLM lists its functions: OSS SDK and proxy, Easily swap out models, Model multi-tenancy, Request prioritisation, Budget limits, Token and request limits, Cost and usage tracking, Request auditing, Load balancing.
The translator role, and what it enables along the way. On the left, applications emit one format; on the right, the gateway converts it to each destination's native format. The lower note lists what the single choke point makes possible: budget caps, token limits, cost tracking, auditing, load balancing. Note the database attached at the top: it can store prompts and responses, which makes it a data file to be treated as one.Source : LiteLLM Operator documentation (BBD Software), Architecture

Route

When several destinations can serve the same request (several deployments of one model, or several models deemed equivalent) something must choose. Four rules cover almost every case:

RuleHow it choosesWhen it fits
Round robinEach in turn, statelessIdentical, interchangeable destinations
Least busyTo whichever has fewest requests in flightUneven load across destinations
By latencyTo the fastest recently observedResponse time is the priority
By costTo the cheapest that can serveBudget is the priority

The last two assume the gateway measures continuously what it routes. A latency rule without fresh measurement is yesterday's latency rule.

Fall back

This is the function that most often justifies installing one. If a provider returns a rate-limit or server error, the request is automatically re-sent to another, with the application none the wiser.

The typical chain: first provider, error; second provider, success; if all fail, an error returned to the application with the details of each attempt.

Fallback changes the model, and nobody notices

This is the consequence no brochure mentions, and it is serious. Falling back to another provider changes which model answers. Four effects to anticipate:

  • Behaviour changes. Tone and length differ, and an instruction tuned for one model is no longer tuned for the other.
  • Format may change. A service expecting schema-conformant JSON may get something else from the backup model, if that model handles constrained output differently (see structured output).
  • Measurements become unreadable. An unexplained quality regression is often explained by a silent fallback the day before. The trace must therefore record which model actually answered, not just which was requested (see observability).
  • Compliance can break. If the backup provider sits outside the permitted region, an automatic fallback moves data out with no human having decided anything. A fallback rule must be checked against the data residency policy, not only against availability.

Govern

This is what interests an organisation most, and developers least.

The gateway holds the providers' real keys; applications hold only an internal key. You can then revoke a team's access without touching any contract, cap a spend, refuse certain destinations for certain data categories, and hold an exhaustive log, the only place where "exhaustive" is a defensible word, since nothing passes anywhere else.

Numbered AWS architecture diagram. On the left, three clients Tenant 1, Tenant N and Tenant N enter the AWS cloud. Step 1: AWS WAF, preceded by distribution options Amazon CloudFront or AWS Route 53. Step 2: an ALB. Step 3: Amazon ECR supplies the cluster images. In the centre, a Cluster VPC contains an Amazon ECS or Amazon EKS cluster, with ECS tasks and EKS pods running an API slash middleware block connected to a LiteLLM block. Step 4: LiteLLM calls the AWS Model Providers, Amazon Bedrock and Amazon Nova. Step 5: LiteLLM also calls External Model Providers, OpenAI, Anthropic, Vertex AI and Cohere. Step 6: AWS Secrets Manager holds the secrets, and Amazon RDS plus Amazon ElastiCache (Redis OSS) store data and cache respectively. Step 7: Amazon S3. An ACM certificate is attached to the ALB.
The same principle deployed for real, in an AWS reference architecture. Several teams (the tenants on the left) all pass through a single gateway block. Secrets live in a dedicated vault rather than in application code; a relational database carries budgets and logs, a cache carries reused responses. What to read in this diagram is not the service list but the shape: all traffic converges on one choke point, with the benefits and the risk that implies.Source : AWS, Guidance for Multi-Provider Generative AI Gateway on AWS

What the choke point costs

No serious page on gateways can skip this section.

The gateway is a single point of failure. If it goes down, every application goes down, including those whose provider is working perfectly. You have concentrated risk instead of spreading it, which is the opposite of the stated goal. The architectural consequence: a production gateway runs in several instances, and you verify that losing one is not enough to stop the service.

It adds a network hop. The added time is one extra round trip: a few milliseconds if the gateway sits in the same data centre as the application, several tens if it does not. Against model generation time, which runs from hundreds of milliseconds to several seconds, this is usually negligible, but geographic distance decides it, not the software, and it is measured rather than assumed.

It sees everything. Prompts and responses pass through it and, depending on configuration, are stored there. It therefore carries the same obligations as observability traces: lawful basis, retention period, location. See data governance.

It delays. A new model released by a provider is unusable until the gateway supports it. The decoupling you gain on the application side is paid for with one more intermediary in the adoption chain.

The tools, in verifiable characteristics

The market moves fast and comparison tables rated "basic" or "advanced" cannot be checked. Here are structural facts only, to be rechecked before any decision:

LiteLLMPortkeyHelicone
Open sourceYesYes, the gateway, MIT licenceYes, Apache 2.0 licence
Self-hostableYesYesYes
Managed offeringYesYesYes
Stated focusLibrary and proxy unifying a very large model catalogueConfigurable routing and fallback, built-in guardrail catalogueGateway paired with an observability platform

One useful correction, because the mistake is widespread: all three are self-hostable. The idea that a "premium" gateway must necessarily be a managed service is false, and it leads teams to rule out options on a criterion that does not exist.

Two other names circulate. OpenRouter aggregates many providers behind a single key, which is convenient for comparison and prototyping but adds a commercial intermediary between you and the provider. Routers marketed as "intelligent", claiming to pick the best quality-per-dollar model per request on their own, appear and vanish regularly: the promise requires predicting an answer's quality before obtaining it, which is precisely the hard problem described in cutting the bill.

What belongs in the gateway, and what does not

A single choke point attracts everything, and that is a trap. Some markers:

Belongs whatever must hold for every application: keys, budgets, rate limits, fallback, logging, destination restrictions.

Does not belong whatever depends on the business: application logic, prompt construction, response interpretation. A gateway that rewrites prompts becomes a dependency nobody understands, and the smallest change hits every service at once.

Borderline: caching and guardrails. Both are legitimate at the gateway, and both are dangerous there, because the correct threshold differs by service. A semantic cache shared across all uses will apply to a regulatory-advice service the threshold tuned for a frequently-asked-questions service, with the consequences described in cutting the bill. Those settings must remain configurable per service, even if they execute in one place.

The architecture, and the practices

The usual stack:

  1. The applications, services, agents, interfaces.
  2. The gateway, in several instances.
  3. The providers, remote interfaces and self-hosted models (see model serving).
  4. Observability, fed by the gateway.
  5. Alerts on cost, latency and error rate.

Six practices, three of which are rarely applied:

  • Configure fallbacks, checking that the backup destination is permitted by the data policy.
  • Centralise keys, so revocation is a gesture rather than a project.
  • Version the configuration. Routes, fallbacks and budgets are code: they live in a repository and go through review. A spend cap changed in a web interface with no record is an incident in preparation.
  • Exercise the fallback. A fallback that never fires is a fallback never tested. Deliberately cut a provider, outside peak hours, and check that the switch happens, and that the resulting answer is still acceptable.
  • Record the model that answered, not just the one requested.
  • Watch the fallback rate. It rises quietly, and it is the first sign that a provider is degrading or a quota is set too tight.

Why it matters

The module's anchor applies here too, and particularly sharply. A proxy that unifies interfaces, spreads load and switches to a backup on failure is a classical distributed-systems component, predating language models by decades. Describing it applied to model calls is not in itself a contribution.

What can rise above lies in what the gateway decides, and on what data: the mechanism that picks a destination from an estimate of the request's difficulty rather than a written rule; the one that learns from past fallbacks when to switch before the error rather than after; the one that arbitrates between competing requests under a shared budget constraint; the one that enforces a data-residency constraint from the request's content rather than from the caller's identity alone. The question to ask of such a description is always the same: is the routing rule written by a human, or computed by the system?

Check your understanding0 / 5

1. What does a gateway really buy you, beyond unifying interfaces?

2. A team switches on automatic fallback to a second provider. Which consequence is most easily overlooked?

3. What risk does a gateway introduce by its very nature?

4. Should a semantic cache shared by all services sit at the gateway?

5. A provider starts degrading slowly. Which indicator reveals it earliest?