System Design Arena
System Design: OpenAI/Gemini Platform
Expose large language models through APIs, manage training, safety, billing, and observability.
Case Study
LLM Serving (OpenAI/Gemini)
Same conversation, diagrams, and wrap-up you expectβnow framed with clearer scaffolding and iconography.
Prompt
You run an LLM platform like OpenAI/Gemini. Provide API for completions/chat, fine-tuning, moderation, usage tracking, billing, and safety with global latency under 300 ms.
Interview snapshot
- β’ Topic: LLM Serving (OpenAI/Gemini)
- β’ Expected depth: 45 - 60 minutes
- β’ Focus areas: APIs, scale estimation, resilient architecture
- β’ Wrap-up: risk, monitoring, disaster recovery
Key takeaways
- β’ REST/WS APIs for text/chat completions, embeddings, moderation, fine-tuning jobs.
- β’ Latency: < 300 ms for small models, < 1s for large context responses.
- β’ POST /v1/chat/completions - main chat API.
ποΈ Interview mode
Practice this like a real interview
Don't read the answer first. Work the framework against the bare prompt, then compare against what the interviewer expected at each step.
Scorecard
What the interviewer is evaluating
Staff-level signal
Does the candidate treat GPU hours as the scarce resource and design everything β queueing, checkpointing, data pipelines β around not wasting them?
π§ Staff engineer judgment
The GPUs must never wait. Any component that can stall the data feed β storage, network, preprocessing β deserves more design attention than the trainer itself.
Calibration
The common (bad) answer
Data β Training job on GPU cluster β Model β Deploy
β Why this scores poorly: A month-long job across thousands of GPUs is not "a job" β it is an exercise in surviving hardware failure, data pipeline stalls, and loss spikes without losing weeks of compute.
β What a strong answer adds
- Checkpointing cadence derived from MTBF math: at 10K GPUs, failures are hourly events.
- Data pipeline as its own system: dedupe, filtering, tokenization, streaming shards that never starve GPUs.
- Topology-aware placement β interconnect locality decides throughput.
- Experiment tracking and eval harness as first-class citizens, not afterthoughts.
- Separate research clusters (fast iteration) from flagship runs (stability ΓΌber alles).
Build it up
Step-by-Step Walkthrough
An OpenAI/Gemini-style platform is really two systems wearing one API: a serving plane that must answer in milliseconds, and a training plane that runs for weeks on thousands of GPUs. The interview is won by separating them cleanly and connecting them through a model registry.
Naive serving: an API in front of a GPU box
Version one: a web server receives POST /v1/chat/completions, loads the model onto a GPU, runs generation, returns the text. It demos beautifully and fails immediately: loading tens of gigabytes of weights per request takes minutes, one GPU serves one request at a time, and there is no auth, no safety filter, no metering β three things a public LLM API cannot ship without.
The first fix is warm pools: inference servers that load weights once at startup and stay resident, fronted by a gateway that authenticates, applies per-org rate limits, and streams tokens back over SSE as they generate β because a user watching a 30-second generation needs the first token in well under a second, not the last.
The serving plane grows a spine: safety, routing, dispatch
A real request path has stages: gateway β safety policy (prompt-level abuse and jailbreak screening) β request router β dispatcher. The dispatcher is the interesting box β it knows which model versions live on which GPU clusters, picks a target by requested model and current load, and keeps warm pools sized per model tier so a burst on the small fast model never evicts the large one.
This tiering is also the latency story: small models answer in well under ~300ms and absorb most traffic; large-context requests route to bigger clusters with a ~1s budget. A telemetry bus taps every hop β latency, token counts, errors β because at millions of requests/day you debug from aggregates, not logs.
The training plane: a factory, not a service
Training shares nothing with serving except the artifact it produces. The pipeline is a batch factory: a data lake feeds preprocessing (dedup, filtering, tokenization), which feeds a distributed training run β on the order of ~2K accelerators for weeks on a trillion-token corpus, orchestrated by Kubernetes or Slurm over a high-bandwidth interconnect fabric.
At that scale, hardware failure is a schedule item, not an exception: with thousands of GPUs running for weeks, node failures arrive routinely. Checkpointing the full training state to durable storage on a regular cadence is what converts a dead node from 'restart a multi-million-dollar run' into 'lose the minutes since the last checkpoint'. Checkpoint frequency is itself a trade-off β snapshot time steals training throughput.
?The follow-up that filters seniors
'A node dies two weeks into the run β what happens?' The answer is checkpoint-restore plus elastic rescheduling, and the sharp trade-off: checkpoint too often and you burn throughput on snapshots, too rarely and each failure costs hours of GPU-time across the whole fleet. Saying that trade-off out loud is the signal.
The registry is the bridge; canaries are the gate
The model registry is the only door between the planes: training publishes versioned weights with eval scores attached, and serving deploys exclusively from it. New versions roll out as canaries β a small slice of traffic on the new weights while automated checks compare quality metrics, latency, and refusal rates against the incumbent β with automated rollback wired to the same signals.
This is where fine-tuning slots in without a new architecture: POST /v1/fine-tunes runs a small training job against an org's uploaded files, and the resulting adapter weights land in the same registry, deployed through the same canary gate, scoped to that tenant. One promotion path for every model that ever serves traffic.
Metering, billing, and the operator console
Every request already emits token counts onto the telemetry bus; a usage pipeline aggregates them into an OLAP store (~1 KB/request, on the order of a GB/day of logs) that powers GET /v1/usage and per-token billing. Metering must survive cancelled streams β bill the tokens actually generated β which is why it hangs off telemetry emitted during generation, not a post-hoc reconciliation.
The admin console closes the loop for humans: rollout controls, per-org quotas and key management, safety overrides, and incident response. Enterprise requirements β tenant isolation, regional data residency, retention policies β show up here as routing policy (pin an org's traffic to a region's pools) rather than as new machinery. The final diagram is the lane architecture: gateway β safety β router β dispatcher β pools, with training β registry β deployment feeding it from behind.
!Name the isolation boundary
Interviewers will ask what stops one tenant's traffic β or fine-tuned model β from affecting another's. The answer lives at the dispatcher: per-org quotas before dispatch, tenant-scoped adapters, and regional pinning as routing policy. If isolation is not in the routing layer, it is nowhere.
Blueprint
Architecture Diagram
The narrated components above, laid out as an actual flow β so you can see how a request moves through the system, not just read a list of pieces.
Global API gateway
Global API gateway
auth
safety policy
request router
Dispatcher selects model
Dispatcher selects model version/cluster
Dispatcher selects model version/cluster, manages warm pools, streams tokens back via SSE
Telemetry bus aggregates
Telemetry bus aggregates latency
Telemetry bus aggregates latency, token usage, errors
Training pipeline
data lake
preprocessing
distributed training cluster
model registry
deployment
Vector store
Vector store
file storage for RAG
file storage for RAG, integrated via connectors
Admin console manages
Admin console manages rollouts
Admin console manages rollouts, quotas, keys, safety overrides
Flow Diagram
How the API maps to this flow
- 1
POST /v1/chat/completionsβ main chat API. - 2
POST /v1/fineβ tunes - submit training job. - 3
POST /v1/filesβ upload documents for fine-tune or RAG. - 4
GET /v1/modelsβ list available models and capabilities. - 5
GET /v1/usageβ usage metrics for billing.
?But why does this actually hold up at scale?
Inference: assume 100 tokens/s average per request, 1M requests/day -> 100M tokens/day. With 100 tokens per GPU/s, need ~12K GPU-seconds/day; with concurrency, keep 500 GPUs active.
Video walkthrough
How ChatGPT Works Technically | ChatGPT Architecture
ByteByteGo Β· 7 min
The eight-minute version of what sits behind a model endpoint, before you design your own.
Work the prompt yourself first β guided practice grades your own answer step by step. Watching someone else design it feels like progress and teaches you far less.
Interview flow
Dialogue timeline
Interviewer
Outline product surfaces.
Candidate
Core: /completions, /chat, embeddings, fine-tune jobs, file uploads, safety filters, usage/billing, admin console.
Interviewer
Serving pipeline?
Candidate
API gateway -> request router -> safety filter -> model dispatcher -> inference clusters (GPU pods). Stream tokens back via SSE/WebSocket. Cache small models for low-latency.
Interviewer
Training and deployment?
Candidate
Offline training on massive GPU clusters (data lake -> preprocessing -> distributed training). Model registry stores versions. Canary inference nodes + automated rollback.
Scoping
Requirements & trade-offs
Functional Requirements
- βREST/WS APIs for text/chat completions, embeddings, moderation, fine-tuning jobs.
- βFile uploads + vector store integration for RAG use cases.
- βUsage metering + billing per token or per minute.
- βSafety filters, abuse detection, rate limiting per org.
- βAdmin tooling for rollout, model versioning, incident response.
Non-Functional Requirements
- βLatency: < 300 ms for small models, < 1s for large context responses.
- βThroughput: millions of requests/day, burst handling via autoscaled GPUs.
- βSecurity: isolation per tenant/org, signed requests, audit logs.
- βCompliance: data retention policies, regional data residency for enterprise accounts.
Blueprint
Architecture modules
Module 1
API Endpoints
- β’POST /v1/chat/completions - main chat API.
- β’POST /v1/fine-tunes - submit training job.
- β’POST /v1/files - upload documents for fine-tune or RAG.
- β’GET /v1/models - list available models and capabilities.
- β’GET /v1/usage - usage metrics for billing.
Module 2
Back-of-the-Envelope
- β’Inference: assume 100 tokens/s average per request, 1M requests/day -> 100M tokens/day. With 100 tokens per GPU/s, need ~12K GPU-seconds/day; with concurrency, keep 500 GPUs active.
- β’Training: 1T token run on 2048 A100s for several weeks -> orchestrate via Kubernetes/Slurm + NVLink fabric.
- β’Vector store: 100M embeddings (1536 dims) -> ~600 GB; use partitioned ANN index (FAISS/HNSW).
- β’Usage logs: 1 KB per request -> 1 GB/day; store in OLAP DB for billing.
Module 3
System Diagram Notes
- β’Global API gateway -> auth -> safety policy -> request router.
- β’Dispatcher selects model version/cluster, manages warm pools, streams tokens back via SSE.
- β’Telemetry bus aggregates latency, token usage, errors.
- β’Training pipeline: data lake -> preprocessing -> distributed training cluster -> model registry -> deployment.
- β’Vector store + file storage for RAG, integrated via connectors.
- β’Admin console manages rollouts, quotas, keys, safety overrides.
Module 4
Design Playbook
- β’Clarify workloads (chat vs embeddings vs fine-tune).
- β’Explain inference routing, autoscaling, streaming responses.
- β’Cover safety filters (prompt scanning, output moderation).
- β’Discuss training pipeline, evals, canary rollouts, rollback triggers.
- β’Highlight billing/usage metering, multi-tenant isolation, SLAs.
- β’Mention observability: latency heatmaps, GPU utilization, token stats.