Asked at
URL Shortener (TinyURL)
Asked from Junior level upFoundations & Storage
Distributed Rate Limiter
Asked from Mid level upAPI Gateway & Security
Distributed Key-Value Store
Asked from Senior level upFoundations & Storage
Distributed Notification Service
Asked from Mid level upMessaging & Queues
Distributed Web Crawler
Asked from Mid level upDistributed Systems
Metrics & Monitoring Platform
Asked from Senior level upObservability & Time-Series
Real-Time Chat App (like WhatsApp or Slack)
Asked from Mid level upReal-Time & WebSockets
Social News Feed (like X/Twitter)
Asked from Mid level upSocial & Feed Systems
Ride-Hailing App (like Uber)
Asked from Senior level upGeospatial & Real-Time
Low-Latency Stock Exchange Matching Engine
Asked from Staff level upFintech & Low Latency
Global Video Streaming Platform (like YouTube or Netflix)
Asked from Senior level upMedia & Streaming
Distributed Hotel & Ticket Reservation System
Asked from Mid level upE-Commerce & Transactions
Shared Document Editor (like Google Docs)
Asked from Staff level upReal-Time & Distributed State
Game Leaderboard
Asked from Junior level upCaching & Data Structures
File Sync Service (Dropbox / Google Drive)
Asked from Mid level upStorage
Payment System
Asked from Senior level upPayments & Transactions
Ad Click Aggregation
Asked from Senior level upStream Processing
AI Support Assistant (RAG)
Asked from Senior level upAI Systems
LLM Inference Platform
Asked from Senior level upAI Systems
Enterprise Semantic Search
Asked from Mid level upAI Systems
AI Code Completion
Asked from Senior level upAI Systems
LLM Gateway
Asked from Senior level upAI Systems
AI Agent That Takes Actions
Asked from Senior level upAI Systems
LLM Evaluation Platform
Asked from Senior level upAI Systems
AI Document Processing Pipeline
Asked from Mid level upAI Systems

Design an LLM Inference Platform

Asked from Senior level upEmerging topicPart of the AI track: start with AI basicsDomain: AI Systems
Design it: check it against goals
Concepts to know first:

Serve several open language models to every product team through one API, with streaming, fair quotas and a cost per token you can predict.

An analogy

Like a busy kitchen with a few very expensive ovens. Orders are grouped so no oven sits idle, and each team gets a fair share of oven time. A queue shows when to fire up another oven.

Where this analogy stops working: An oven cooks each dish in one go. A GPU writes every answer one token at a time. Its memory, not only its time, limits how many answers it can hold at once.

Where this design ends up. This is version 3 of 3. Part 5 builds it up from version 1 and says why each part was added.
  1. Teams
    • Product team apps
  2. Gateway
    • Gateway
  3. Routing
    • Router
    • Queue per model
  4. GPUs
    • Chat lane GPUs
    • Batch lane GPUs
    • 70B model
  5. Usage
    • Usage metering

1. Requirements and scope

Functional Requirements
  • One API for every team: send a prompt, choose a model, get the answer streamed back token by token.
  • Serve several models, such as a small fast one and a large accurate one, and add new versions safely.
  • Give each team a token quota and a rate limit, and report usage for billing.
  • Offer a cheaper batch lane for work that can wait, such as summarising yesterday's tickets.
Non-Functional Requirements & SLAs
  • Time to first token under about 0.5 s for 95 of every 100 chat requests (the p95).
  • At least 20 tokens a second for each streaming answer, faster than people read.
  • Keep GPUs busy, since they are the main cost.
  • One team's traffic spike must not slow the other teams down.
Key Traffic Assumptions: 20 million requests a day, with the busiest hour at about 3 times the average. • A typical request has about 1,000 prompt tokens and 300 output tokens.

2. Back-of-the-envelope numbers

Write Throughput
Usage records: one per request, written in batches to a metering pipeline
Read Throughput
20M ÷ 86,400 ≈ 230 requests/s on average, about 700/s at peak; 700 × 300 ≈ 210,000 output tokens/s at peak
Storage Growth
Model weights at 2 bytes a parameter: about 16 GB for an 8B model, 140 GB for a 70B model. Usage logs ≈ 20M/day × 200 B ≈ 1.5 TB a year
RAM Cache Footprint
KV cache for a Llama-3-style 8B model: 32 layers × 8 key-value heads × 128 numbers × 2 (keys and values) × 2 bytes ≈ 128 KB a token. A 1,300-token request holds about 166 MB. On an 80 GB GPU, after 16 GB of weights, (80 − 16) GB ÷ 166 MB ≈ 380 requests fit at once

3. API

POST/v1/completions{ model, messages, maxTokens, stream: true } → tokens streamed back (server-sent events)
GET/v1/modelsThe models this team may call, with their context lengths
GET/v1/usage?team={id}&day={date}Tokens in and out per model, for billing

4. Data model and storage

Storage Strategy: A relational database holds the model registry, teams and quotas. Token counters for rate limits live in Redis. Usage events flow through a queue into a warehouse for billing.
MODEL(id, version, weights_uri, gpus_needed, max_context) · TEAM(id, tokens_per_minute, daily_tokens) · USAGE(team_id, model, minute, tokens_in, tokens_out)

5. The design, in three versions

Version 1: One model on one GPU server

A single server loads one model and answers requests one batch at a time. A new batch starts only when the whole previous batch has finished.

Inference v1: One Model on One GPU Server Version 1 of 3

The picture follows one request through the parts of this version, in order. Under it, switch a part off to see what the request does without it.

One request, step by step

Each numbered arrow is one step. Press "Simulate Request Flow" to follow them one at a time.

Product team appsAPI serverGPU server123
  • The order of the steps
  • A request or its reply

The parts: switch one off

1. Teams

Product team appsCall one API
Example figures
Speaks
HTTPS + SSE

2. Gateway

API serverForwards prompts
Example figures
Time budget
< 5 ms

3. GPU

GPU serverOne model, whole batches
Example figures
Capacity
Idle slots

The steps in words0 of 3 steps shown

  1. Team app to API serverHTTPS · 10ms

    POST /v1/completions { model, messages, stream: true }

  2. API server to GPUBatch slot · 900ms

    Waits for the whole previous batch to finish

  3. GPU to Team appSSE · 50ms/token

    Tokens stream back, about 20 a second or faster

Why this version
Working answers in a day, enough for one team's prototype.
Next bottleneck
A batch waits for its longest answer, so the GPU sits half idle, and one team's burst blocks everyone.

Write path, read path and failures

Each path follows one request through the final design (version 3), one hop at a time.

Write pathRoll out a new model version

  1. Model team
  2. Weight store
  3. Chat lane GPUs
  4. Router
  1. Model team to Weight store

    The team uploads the new weights. A 70B model in 16-bit numbers is about 140 GB.

  2. Weight store to Chat lane GPUs

    Spare GPU servers copy the weights to fast local disk and load them before taking traffic.

  3. Router to Chat lane GPUs

    The router sends a small share of traffic, for example 5%, to the new version.

  4. Chat lane GPUs to Router

    Latency and errors on that share are compared with the old version. If they are worse, the router moves the share back.

Read pathServe a chat request

  1. Team app
  2. Gateway
  3. Router
  4. Chat lane GPUs
  5. Usage metering
  1. Team app to Gateway

    A product team's app sends a prompt with its API key.

  2. Gateway to Router

    The gateway checks the key and the team's token quota, and marks the request as chat or batch.

  3. Router to Chat lane GPUs

    The router picks a chat GPU with room in its batch. It prefers one that already holds this system prompt in its cache.

  4. Chat lane GPUs to Team app

    The GPU reads the whole prompt first, then streams the answer one token at a time.

  5. Chat lane GPUs to Usage metering

    It reports the tokens in and out, so each team pays for what it used.

What breaks, and what happens then

  • One team sends a sudden spike

    What users see
    Other teams wait longer for their first token.
    What the design does
    Quotas and priority per team at the gateway. Batch work waits in its own lane.
  • A GPU server fails during an answer

    What users see
    That answer stops part way.
    What the design does
    The gateway retries on another GPU, and the answer starts again.
  • Long prompts fill GPU memory

    What users see
    New requests wait or are refused.
    What the design does
    The scheduler limits the tokens each GPU holds at once and queues the rest.
  • A new model version answers worse

    What users see
    Users in the small test share get worse answers.
    What the design does
    The share stays small until the comparison passes, and the router can move it back at once.

6. Deep dives

Memory, not compute, decides batch size
As the model reads each token, it saves two lists of numbers for it, called keys and values. With this KV cache, it does not have to work out those numbers again for earlier tokens. It takes about 128 KB a token for an 8B model. Long prompts fill memory fast, so the scheduler must stop admitting requests or pause one. Paging that memory avoids wasting space on answers that end early.
Scaling on the right signal
GPU use reads close to full both when the server keeps up and when users are waiting, so it cannot tell the two apart. Scale on queue length and time to first token instead. Keep spare GPUs with the weights already loaded, since loading them is the slowest step.

7. Follow-up questions

  • One team suddenly sends ten times its usual traffic. What happens? (Its rate limit and token quota reject the extra with 429, so other teams' queues stay short; the platform alerts the team.)
  • How do you release a new model version safely? (Load it beside the old one and send it a small share of traffic. Compare quality and latency on a fixed test set, then shift traffic in steps.)

What it costs

GPUs are the bill, and an idle GPU costs the same as a busy one. Batching more requests on each GPU lowers the cost per token. A separate, cheaper pool for jobs that can wait keeps the fast pool small.

Another way to design it

Teams could call a hosted model API and run no GPUs at all. That is cheaper at low or uneven volume, and there is nothing to operate. Running your own pays off with steady high volume, or with data that may not leave your network.

8. How answers are judged

A passing answer at Mid level. A complete design with numbers: about 700 requests a second at peak, about 210,000 output tokens a second. It explains batching and goes deep on one part, such as per-team quotas.

How each level is judged
What is judgedJuniorMidSeniorStaff
BreadthHow much of the system does the answer cover?Names the core parts: clients, servers, a database and a cache.Covers the whole main flow, from the request to the stored data and back.Builds a complete design without being led through it.Covers the system, the systems around it and who owns each part.
DepthHow far does it go into the hard parts?Explains what each part does and why it is there.Goes deep on one part, such as the database or the cache.Goes deep on the two or three riskiest parts.Goes deepest where the risk is largest, and explains why the risk is there.
DrivingWho leads the conversation?Follows the interviewer, step by step.Moves forward alone, with an occasional nudge.Leads the conversation from start to finish.Changes the problem when the question asked is not the right one.
Trade-offsAre choices compared and justified?Names more than one option.Says why one option was picked over another.Compares options in detail, with what each one costs.Ties each choice to cost, speed and risk for the business.
Unclear questionsWhat happens when the question is vague?Answers the questions that are asked.Asks questions to make the problem clear.Sets the scope and says what is left out.Questions the assumptions behind the problem itself.
ScopeWhat does it consider beyond the normal path?Covers the normal path, when everything works.Adds what happens when a part fails.Adds growth: what breaks at ten times the load, and the fix.Adds abuse, cost and the daily work of running the system.

Requirements and scope

Strong answer
Before I design, I want to know who calls this and what they need. Chat needs first tokens within about half a second, while overnight batch jobs can wait. Each team needs a quota, so one team cannot starve the rest. Which models must we serve on day one?
Weak answer
Every request is a prompt in and an answer out. I will treat them all the same and serve them in order.

Shows: Unclear questionsThe difference: Chat and batch work have very different deadlines. Treating them the same makes people wait behind jobs that could have run later, more cheaply.

Estimates

Strong answer
20 million requests a day is about 230 a second, about 700 at peak. At 300 output tokens each, peak is about 210,000 tokens a second. An 8B model keeps about 128 kilobytes per token in GPU memory, so a 1,300-token request holds about 166 megabytes.
Weak answer
The model is 16 gigabytes and a GPU has 80. So each GPU holds five copies of the model and serves five requests at a time.

Shows: DepthThe difference: Memory goes to each request's keys and values, not to copies of the weights. One copy serves a few hundred requests at once.

Core design

Strong answer
A gateway checks each team's key and quota, then routes to that model's pool. Each GPU runs continuous batching: when one answer finishes, a waiting request takes its place right away. KV-cache memory is handed out in small pages, so an answer wastes at most one part-filled page.
Weak answer
Each GPU takes a batch of 32 requests, runs them together, and starts the next batch when all 32 have finished.

Shows: DepthThe difference: The batch waits for its longest answer, so most slots sit empty for most of the time. Continuous batching refills each slot as soon as it frees.

Deep dive

Strong answer
The hard part is scaling, because a new GPU must load gigabytes of weights before it serves anything. I would scale on queue length and time to first token, not GPU use, which stays high anyway. I would keep weights on local disk and hold a little warm spare capacity.
Weak answer
I would add GPUs when GPU utilisation goes above 80 percent and remove them when it falls below 30 percent.

Shows: DepthThe difference: A busy GPU is the goal, so utilisation stays high while users wait in the queue. Queue length and time to first token show the real pressure.

Failures and trade-offs

Strong answer
If the large model is overloaded, chat requests can fall back to the smaller model, and batch work waits. A team over its quota gets 429 with a retry time. If a GPU fails before any token is sent, the gateway retries once elsewhere. Mid-stream, the stream ends with a clear error.
Weak answer
If a GPU fails, the requests on it fail too, and the teams can retry if they want to.

Shows: Trade-offsThe difference: Many retries at once would land on the busiest pool. The platform should retry once itself and shed batch work first, protecting chat.

We wrote this guide in our own words, informed by public interview guides such as AlgoMaster and Hello Interview. We are not connected to either site. Interviewers differ. The guide and the example answers show the direction each level takes, not a checklist.

10. Check your design with your own AI

Write your design first. Then copy this prompt into the AI chat you already use, and add your design at the end. It asks for a score in each area, one fix for each, and two follow-up questions.

The site sends nothing anywhere. An AI review can be wrong, so check what it says against sections 8 and 9.

See the prompt
You are a system design interviewer. Review my design for the interview problem below.

Problem: Design an LLM Inference Platform
Serve several open language models to every product team through one API, with streaming, fair quotas and a cost per token you can predict.

What users must be able to do:
- One API for every team: send a prompt, choose a model, get the answer streamed back token by token.
- Serve several models, such as a small fast one and a large accurate one, and add new versions safely.
- Give each team a token quota and a rate limit, and report usage for billing.
- Offer a cheaper batch lane for work that can wait, such as summarising yesterday's tickets.

How well it must work:
- Time to first token under about 0.5 s for 95 of every 100 chat requests (the p95).
- At least 20 tokens a second for each streaming answer, faster than people read.
- Keep GPUs busy, since they are the main cost.
- One team's traffic spike must not slow the other teams down.

Numbers to assume:
- 20 million requests a day, with the busiest hour at about 3 times the average.
- A typical request has about 1,000 prompt tokens and 300 output tokens.

Judge my design at the Mid level.
A passing answer at this level: A complete design with numbers: about 700 requests a second at peak, about 210,000 output tokens a second. It explains batching and goes deep on one part, such as per-team quotas.

For each area below, say whether my design is strong, fine or weak. Give one reason and one fix for each:
1. Requirements and scope
2. Estimates
3. Core design
4. Deep dive
5. Failures and trade-offs

Then ask me the two follow-up questions an interviewer would ask next.
Do not write a full model answer for me.

My design:
[Describe your parts, how one request moves through them, and why you chose each one.]