Design: internal AI platform

In one sentence

A thin paved road: one mandatory LLM gateway (virtual keys, quotas, fallbacks, cost tags), opt-in shared services (prompt registry, evals, vector store, guardrails) and templates that make the right way the easy way.

Analogy: A city's utilities: everyone must connect to the same power grid and meter, but each household picks its own appliances.

Every call crosses the gateway, the one mandatory hop; registry, vector store and evals are services teams opt into.

How it works

  • Scale: ~100 teams, ~50M calls/month (~100 QPS at peak) and ~$175k/month of spend to attribute.
  • The gateway is mandatory because it is the only source of keys; everything else must win on convenience.
  • Expose an OpenAI-compatible API with your own aliases, so you can swap the gateway without touching 100 teams.
  • The worst failure is platform-wide blast radius: run multi-region, and let quotas fail open if Redis dies.
  • Report cost per successful task, not per token, and track the share of AI traffic through the gateway.

Check yourself

Answer to mark it learned; your answers aren't scored.

Your internal LLM gateway keeps per-team token quotas in Redis. At peak, the Redis cluster goes down. Every AI feature in the company calls through this gateway. What should the gateway do?

Go deeper

Do this round in 45 minutes System design round
Full explanation

An internal AI platform is the shared layer that lets many product teams ship LLM features without each one re-solving keys, providers, cost, safety and evaluation. Principle: mandatory at the choke point, opt-in everywhere else.

Requirements

  • Functional: ~100 teams call approved models through one API; version and roll out prompts; run evals in CI; get RAG storage and guardrails as services; see their own cost, latency and errors.
  • Non-functional: gateway overhead under 10 ms p99; 99.95% availability, higher than any single app because every AI feature depends on it; rules on which data class may reach which provider; every dollar attributable to a team and feature.
  • Questions I'd ask: Greenfield, or are 30 teams already calling providers with their own keys? Which data classes may go to which providers and regions? Central budget or chargeback? Can we mandate the gateway, or must we earn adoption? How many platform engineers do we have (that decides build vs buy)?
  • Highest-cost failure: platform-wide blast radius. The gateway goes down and takes every AI feature with it, or confidential data reaches an unapproved provider. The quiet failure is a platform nobody uses: teams route around it and you get neither control nor savings.

High-level design

Online path: app → thin SDK or template → LLM gateway, which authenticates the virtual key, checks policy (data class → allowed models) and quotas, runs input Guardrails: input, output, action, routes the alias with fallbacks to external providers or a self-hosted Self-hosted serving stack, and logs tokens, latency and cost with team tags.

Control plane: a model catalog (approved models, data terms, regions, prices), a team registry with budgets, a prompt registry (Prompts as code: versioning), an eval service wired into Evals in CI/CD & release gates, and a vector store as a service with per-team namespaces (Multi-tenant isolation in AI apps).

Offline path: traces → warehouse → per-team cost reports, budget alerts, LLM observability & tracing dashboards, and qualification of new models (security review plus the platform's eval suite) before they enter the catalog.

Golden paths: templates for RAG Q&A, extraction and a tool-using agent, pre-wired to all of the above, so a new team ships in days instead of weeks.

Code A team's manifest: declare intent, the platform enforces
yamlA team's manifest: declare intent, the platform enforces
# teams/payments-assistant.yaml: reviewed by PR, applied by the platform
team: payments-assistant
cost_center: CC-4471
oncall: payments-oncall
data_class: confidential          # policy maps this to allowed providers/regions
models:                           # aliases, never vendor ids: we swap the backing model
  - alias: chat-default           # fallback = same model on a second cloud
  - alias: chat-fast
  - alias: embed-default
quotas:
  tokens_per_min: 400000          # TPM and RPM: a 100k-token call is still 1 request
  requests_per_min: 600
budget:
  usd_per_month: 8000
  alert_at: 0.8                   # notify owners at 80%
  on_exceed: downgrade:chat-fast  # degrade, don't break production
guardrails: [pii-redact, injection-detect, output-moderation]
eval_gate:
  suite: payments-golden@v7       # pinned dataset version
  min_pass_rate: 0.92
retention:
  payload_days: 30                # full prompts; metadata kept 13 months
Real example

The payments assistant calls chat-default with a 2,100-token prompt. The SDK attaches the team's virtual key and a trace ID. The gateway authenticates (~1 ms), checks quota in Redis (310k of 400k TPM used, ~1 ms) and policy: confidential allows only zero-retention providers in the EU region. The PII guardrail masks an IBAN (~20 ms). The primary provider returns 429, so the router sends the call to the same model on a second cloud, adding ~300 ms. The response (350 output tokens) is logged with team, feature, model, latency and a cost of $0.012 at $3/M input and $15/M output. That afternoon, month-to-date spend crosses $6,400 of $8,000 and the 80% alert reaches the team, two weeks before a hard stop would.

Trade-offs +4 · −4

+ You gain

  • One control point: switching a model, rotating a key or adding a policy is config, not 100 migrations.
  • Spend becomes attributable per team and feature, which makes budgets and ROI conversations possible.
  • Shared evals, guardrails and templates raise the floor: a new team inherits tracing, PII masking and a CI gate on day one.
  • Pooled volume buys better provider pricing and reserved capacity.

− You pay

  • The gateway is a platform-wide single point of failure and an extra hop; it needs higher availability than any app.
  • Slow model approvals push teams back to shadow IT with personal keys.
  • A common API lags new provider features (realtime audio, new tool types, batch), so it needs a passthrough.
  • A platform team is a fixed cost that only pays off once several teams ship AI.

Use it when

Once 5–10+ teams call LLMs in production, spend is material, or legal needs to know which data reaches which provider: central keys and logs then pay for themselves.

Avoid it when

With one or two AI teams: a shared gateway config and a cost dashboard are enough, and a full platform team would build for customers you don't have yet.

Numbers to know 5
  • Load: 100 teams, ~50M LLM calls/month ÷ 2.6M s ≈ 20 QPS average; at ~5× peak-to-average, plan for ~100 QPS plus long-lived streams.
  • Spend: 50M calls × (2k in + 300 out) = 100B input + 15B output tokens/month; at an assumed $1/M in and $5/M out ≈ $100k + $75k = $175k/month.
  • Logs: 50M calls × ~10 KB (prompt, response, metadata) ≈ 500 GB/month; keep full payloads ~30 days and metadata 13 months.
  • Latency: auth + quota + routing under 10 ms p99; guardrail classifiers cost ~20–100 ms, so run low-risk input checks in parallel with the LLM call and cancel on a hit.
  • Routing math: moving 70% of traffic to a model 10× cheaper leaves 0.3 + 0.07 = 37% of spend, a ~63% cut, if evals show quality holds.
Common pitfalls 4
  • Building a heavy framework instead of a thin API: teams route around it. Keep the contract OpenAI-compatible and everything past the gateway opt-in.
  • Model approval taking a quarter: teams switch to personal keys. Set a ~2-week SLA with a standard review.
  • Logging full prompts with PII forever: the observability store becomes the biggest privacy liability. Mask PII and tier retention.
  • Falling back across model families without evals: prompts tuned for one model silently break on another. Fall back to the same model on another cloud first.
Interview questions 3

Answer out loud first, then reveal.

What do you centralize, and what do you leave to product teams?Show answer

I centralize what has platform-wide blast radius or economies of scale: provider contracts and keys, the policy on which data reaches which model, logging and retention, cost attribution, baseline guardrails and provider-outage response. Teams keep product judgment: prompts, model choice within the catalog, retrieval design, eval criteria, UX and the ship decision. The gateway is mandatory because it's the only way to get keys; everything else has to win on convenience. If teams avoid a shared service, I treat that as product feedback, not a compliance problem.

Would you build or buy the gateway?Show answer

Adopt, then wrap. Gateways are commoditizing fast (LiteLLM, Portkey, Kong AI Gateway, Agent Router, cloud offerings), and tracking every provider's new API each month is a treadmill a small platform team can't win. I build the organization-specific parts: SSO and cost-center integration, the data policy, the catalog workflow and the templates. The real one-way door is the client contract, so I expose an OpenAI-compatible API on our own domain with our own aliases like chat-default. That lets me swap the gateway underneath without a migration across 100 teams.

A major provider has a two-hour outage. What happens on your platform?Show answer

The circuit breaker trips on the error-rate spike and the router moves traffic to the same model on a second cloud, for example from the Anthropic API to Bedrock: same weights, so prompts keep working. Only aliases whose owners pre-approved it and passed evals fall back to a different model family. Teams without a fallback get fast 503s and a status page, not hung requests. Afterwards I review which teams lacked a fallback and whether reserved capacity on the secondary was sized for the failover load, since everyone else fails over at the same time.

Deep dive 5

Build vs buy, per layer

Buy or adopt where the market moves faster than you: the gateway (LiteLLM, Portkey, Kong AI Gateway, Agent Router (formerly Envoy AI Gateway), or your cloud's Bedrock, Vertex AI or Azure layer), vector storage (managed pgvector, OpenSearch or a vector database), tracing (Langfuse, Arize Phoenix, Datadog) and guardrail models (Llama Guard, Presidio for PII). Build where your organization's policy lives: SSO and cost-center integration, the data-class policy, the catalog approval workflow and the templates. Keeping up with new provider APIs every month is a treadmill a 10-person team loses. The one-way door is the client contract, not the vendor: expose an OpenAI-compatible API on your own domain with your own aliases (chat-default), so you can replace the gateway underneath without touching 100 teams. Wrap open source; don't fork it. See Build vs buy (and AI vendor selection) and API vs self-hosting.

Governance: central vs team-owned

Centralize what has platform-wide blast radius or economies of scale: provider contracts and keys, the data-class → model policy, logging and retention, cost attribution, baseline guardrails and incident response to provider outages. Teams own product judgment: prompts, model choice within the catalog, retrieval design, eval criteria and datasets, UX and the decision to ship. The gateway is mandatory because it is the only source of keys; everything else must win on convenience. New models enter the catalog after security and legal review (data terms, regions) plus the platform eval suite, with a ~2-week SLA, or teams go back to personal keys. Review by risk tier, not per prompt: internal tools self-certify, customer-facing features need a checklist and evals, regulated uses get human review (EU AI Act, NIST AI RMF & ISO/IEC 42001).

Cost attribution and budgets

Every request carries team, project and feature through its virtual key and a metadata header. The gateway prices it from the catalog (input, output and cached tokens at their own rates) and streams the row to the warehouse. Budgets have a soft limit (alert at 80%) and a hard action the team chooses: block, or downgrade to a cheaper alias. Shared costs such as self-hosted GPUs or the vector store are split by usage share (tokens served, GB stored). Start with showback and move to chargeback once teams trust the numbers, usually after a quarter or two. Report cost per successful task, not per token: a cheap model that fails half the time is expensive. The biggest levers are usually Model routing & cascades and Prompt caching; see AI cost governance (FinOps for AI) and Token economics & cost estimation.

Reliability of the platform itself

The gateway is a single point of failure for every AI feature, so it must be stateless, multi-AZ and multi-region, autoscaled on open connections because streams are long-lived. Quotas live in Redis and fail open if Redis is down: a brief overspend beats an outage. Config is pushed and cached locally; logging is async and buffered, never on the request path. Fallback order: the same model on another cloud first (the Anthropic API to Bedrock or Vertex AI, OpenAI to Azure OpenAI), because prompts are tuned per model; a different model family only for aliases whose owners ran evals on it. Circuit breakers per provider and region; guardrail services fail open or closed by risk tier. SLOs: overhead under 10 ms p99 excluding guardrails, 99.95% availability (SLIs, SLOs & error budgets, Retries, backoff & circuit breakers, Rate limiting).

Adoption and golden paths

A platform is a product, so measure it like one: share of AI traffic through the gateway (~100%, enforced by key control), lead time from idea to first production call (days, not weeks), teams on templates, and a quarterly satisfaction survey. Golden paths are templates for RAG Q&A, extraction and a tool-using agent, each pre-wired to the gateway, tracing, guardrails and an eval gate in CI. Embed platform engineers with the first 3–5 launch teams to harden the templates against real use. Keep the SDK thin: an internal framework teams must learn becomes the thing they route around. A vector store as a service means per-team namespaces with Metadata filters & permission-aware retrieval, not one shared index. Deprecate models with a migration window and an eval report, never by surprise (LLMOps vs MLOps).