Preparing your design workspace

Loading the problem and your latest saved attempt…

Design a Multi-Tenant AI Gateway

Design an isolated multi-provider HTTP gateway with safe fallback, quotas, complete request audit records and reconcilable usage metrics.

Problem statement

For this exercise, assume internal tenant services send text-generation requests through a gateway to configured model providers. Treat providers as ordinary HTTP request/response calls: streaming is outside the required baseline.

The gateway authenticates callers, applies a versioned routing policy, enforces quotas, chooses a compatible provider and returns a completed response or an explicit failure. Each tenant owns aliases, fallback rules and isolated credential references.

For this exercise, every gateway API request must have a stable identity and an auditable final outcome, including authentication/validation rejection, quota rejection, provider failure and success. Record bounded decision and attempt metadata, not raw prompts or secrets.

A retry keeps the gateway identity; a distinct provider attempt has its own identity. A late provider response must not overwrite a completed gateway outcome.

For this exercise, cost accuracy means reconcilable usage accounting: distinguish provider-reported usage, provisional estimates and unresolved timed-out attempts. Deduplicate redelivered usage events without erasing genuinely separate billable provider attempts. Do not assume that a failed or timed-out call was free.

Explain the request/data model, APIs, routing/fallback decisions, business logs and metrics used to adjust routing. Model training, client agent orchestration and streaming transport design are excluded.

What to build

  1. An internal tenant service submits a normal HTTP text-generation request and receives a completed result or explicit terminal failure with provider/model provenance.
  2. An authorized operator publishes and activates versioned aliases, routes, compatible fallbacks, credential references and retry budgets; an in-flight request retains its bound policy.
  3. Authenticate callers, isolate tenant/provider credentials and quotas, and use bounded admission so one tenant cannot exhaust shared request capacity.
  4. Every gateway request has a durable correlated outcome, including local rejection and provider failure. Record routing decisions, provider attempts and usage with idempotent delivery and explicit provisional/reconciled cost state.

At scale

  • For this exercise, assume 50,000 new HTTP requests per second globally, tenfold bursts and up to 200,000 in-flight provider requests.
  • For this exercise, target at most 50 milliseconds p95 healthy gateway overhead before provider time; reject overload within bounded queues and honor end-to-end deadlines.
  • For this exercise, support dozens of providers/model families with different HTTP limits, latency distributions and regional failure patterns.
  • For this exercise, request audit and usage records must survive a zone failure. Delivery can be at least once; timed-out usage can remain explicitly unresolved until provider reconciliation.