ML Design Examples¶
The best way to learn ML systems design is through worked examples. This file walks through eight complete designs, covering recommendation systems, search ranking, ads click prediction, fraud detection, content moderation, modern RAG conversational AI, large-scale image search, and reasoning and agentic AI systems.
- Each example follows a consistent framework:
- Problem framing: what are we building, who are the users, what are the constraints?
- Data: what data do we have, how is it collected, how is it labelled?
- Features: what features does the model need?
- Model: what architecture and training approach?
- Serving: how is the model deployed and served?
- Evaluation: how do we measure success?
- Iteration: what improvements would we make over time?
1. Recommendation System (e.g., YouTube, Netflix, Spotify)¶
Problem Framing¶
- Goal: show users content they will enjoy, maximising engagement (watch time, listens, clicks).
- Scale: 1B+ users, 100M+ items, 10K+ recommendations per second.
- Latency: <200ms for the full recommendation pipeline.
- Key challenge: the candidate space is enormous (100M items). Cannot score all items for all users in real-time.
Architecture: Two-Stage Pipeline¶
100M items → Candidate Generation (fast, coarse) → 1000 candidates
→ Ranking (slow, precise) → 100 ranked items
→ Re-ranking (business rules) → 20 shown to user
Candidate Generation¶
- Goal: reduce 100M items to ~1000 candidates. Must be fast (<50ms).
- Two-tower model: encode users and items into the same embedding space. The user embedding captures preferences; the item embedding captures content characteristics. Score = dot product of user and item embeddings.
- Training: contrastive learning on (user, positive_item, negative_items) triples. Positives = items the user engaged with. Negatives = random items + hard negatives (popular items the user did not engage with).
- Serving: precompute all item embeddings. At request time: compute the user embedding, ANN search (HNSW in a vector database) to find the 1000 nearest item embeddings.
Ranking¶
- Goal: precisely score the 1000 candidates. Can afford ~100ms.
- Model: a deep neural network (MLP or transformer) that takes rich features: user features (demographics, history, context), item features (content, popularity, freshness), and cross features (user-item interaction history, contextual relevance).
- Output: predicted probability of engagement (click, watch 50%+, like, share). Multiple objectives can be combined: \(\text{score} = w_1 \cdot P(\text{click}) + w_2 \cdot P(\text{watch}) + w_3 \cdot P(\text{like})\).
Re-ranking¶
- Apply business rules: diversity (do not show 5 videos from the same creator), freshness (boost new content), safety (filter flagged content), and personalised exploration (show some lower-ranked items the user might discover).
Back-of-Envelope Numbers¶
-
Item embedding index: 100M items × 256-dim × float16 = 50 GB. HNSW index adds ~2x overhead → ~100 GB. Fits on a single machine with 128 GB RAM, or shard across 4 × 32 GB machines.
-
User embedding computation: ~5ms per user (small MLP on user features). At 10K QPS, need ~50 model replicas to handle the load.
-
ANN search: ~2ms for top-1000 from 100M vectors with HNSW. At 10K QPS, each index replica handles ~500 QPS → need 20 replicas.
-
Ranking model: 1000 candidates × ~0.1ms per candidate = 100ms per request. At 10K QPS, need 1000 GPU-seconds per second → ~10 A10G GPUs for ranking alone.
-
Total infrastructure: ~20 embedding index replicas + ~50 user embedding servers + ~10 ranking GPUs + caching + load balancers. Cost: ~\(50K-\)100K/month at cloud prices.
Cold Start¶
-
New users (no history): use demographic features, device/location context, and popularity-based recommendations. After 5-10 interactions, switch to the personalised model.
-
New items (no engagement data): use content-based features (title, description, thumbnail embeddings). Allocate an exploration budget: show new items to a fraction of users to gather engagement data quickly. Items with no engagement after a boost period are demoted.
-
Cold start is a systems problem: the feature store must handle missing features gracefully (return defaults, not errors). The model must be trained with missing features (dropout on user history features during training simulates new users).
Evaluation¶
- Offline: NDCG (Normalized Discounted Cumulative Gain), recall@K, precision@K on a held-out set.
- Online: A/B test measuring watch time, DAU, retention. Long-term A/B tests (weeks) to catch effects on user retention that short tests miss.
2. Search Ranking (e.g., Google, Bing)¶
Problem Framing¶
- Goal: given a user query, return the most relevant results from a corpus of billions of documents.
- Latency: <500ms total (100ms retrieval + 200ms ranking + 100ms rendering + overhead).
Architecture: Query Understanding → Retrieve → Rank¶
Query Understanding¶
-
Before retrieval, process the raw query to improve results:
-
Spell correction: "reccomendation systm" → "recommendation system." Use an edit-distance model or a sequence-to-sequence model trained on (misspelled, corrected) pairs from search logs.
-
Query expansion: add related terms to improve recall. "Python ML" → "Python machine learning scikit-learn pytorch." Use synonym dictionaries, word embeddings, or an LLM to generate expansions.
-
Intent classification: determine what the user wants. "buy Nike shoes" is transactional (show product pages). "How does backpropagation work" is informational (show articles). "facebook.com" is navigational (go directly to the site). Different intents should trigger different retrieval strategies and result layouts.
-
Entity recognition: extract entities from the query. "best restaurants near Times Square" → location: "Times Square", entity type: "restaurants." Route to a location-aware search pipeline.
Retrieval¶
-
BM25 (traditional): term-matching retrieval using an inverted index. Fast, effective for keyword queries. No semantic understanding ("dog food" does not match "canine nutrition").
-
Dense retrieval: encode queries and documents as embeddings (using a bi-encoder like DPR or ColBERT). Retrieve by ANN search. Captures semantic similarity ("dog food" matches "canine nutrition"). Slower than BM25 but better for natural language queries.
-
Hybrid retrieval: combine BM25 and dense retrieval. BM25 finds exact keyword matches; dense retrieval finds semantic matches. Merge and deduplicate. Best of both worlds.
Ranking¶
-
Learning to rank: a model scores each (query, document) pair. Three approaches:
- Pointwise: predict a relevance score for each document independently. Simple but ignores relative ordering.
- Pairwise: predict which of two documents is more relevant. LambdaMART (gradient-boosted trees) is the classic approach.
- Listwise: optimise the entire ranked list directly for a list-level metric (NDCG). More complex but best results.
-
Cross-encoder: a transformer that takes
[query, document]as input and outputs a relevance score. More accurate than bi-encoders (which encode query and document independently) because it captures fine-grained interactions. But too slow for the full corpus — used only for re-ranking the top 100-1000 candidates from retrieval.
Features¶
- Query features: query length, language, intent classification (navigational, informational, transactional).
- Document features: PageRank, freshness, content quality score, domain authority.
- Query-document features: BM25 score, embedding similarity, exact match count, click-through rate for this (query, document) pair in historical logs.
3. Ads Click Prediction¶
Problem Framing¶
- Goal: predict the probability that a user will click on an ad. This determines how much to bid in real-time auctions.
- Scale: 100K+ auctions per second, each requiring a prediction within 10ms.
- Revenue impact: a 0.1% improvement in click prediction accuracy translates to millions in additional revenue.
Architecture¶
-
Feature engineering is the core of ads systems. Features include:
- User features: demographics, browsing history, purchase history, device, location, time of day.
- Ad features: creative (image/text), advertiser, category, historical CTR, bid amount.
- Context features: page content, ad position, device type, connection speed.
- Cross features: user_category × ad_category interaction, user_region × ad_campaign interaction.
-
Model: historically logistic regression (simple, fast, interpretable). Modern systems use deep learning: a DLRM (Deep Learning Recommendation Model) with embedding tables for categorical features and an MLP for dense features.
-
Calibration: the predicted probability must be accurate (if the model says P(click) = 0.05, then 5% of such impressions should actually be clicked). Calibration is critical because the predicted probability directly determines bid amounts.
-
Exploration-exploitation: always showing the predicted best ad is suboptimal long-term (you never discover that a new ad might be better). Thompson sampling or \(\epsilon\)-greedy exploration ensures some fraction of impressions go to less-certain ads to gather data.
Real-Time Bidding¶
- When a user loads a page, an ad auction runs in <100ms:
- Publisher sends a bid request (user info, page context) to multiple ad exchanges.
- Each advertiser's bidding server predicts CTR for their ads.
- Bid = CTR × value_per_click. Higher bids win the auction.
- The winning ad is shown; if clicked, the advertiser pays.
4. Fraud Detection¶
Problem Framing¶
- Goal: detect fraudulent transactions in real-time (credit card fraud, account takeover, fake reviews).
- Latency: <100ms (the transaction must be approved or flagged before the payment processes).
- Key challenge: extreme class imbalance (0.1% fraud rate). False positives block legitimate users; false negatives lose money.
Architecture¶
Features¶
- Transaction features: amount, currency, merchant category, time of day, is_international.
- User features: account age, average transaction amount, number of recent transactions, device fingerprint.
- Velocity features (real-time, from a streaming pipeline): number of transactions in the last 5 minutes, number of distinct merchants in the last hour, geographic distance from previous transaction.
- Graph features: is this merchant connected to known fraud rings? Is this device shared with flagged accounts?
Model¶
-
Gradient-boosted trees (XGBoost, LightGBM) are the standard for tabular fraud detection. They handle mixed feature types, are interpretable (feature importance), and train fast.
-
Handling imbalance: undersampling the majority class, oversampling the minority (SMOTE), or using class weights in the loss function. Focal loss (chapter 8) down-weights easy negatives.
-
The cost matrix: a false positive (blocking a legitimate transaction) has a cost (user frustration, lost sale). A false negative (missing fraud) has a different cost (financial loss). The decision threshold should minimise total expected cost, not maximise accuracy.
Human-in-the-Loop¶
- Uncertain predictions (model confidence between 0.3 and 0.7) are sent to human reviewers. Reviewer decisions become labels for retraining. This creates a feedback loop: the model improves over time as it sees more labelled fraud cases.
5. Content Moderation¶
Problem Framing¶
- Goal: automatically detect and remove harmful content (hate speech, violence, misinformation, CSAM) from a platform.
- Scale: billions of posts per day (text, images, video).
- Challenge: context-dependent (sarcasm, satire, cultural nuance). Must balance free expression with safety.
Architecture¶
-
Multi-modal classification: separate models for text, images, and video, with a fusion layer that combines their signals.
-
Text moderation: fine-tuned language model classifies text into categories (harassment, hate speech, misinformation, spam). Multilingual models handle 100+ languages.
-
Image moderation: vision model detects: explicit content (nudity, violence), text in images (OCR + text classifier), and known harmful content (hash-matching against databases of known CSAM).
-
Video moderation: sample frames at regular intervals, run image classifier on each frame, combine with audio transcription (ASR → text classifier).
-
Policy-as-code: moderation policies are defined in structured rules that map model outputs to actions:
if text_model.hate_speech_score > 0.9:
action = "remove"
elif text_model.hate_speech_score > 0.7:
action = "human_review"
else:
action = "allow"
- Policies change frequently (new regulations, evolving norms). Separating policy from model ensures changes can be deployed without retraining.
Proactive vs Reactive Moderation¶
-
Proactive (pre-publication): run classifiers on content before it goes live. High-confidence violations are blocked automatically. This prevents harmful content from ever being visible but adds latency to publishing and risks false positives (blocking legitimate content).
-
Reactive (post-publication): content goes live immediately. Users can report violations. Reports trigger classifier + human review. Lower latency for publishers but harmful content is visible until detected.
-
Most platforms use both: proactive for high-severity categories (CSAM: zero tolerance, block before publication) and reactive for nuanced categories (misinformation: needs human judgement, review after reports).
Hash Matching¶
-
For known harmful content (CSAM, terrorist propaganda), use perceptual hashing: compute a hash of the image/video that is robust to minor modifications (cropping, resizing, compression). Compare against databases of known harmful content (NCMEC's hash database, GIFCT shared hash database). Match → immediate removal without needing a classifier.
-
PhotoDNA (Microsoft) is the standard perceptual hash for CSAM detection. It is a legal obligation in many jurisdictions, not just a technical choice.
Back-of-Envelope Numbers¶
-
Scale: 1B posts/day = ~12K posts/second. Each post needs: text classification (~5ms), image classification (~20ms), hash matching (~1ms). At 12K QPS: need ~60 text classifiers, ~240 image classifiers, and ~12 hash matchers (plus redundancy).
-
Human review: if 2% of posts are flagged for review = 20M/day. At 100 reviews/reviewer/day, need 200K reviewers (this is why automated accuracy matters: every 0.1% reduction in false positives saves 1M reviews/day).
-
Latency budget: proactive moderation must complete within the publishing pipeline (~500ms). Text (5ms) + image (20ms) + hash (1ms) + overhead = well within budget. Video is the exception: even sampling 1 frame/second from a 10-minute video requires 600 classifier calls → handle asynchronously.
Escalation Workflow¶
-
Automatic removal → human review of appeals → specialist review (legal, cultural experts) → policy team for ambiguous cases. Each level handles fewer cases with more nuance.
-
Feedback to model: human review decisions are the highest-quality labels for retraining. Disagreements between the model and reviewers are prioritised for active learning — they represent the cases the model handles worst.
6. Conversational AI (RAG-Based Chatbot)¶
Problem Framing¶
- Goal: a chatbot that answers questions about a company's products using its documentation.
- Requirements: accurate (does not hallucinate), cites sources, handles follow-up questions, and stays within the product domain.
Architecture (Production Hybrid RAG)¶
User query → Semantic Cache (hit → return cached grounded answer)
↓ (miss)
Query Rewriting → Parallel Retrieval (Contextual BM25 + Dense Vector Search)
↓
Reciprocal Rank Fusion (top 50-100)
↓
Cross-Encoder Reranker (top 5-8)
↓
Prompt + Grounded Chunks → LLM → Citation-Verified Response
Components¶
-
Document ingestion and contextual chunking shapes retrieval accuracy before a single user ever asks a question. Standard splitting strategies each carry clear trade-offs.
- Fixed-size chunking slices text every N tokens (say 500 tokens with a 50-token overlap), keeping index sizes predictable yet frequently severing sentences or tables mid-thought.
- Recursive and semantic chunking prefers natural boundaries (headings, paragraphs, then sentences) so each chunk remains a coherent unit of meaning.
- Contextual chunking (popularised by Anthropic's Contextual Retrieval) fixes the biggest failure mode of chunked search, namely lost document context. A raw chunk reading "Revenue rose 3% last quarter" cannot be matched to "Acme Q2 2025 results" because the company and quarter lived three paragraphs earlier. During offline ingestion, a fast LLM reads the parent document and prepends a brief situational blurb to every chunk before indexing it into both the vector store and the lexical index, slashing retrieval misses dramatically.
-
Hybrid retrieval (BM25 + dense embeddings) avoids the blind spots of vector-only search. Dense bi-encoder embeddings excel at conceptual queries and paraphrases, yet struggle with exact error codes, SKU numbers, function names, and legal clauses. Production RAG executes BM25 lexical search and dense ANN vector search in parallel over the contextualised chunks, then merges both ranked lists via Reciprocal Rank Fusion (RRF) without needing fragile score normalisation across disparate scales.
-
Cross-encoder reranking acts as a precision filter. Retrieving a generous candidate set (top 50 to 100 chunks) from hybrid search maximises recall, and passing
(query, chunk)pairs jointly through a cross-encoder reranker lets full cross-attention score exact relevance, trimming the final prompt down to the sharpest 5 to 8 passages for roughly 20-40 ms of extra latency. -
Citation grounding and abstention keeps responses trustworthy. Each retrieved chunk enters the prompt tagged with a stable source ID, and the model is instructed (often with structured output schemas from chapter 20 file 03) to attach inline citations to every factual claim. Post-generation verification checks that cited claims are genuinely entailed by the referenced spans, and when reranker scores fall below a confidence threshold the system abstains honestly ("I cannot find that in the documentation") rather than guessing.
-
Semantic caching sits right at the front of the pipeline. Incoming queries are embedded and matched against a low-latency vector cache (such as Redis with vector indexing). When a new question lands above a strict cosine similarity threshold against a recently answered query, the system returns the verified answer immediately in tens of milliseconds without invoking the LLM. Cache keys must be scoped by user access permissions (ACLs) and corpus version so private documents never leak across tenants and stale answers invalidate automatically when documentation changes.
-
Guardrails and conversation memory keep multi-turn sessions safe and coherent. Input filters screen for prompt injection and off-topic abuse, while rolling conversation summaries preserve recent turns without overflowing context budgets.
Query Rewriting¶
- Users regularly ask ambiguous follow-up questions such as "What about the enterprise pricing?" whose meaning depends on earlier turns. Query rewriting combines recent conversation history with the latest message to synthesise a standalone search query ("What is the enterprise plan pricing for Product X?") before embedding and BM25 lookup. Running this step with a compact fine-tuned model adds only 5-30 ms while preventing retrieval from collapsing on follow-up turns.
Back-of-Envelope Numbers¶
- Documentation corpus of 10K pages averaging 2000 tokens each totals 20M tokens, yielding roughly 44K chunks at 500 tokens per chunk with 50-token overlap.
- Dual indexes stay lightweight at this scale. The dense vector index (44K chunks × 768 dims × float16) occupies roughly 65 MB (even 10M chunks fit in ~15 GB), alongside a compact inverted BM25 index.
- Latency breakdown on a semantic cache miss runs roughly 5 ms for query embedding and parallel BM25/vector search, 25 ms for cross-encoder reranking over top 50 candidates, and 400-1500 ms for streamed LLM generation (with sub-second TTFT). On a semantic cache hit (often 20-35% of customer support traffic), end-to-end latency drops below 30 ms.
- Cost profile improves sharply with caching and model right-sizing. At 1M queries per day averaging 2K tokens each, a 30% semantic cache hit rate combined with RadixAttention prefix caching (chapter 20 file 03) and a self-hosted quantised model cuts GPU spend by an order of magnitude compared with uncached frontier API calls.
Evaluation¶
- Retrieval quality tracks Recall@K, MRR (Mean Reciprocal Rank), and NDCG on curated golden query-document pairs, measuring hybrid + reranked retrieval independently from generation.
- Groundedness and citation fidelity measure whether every generated claim is supported by the cited passages (faithfulness) and whether the system abstains properly on unanswerable queries.
- End-to-end product metrics monitor user satisfaction (thumbs up/down), citation click-through rates, semantic cache hit rate, and escalation rate to human support agents.
7. Large-Scale Image Search¶
Problem Framing¶
- Goal: given an image, find visually similar images from a corpus of 1B+ images.
- Applications: reverse image search, product search (photo → matching products), duplicate detection.
- Latency: <500ms including network round trip.
Architecture¶
Embedding Extraction¶
-
Model: a pre-trained vision encoder (ViT, CLIP's image encoder, DINOv2). Fine-tuned on the specific domain if needed (fashion, e-commerce, medical imaging).
-
Training: contrastive learning (chapter 13). Positive pairs = different views of the same image (or image + matching text). Negative pairs = random images. The model learns to produce similar embeddings for similar images and dissimilar embeddings for different images.
Indexing¶
-
Offline: embed all 1B images and build an ANN index. For HNSW (file 03), building the index takes hours and the index is stored in memory (~128 GB for 1B × 512-dim × float16 + graph overhead).
-
Sharding: split the index across multiple machines. Each machine holds a shard. At query time, search all shards in parallel and merge the top-K results.
-
Incremental updates: new images (uploads, new products) must be added to the index. HNSW supports incremental insertion without rebuilding. Vector databases (Milvus, Pinecone) handle this natively.
Serving¶
-
Embedding service: a GPU server running the ViT model. Latency: ~20ms per image. Batch multiple queries for throughput.
-
Search service: the ANN index server. Latency: ~10ms for top-100 search over 1B vectors (with HNSW).
-
Caching: cache results for popular queries. For duplicate detection, cache the embedding of recently uploaded images and compare new uploads against the cache before searching the full index.
Evaluation¶
- Precision@K: are the top-K results actually similar?
- Recall@K: out of all truly similar images in the corpus, how many are in the top-K?
- Mean Average Precision (mAP): the area under the precision-recall curve.
- Human evaluation: for subjective similarity, human raters judge whether retrieved images are relevant.
8. Reasoning and Agentic AI System¶
Problem Framing¶
- Goal is to build a production AI assistant that solves complex, multi-step tasks (such as debugging codebases, synthesising research, or executing enterprise workflows) by combining extended reasoning with external tools (code execution, search, databases, internal APIs).
- Key challenge lies in extreme variance. A simple factual query needs a 300 ms reply costing a fraction of a penny, whereas a gnarly multi-file debugging session may spend 30 seconds thinking across ten tool invocations. Meanwhile, giving a model real tools turns prompt injection and hallucinated actions into genuine security and financial hazards.
Architecture¶
User Request → Input Guardrails & Complexity Router
│
┌─────────────┴─────────────┐
↓ (simple) ↓ (complex / multi-step)
Fast Model Path Agent Orchestrator (State + Budgets)
(low latency) ├── Reasoning LLM (variable thinking budget)
├── Grammar-Constrained Tool Calls
├── Sandboxed Tool Execution (microVMs / scoped APIs)
└── Policy Gate (human approval for risky writes)
↓
Output Verification, Streaming & Trace Store
Latency and Cost Routing Between Fast and Deep Models¶
-
Sending every incoming message to a heavyweight reasoning model destroys both latency SLOs and unit economics. Production agent platforms place a complexity router at the entry point, using a lightweight classifier (or confidence-based cascade, chapter 20 file 03) to sort traffic across model tiers.
-
Straightforward queries (definitions, quick summaries, template edits) go straight to a fast, compact model with minimal or zero reasoning overhead, answering in under a second at roughly 10-20x lower cost per token. Multi-step planning, tricky code synthesis, mathematical verification, and ambiguous tool orchestration escalate to a frontier reasoning model.
Variable Test-Time Thinking Budgets¶
-
Modern reasoning models (chapter 07) expose an explicit test-time thinking budget, controlling how many internal reasoning tokens the model may spend before emitting a tool call or final answer. Treating that budget as a first-class systems knob unlocks smooth control over quality, latency, and spend.
-
The orchestrator allocates thinking tokens dynamically based on query difficulty, user tier, and remaining SLA budget (for instance, 0-512 tokens for quick lookups, 2K-8K tokens for standard coding tasks, and 16K+ tokens with self-verification for hard analytical problems). Hard guardrails cap both total thinking tokens per turn and maximum agent loop iterations so a confused model can never spin indefinitely or rack up runaway API bills. Streaming progress indicators (such as step status updates or concise reasoning summaries) keep users informed while deep thinking runs.
Tool-Call Sandboxing and State Isolation¶
-
Letting an LLM run generated Python scripts, shell commands, or authenticated API calls breaks the traditional security perimeter. A malicious web page or poisoned document retrieved mid-task can embed indirect prompt injections attempting to steal secrets or mutate production data.
-
Ephemeral execution sandboxes isolate every untrusted code or shell call inside a disposable microVM (such as Firecracker), gVisor runtime, or locked-down container with strict CPU, RAM, wall-clock timeout, and network-egress policies (default-deny internet access unless explicitly whitelisted). The sandbox is wiped cleanly once the session ends.
-
Least-privilege tool interfaces enforce strict argument schemas using fast grammar-constrained decoding (chapter 20 file 03), pass short-lived user-scoped OAuth tokens rather than service-wide admin keys, and require idempotent tool APIs so network retries never duplicate side effects. High-impact or irreversible operations (sending external emails, modifying billing records, deploying to production) pause at a policy gate requiring explicit human-in-the-loop confirmation before execution.
-
Prefix caching and durable state keep multi-step trajectories affordable. Because an agent resends the growing conversation and tool-output history on every step, pairing durable workflow state (checkpointing after every tool call so crashed sessions resume mid-trajectory) with RadixAttention and tiered KV-cache offloading (chapter 20 file 03 and chapter 21 file 03) avoids recomputing the entire conversation prefix on every loop iteration.
Guardrails and Continuous Evaluation Monitoring¶
-
Layered guardrails inspect three boundaries independently, checking user prompts for policy violations, scanning untrusted tool outputs for indirect prompt-injection payloads before re-injecting them into context, and validating final outputs against safety, PII, and groundedness policies.
-
Trajectory observability extends standard OpenTelemetry tracing to capture the full agent execution graph, recording router decisions, thinking-token consumption, every tool invocation and latency hop, sandbox exit codes, and cache hit rates per session.
-
Offline and online evaluation must test full multi-step behaviour rather than single-turn prompts. Offline suites run deterministic task benchmarks inside replayable mock environments (measuring end-to-end task completion rate, tool-argument accuracy, and average steps to resolution) before any prompt, model, or tool change ships. Online monitors continuously sample live trajectories for automated LLM-as-a-judge grading, alerting on regressions in task success rate, tool-error spikes, p95 completion latency, guardrail trigger rates, and cost per resolved task (the true north-star metric for agentic systems).
The Interview Framework¶
-
When you encounter a systems design question, follow this framework:
-
Clarify requirements (2-3 minutes): ask about scale, latency, consistency requirements, and edge cases. "How many users? What latency is acceptable? What happens during failures?"
-
High-level design (5-7 minutes): draw the major components and their interactions. Start with the happy path. Use the patterns from files 01-03.
-
Deep dive (15-20 minutes): pick the most interesting/challenging component and design it in detail. This is where you show depth. For an ML system, the deep dive is often: the model architecture, the feature pipeline, or the serving architecture.
-
Evaluation and monitoring (3-5 minutes): how do you measure success? What can go wrong? How do you detect and respond to problems?
-
Iteration (2-3 minutes): what would you improve with more time/resources? This shows you understand tradeoffs and can prioritise.
-
What interviewers look for: structured thinking (not jumping to solutions), tradeoff awareness (every choice has a cost), practical knowledge (you have actually built systems), and communication (can you explain your design clearly?).