Skip to main content
HS
HiSETSuccess
LeetCode Prep

AI & FDE Interview Room

Role paths, mocks, cost studio, chapters, cases, and staff-level depth.

Case study · Architect · 30 min

Cost-Optimized LLM Inference Stack

Design a multi-model inference platform that routes traffic across sizes, batches requests, and hits cost and latency SLOs.

inferenceGPUrouting

Interview opener

Cut generation spend ~60% without tanking quality.

  1. 1.Which traffic should never touch the frontier model?
  2. 2.How do you detect silent quality regressions?
  3. 3.Cache key design under multi-tenant ACL?

Strong signals

Hit 0/3

Weak signals (avoid)

  • Only 'use cheaper model'
  • No regression detection

Requirements

  • Functional: OpenAI-compatible API; model routing; streaming; tenant quotas
  • Non-functional: chat p95 TTFT < 800ms; availability 99.9%; unit cost −40% YoY
  • Scale: 120 peak QPS; avg 1.5K in / 400 out tokens
  • Constraints: mix of hosted API + self-hosted 70B/8B GPUs

Back-of-envelope Estimation

MetricCalculationResult
Tokens/sec peak120 × (1500+400)~228K tok/s
If all 70Bneed ~40 H100s (rough)high $
Route 70% to 8Beffective GPU need ~0.4×~16 H100-eq
API fallback 10%12 QPS × 1.9K × 86400~2B tokens/day
API cost @ $3/1M2B × $3/1M~$6K/day worst
Target mix costself-host heavy~$1.2K/day

API Design

EndpointMethodDescription
POST /v1/chat/completionsPOSTCompatible schema; router picks model
GET /v1/modelsGETLists logical models (quality tiers)
POST /v1/admin/routingPOSTUpdate rules: intent → model

Data Model

EntityKey fieldsNotes
routing_rulesrule_id, match, model_id, weightVersioned config
usagetenant_id, model_id, tokens_in/out, tsBilling + quotas
quality_labelsrequest_id, scoreFrom eval/sample

High-level Design

Router + serving
Client → API GW → Router (complexity classifier)
                      ├─► cache hit? return
                      ├─► small model pool (8B, continuous batch)
                      ├─► large model pool (70B)
                      └─► hosted API fallback (circuit breaker)

Telemetry → cost dashboards + auto scale GPU replicas

Deep Dive: Routing Without Quality Loss

  • Train a tiny classifier on (prompt features → needed model tier) using eval labels
  • Cascade: try 8B; if confidence low or self-check fails, escalate to 70B
  • Speculative decoding: 8B drafts, 70B verifies for hard prompts
  • Quantization (AWQ/FP8) with eval gate before prod

Bottlenecks at Scale

  • KV-cache memory for long contexts — cap and summarize
  • Head-of-line blocking — separate latency classes / priority queues
  • GPU fragmentation — continuous batching (vLLM-style) essential

Failure Modes & Monitoring

SLOTargetAlert
TTFT p95< 800msPage if > 1.5s
$/1M tokensbudget bandWarn on +20%
Fallback rate< 15%Warn if > 25%
Quality vs golden≥ baseline−1ptBlock deploy

Attempt the case aloud first. Then unlock a staff model answer outline.