# Productionizing LLM Gateways: Architecture, Tradeoffs and Hard Lessons — Kanish Manuja, Twilio <!-- ref: @content/youtube/aie/2026-08-28-productionizing-llm-gateways-architecture-tradeoffs-and-hard version: 3 updated_at: 2026-10-31T18:24:16.689Z --> Kanish Manuja (AI Engineer, 2026-08-28): An LLM gateway — the middleware handling routing, auth, fallback, rate limits and governance between apps and model providers — is built around a permanent four-way fight between availability, latency, guardrails and cost. *Synthesized from Kanish Manuja on AI Engineer, 2026-08-28.* Kanish Manuja is a principal engineer at Twilio who works on the middleware layer sitting between applications and model providers. ## Core Thesis An LLM gateway — the middleware handling routing, auth, fallback, rate limits and governance between apps and model providers — is built around a permanent four-way fight between availability, latency, guardrails and cost. Manuja's argument is that during a degradation you cannot maximize all four, so the job of a gateway operator is to consciously pick which one to sacrifice, and the job of a gateway *designer* is to expose those levers to callers rather than deciding for them. Classic distributed-systems reflexes like retry-with-backoff and circuit breaking don't transfer cleanly, because LLM calls are slow and expensive enough that a blind retry multiplies both cost and tail latency. ## Key Insights - With a single model provider, their ceiling is your ceiling and their outage is your outage — the standard retry/exponential-backoff/jitter/circuit-breaker stack is insufficient because retries eat the latency budget fast. - The better primitive is per-request fallback: try provider A, then provider B in sequence on failure. Firing both in parallel is an option only for teams obsessed with latency, since it doubles cost outright. - Circuit breaking still applies, but as a cooldown: pull a persistently failing primary out of the request path for a few minutes, then reintroduce it — rather than tripping open when a healthy second provider exists. - Where failure counts live is a real architectural choice. Fleet-wide shared state gives faster failovers; per-instance in-memory counters break their own assumptions every time you change deployment size or configuration. - Fallbacks are not transparent. Even with the industry converging on OpenAI-compatible APIs, tool-calling schemas, token limits and stop reasons still differ — so a gateway needs a normalization layer, and the fallback path needs real testing. - Streaming trades away your levers: once you've committed to provider A mid-stream you cannot switch, and whatever reached the client is final. The "something went wrong, please try again" message is a design consequence of that, not laziness. - Teams repeatedly over-provision the primary and under-love the fallback. Manuja argues the secondary should carry *more* headroom and throughput than the primary, because it's the last line of defense. - Availability failures page you; latency failures are quiet. Aggregate gateway-wide latency is meaningless on mixed workloads — embeddings and classification under a second, chat around 3 seconds, reasoning far longer. Track P99 per model per route. - Missing timeouts are the number-one root cause of silent outages: the gateway believes a request is being served while it isn't. Set timeouts per model class, per route. - Reasoning and router models are the worst offenders. Temperature often can't be pinned to zero, and the same prompt can range from 2 seconds to 60 seconds — Manuja has watched P99 jump to 60 seconds in production for no visible reason. His framing: a reasoning model's normal is a chat model's outage. - Guardrails are just another dependency that can go down, forcing an explicit fail-open (serve anyway) vs. fail-closed (block) decision — availability against security. A toxicity filter being down may be survivable; the default should be the worst case you can live with. - Guardrail placement has three shapes with distinct costs: pre-hook on input (safest, adds serial latency), parallel (his favorite, but incompatible with streaming), post-hook (best for output monitoring and audit). - A single central company-wide gateway is a single point of failure. What organizations usually actually want is centralized *governance* — cost tracking, rate-limit management — which can be delivered via plugins and custom code over decentralized deployments. One team owning it is fine; one deployment serving the whole company is not. ## Actionable Takeaways 1. Replace blind retries with per-request sequential fallback across providers (A, then B). Reserve parallel dual-firing for cases where latency matters more than a 2× cost increase. 2. Use circuit breakers as cooldowns, not kill switches: eject a failing primary from the load balancer, wait a few minutes, then reintroduce it. Decide deliberately whether failure counts are fleet-wide (faster failover) or instance-local (breaks when deployment size changes). 3. Build a normalization layer in the gateway to absorb cross-provider differences in tool-calling schemas, token limits and stop reasons — and actually test the fallback path, not just the primary. 4. Provision the fallback provider with equal or greater headroom and throughput than the primary. 5. Stop reporting aggregate gateway latency. Instrument P99 per model per route, since mixed workloads span sub-second embeddings to minute-long reasoning calls. 6. Set explicit timeouts per model class per route — this is the single highest-value fix against silent outages. 7. For reasoning and router models, pin the reasoning level per route to make an inherently nondeterministic system as deterministic as you can. 8. Hedge the tail: if the primary request has consumed roughly P90 of the latency budget, fire a second request to cut P99. 9. Give guardrails their own time budget and timeouts so the LLM — never the guardrail — is the rate-determining step. Give them fallbacks too: secondary providers, secondary checks, cached decisions. 10. Choose guardrail placement per use case: pre-hook for maximum safety, parallel for structured outputs (and don't stream those), post-hook for auditing and output monitoring. 11. Segregate API keys per route and per use case at the finest granularity possible so one noisy tenant can't consume shared limits. 12. Verify your gateway supports load shedding, and bound the web servers' internal queues — you cannot scale out of a retry storm. Add traffic prioritization so critical use cases survive under load. Exercise it in runbooks and game days. 13. Before building one central gateway for the whole company, separate the traffic question from the governance question: decentralize the deployment, centralize cost tracking and rate-limit management via plugins. ## Notable Quotes > "If you have a single model provider, their ceiling is your ceiling. Their outage is your outage." — Kanish Manuja > "A reasoning model's normal is actually a chat model's outage." — Kanish Manuja > "In most scenarios, it's not the central gateway that they want. They want centralized governance." — Kanish Manuja > "It's my son's birthday today and I'm here talking to strangers about circuit breaking." — Kanish Manuja --- *You're reading a protocol on [protocol.supply](https://protocol.supply) — hosted, searchable knowledge for AI agents. Think Agent Skills, as an API: bootstrap once (`curl -sL https://api.protocol.supply/bootstrap`), search (`/search?q=…`), fetch (`/@repo/slug`).* *Any skill can become a protocol, and any protocol installs as a local skill — tell your agent "install this as a skill" or see [`@protocol/protocol-to-skill`](https://api.protocol.supply/@protocol/protocol-to-skill).*