skip to content

How do you run a model gateway so that one bad release or one failed node cannot take every AI feature down at once?

level: seniorimportance: should knowfreq 34%

answer

  1. replicas protect nodes, not releases
  2. nothing important in replica memory
  3. concurrency = rate x duration
  4. canary on per-route provider 4xx
  5. config push is a release

basics

~10 s

Run the gateway as stateless replicas across zones, sized by open calls, and cap each release's reach: canary with automatic rollback on per-route errors, staged config pushes, drained shutdowns, and independent cells.

solid answer

~40 s

Replicas only protect against node failure; a bad release runs on all of them. So I would make each replica disposable: routes, aliases and key mappings come from versioned config with a last-known-good copy cached, spend counters live outside the replica, provider health is re-learned locally, and there are no sticky sessions. I would size the fleet by concurrent open calls across zones, because generations stay open for seconds. Then I would cap each release: a canary slice with automatic rollback on gateway-specific signals (per-route error rate including provider 4xx, translation failures, overhead p99), config pushes staged like code, replicas that drain in-flight generations before exiting, and independent cells so one bad release reaches only one group of features.

go deeper

for a junior

Recall that a shared gateway sits in front of every model call, so if it breaks, every AI feature breaks, and that more copies of it do not help if they all run the same bug.

for a middle

Explain what makes a replica stateless here: config with a last-known-good copy, counters outside the replica, local health, no sticky sessions, and why open calls drive sizing.

for a senior

Show the release discipline: canary signals that include provider 4xx, automatic rollback, config staged like code, drained shutdowns, and how you would replay a forty-minute outage against it.

for a principal

Weigh cells against one shared fleet: how many cells, cut by what, the cost of running them, and the provider-quota coupling they leave in place.

## Why one release reaches every feature A **model gateway** is shared by every application that calls a model, so its blast radius is the whole company's AI surface. Adding replicas protects against a failed node, but not against a bad release: every replica runs the same new code and the same new config. Staying up under both needs two things: **replicas that are disposable**, and **releases whose reach is capped**. ## Keep replicas stateless A replica should be killable at any moment with nothing lost except the calls it had open. That means no state that matters lives only in its memory: - **Routes, model aliases and key mappings** come from a versioned config source. Each replica caches the **last known good** copy, so an outage of the config source stops changes, not traffic. - **Spend counters** live in a shared store or are approximated per replica and reconciled. How that store behaves when unreachable is covered with distributed rate limiting; here the point is only that the replica does not own it. - **Provider health** (which upstream is failing) can be local to each replica and re-learned after a restart; replicas briefly disagreeing is acceptable. - **No sticky sessions.** With the usual chat-message request shape each call carries its whole conversation, and where a provider keeps conversation state it keeps it on its side, so any replica can serve any call. ## Size for open calls, not request rate Model calls stay open for seconds, so capacity is about **concurrent open calls**, not requests per second. By Little's law, concurrency = arrival rate x average duration. In an illustrative scenario of 200 calls per second averaging 8 s each, about 200 x 8 = 1,600 calls are open at any moment. Spread across zones with enough headroom that losing one zone's replicas, or draining a batch during a deploy, does not overload the rest. With three zones sharing those 1,600 calls, each carries about 533; if one zone is lost, the other two carry 800 each, so each zone must be sized for about 800 open calls, roughly 50% headroom over its normal share. Memory per open call (buffers for the request and the streamed response) and file descriptors usually run out before CPU, so measure them per replica rather than assuming a web-API profile. ## Release safety 1. **Canary first.** Send a small slice of traffic, ideally from low-risk routes, to the new version. 2. **Watch gateway-specific signals.** Error rate per route *including provider 4xx* (a translation bug makes providers reject requests with 400, which a canary watching only gateway 5xx misses), translation failures, and overhead p99. 3. **Roll back automatically** when a signal breaches, without waiting for a human. 4. **Treat config pushes as releases.** Repointing a model alias or changing a route reaches every replica within seconds; validate it against a schema and a dry run of recent requests, then roll it out the same staged way. 5. **Drain before exit.** On shutdown a replica stops accepting new calls, reports not ready, and lets in-flight generations finish within a drain window longer than the long tail of call duration; only then does it force-close. ## Cells A **cell** is an independent copy of the gateway with its own replicas and its own release schedule: | design | what one bad release hits | cost | |---|---|---| | one shared fleet | every AI feature | simplest to run | | cells by criticality | one cell's features | more fleets, routing clients to cells | | per-team cells | one team | many fleets, drift between them | Release to the least critical cell first. Cells still share provider accounts, and often the store holding team spend counters, so provider-side quota and that store are couplings they do not remove. ## The forty-minute outage, replayed In this leaf's scenario, one gateway release broke every AI feature for forty minutes. Run through the list above and the failure usually has two causes: - the release reached every replica at once, with no canary or with a canary watching the wrong signal; - rollback was manual, so the forty minutes were mostly time to notice and decide. Neither is fixed by more replicas. A canary watching per-route provider 4xx with automatic rollback limits the same bug to minutes on a small slice; cells limit it further to one group of features. Generic load balancer and API-gateway high availability apply too, but they are a separate subject from these model-gateway specifics.

  • Why can a config push be riskier than a code release on a model gateway?
    Repointing a model alias or editing a route reaches every replica within seconds and often skips the canary that code goes through, so one typo can misroute every caller at once. Validate config against a schema and a dry run of recent requests, roll it out per cell, and keep the previous version one step away.
  • How long should a gateway replica's drain window be?
    Longer than the long tail of call duration on the routes it serves, measured rather than guessed; a long generation or an agent step can run for minutes. The replica stops taking new calls and reports not ready immediately, waits out the window, and only then force-closes what is left.
  • Where would you draw cell boundaries for a model gateway?
    By criticality first: revenue-bearing and customer-facing features in one cell, internal tools and experiments in another, so releases land on the least critical cell first. Cells should share as little as possible at runtime, but provider accounts, and often the spend-counter store, still couple them.

  • Adding more replicas protects the gateway against a bad release.
  • Gateway replicas need sticky sessions so a conversation stays on one replica.
  • A canary watching only gateway 5xx errors will catch request translation bugs.
  • Config changes are safe to push everywhere because no code changed.
  • Size gateway replicas by requests per second, the same as a short web API.