ML and AI system design questions, answered the way you’d say them.
25 questions for Data Scientist and AI/ML Engineer roles, Easy to Hard, 17 of them reported by candidates at companies. Say your answer out loud, then open ours. Free, no sign-up.
How would you build a model that estimates food delivery time?
Break the time into legs: assigning a rider, preparing the food, the rider reaching the restaurant, and the ride to the customer. Predict each leg with features such as the restaurant’s recent preparation times at that hour, order size, orders already in the kitchen, distance, route, traffic, weather and time of day, often with gradient-boosted trees, and update the estimate as each leg finishes. A late promise hurts more than an early one, so use an asymmetric or quantile loss; Uber’s DeepETA, for example, uses an asymmetric Huber loss.
Open a question to see the answer to say. Each links to its sources, and to its full explanation where we have one.
How would you set discounts across several shoe brands, given competitors’ prices, to maximise revenue?
MediumDesign
Separate predicting demand from choosing prices. First, model each product’s sales as a function of its own price, competitors’ prices and the prices of rival styles on the site, learning from past price changes or, better, randomised price tests, since past discounts are tangled up with season and stock. Then search the candidate discounts for the set that maximises expected revenue or margin, within rules such as margin floors. Rue La La’s pricing tool, built this way, raised revenue by about 9.7% in a field experiment.
Mention cannibalisation: a discount on one brand can pull sales from another, so price the competing styles together, not one at a time.
How would you build a model that estimates food delivery time?
MediumDesign
Break the time into legs: assigning a rider, preparing the food, the rider reaching the restaurant, and the ride to the customer. Predict each leg with features such as the restaurant’s recent preparation times at that hour, order size, orders already in the kitchen, distance, route, traffic, weather and time of day, often with gradient-boosted trees, and update the estimate as each leg finishes. A late promise hurts more than an early one, so use an asymmetric or quantile loss; Uber’s DeepETA, for example, uses an asymmetric Huber loss.
Report MAE alongside the share of orders that arrive later than promised, since customers judge the promise, not the average.
How would you rank new ads that have no click history, while still earning from proven ones?
MediumDesign
Give a new ad a sensible prior instead of zero: predict its click rate from the features it does have, such as advertiser, category, text and image, with a model that tracks its uncertainty, as Bing’s Bayesian click model keeps Gaussian beliefs over its weights. Then explore on purpose: Thompson sampling or a contextual bandit gives uncertain ads some impressions in proportion to their chance of being good, within a capped share of traffic. Log the probability of every choice, so new policies can be evaluated offline.
Li and colleagues’ contextual bandit gave a 12.5% click lift over a context-free bandit on Yahoo!’s front page.
Design a system that sorts incoming documents, such as invoices, contracts and ID proofs, into types.
MediumDesign
Agree the classes with the business, including an “other” class, and label a sample. Extract text with OCR for scans, but keep the layout too, since an invoice looks like an invoice before you read a word. Start with a TF-IDF and logistic regression baseline, then fine-tune a layout-aware model such as LayoutLMv3, which reached 95.44% accuracy on RVL-CDIP’s 16 document types. Send low-confidence predictions to people, track precision and recall per class, and retrain on their corrections.
ID proofs carry personal data, so mask what’s logged and check retention rules before storing them.
Design a machine learning system to detect payment fraud.
MediumDesign
Score each payment in real time, within the checkout’s latency budget; Stripe’s Radar decides in under 100 milliseconds. Use features such as the amount against the user’s history, payment velocity, device, location, merchant risk and signals shared across the network. Labels arrive late, when chargebacks or investigations close, and only for cases someone checked, so train on matured data and split by time. Fraud is rare, so judge models on precision and recall, set thresholds by cost to approve, challenge or block, and retrain often as fraudsters adapt.
Blocked payments never get a label, so send a small random sample of them for manual review to measure what the model gets wrong.
Design a system that suggests colour palettes for a user’s design.
MediumDesign
Extract the design’s current colours by clustering its pixels in a perceptual colour space such as CIELAB, where distances roughly match how different colours look. Generate candidate palettes from colour-harmony rules and from palettes people have saved, then rank them with a learned model of what looks good together: O’Donovan and colleagues trained models that score five-colour themes on large online datasets of rated themes. Enforce readability, such as WCAG’s minimum 4.5:1 contrast for normal text, and measure how often users apply a suggestion.
Personalise later: once you log which suggestions each user applies, their past choices can re-rank the candidates.
Design a system that flags unusual CPU time and memory use in a company’s recurring compute jobs.
MediumDesign
Judge each job against its own history, since a nightly ETL job and an ad-hoc query have different normals, and normalise by input size where you can. Start with robust statistics: flag runs whose modified z-score, built from the median and the median absolute deviation, exceeds 3.5, as the NIST handbook suggests. For several metrics at once, an Isolation Forest scores how quickly random splits isolate a run. Alert on sustained deviations, let engineers mark alerts useful or not, and tune thresholds from that feedback.
Use seasonal baselines for jobs whose load varies by weekday or month-end, or every Monday will look like an anomaly.
Design search over unlabelled images by colour, where a query names some of 25 palette colours, such as “mostly teal with some white”.
MediumDesign
Offline, map every pixel of each image to the nearest of the 25 palette colours, measured in a perceptual space such as CIELAB, and store the share of pixels per colour as a 25-number vector. A query becomes a target vector, and images are ranked by how closely their colour histograms match it. For scale, keep an inverted index from each colour to the images where it dominates, to prune candidates, or search the vectors with an approximate nearest-neighbour index, and compute histograms in batch as images arrive.
Downsample images before counting pixels: the colour shares barely change, and processing gets much cheaper.
Design a laugh detector for a phone or watch: data, sensors and model.
MediumDesign
Decide where it runs first: on the device keeps audio private and fast. The microphone is the main sensor, and a watch’s accelerometer can add the body’s shaking. For data, start with labelled audio such as AudioSet’s Laughter class, with 5,696 annotations, then record your own across ages, languages, rooms and noise, with consent. Turn audio into log-Mel spectrograms and fine-tune a small pretrained audio model, such as YAMNet, which predicts 521 AudioSet classes, smoothing predictions over time. Measure precision, recall and false alarms per hour.
False alarms are what users notice, so set the threshold for a target number of false triggers per hour rather than the best F1.
Design a customer-support assistant that answers from a company’s help articles and can check orders.
HardDesign
I’d split answering from acting. Answers come from hybrid retrieval over help articles and policies, re-ranked, with citations, an honest “not covered” and a handover to a human agent. Order lookups are tools that use the signed-in customer’s own scoped token, never an ID typed into chat, and refunds need approval. Around it sit Hindi and English support, injection and personal-data guardrails, a golden test set, and monitoring of escalations, groundedness and cost.
Interviewers probe the handover: pass the human agent a summary and the sources used, so the customer doesn’t have to repeat themselves.
Design semantic search for an Indian e-commerce catalogue that customers query in English, Hindi and Hinglish.
HardDesign
Run keyword and vector search over each product’s title, brand, category and attributes, and fuse the two lists. Keyword search catches brands and model numbers; a multilingual embedding model such as BGE-M3, built for over 100 languages, matches meaning across English and Hindi; romanised queries such as “joote” can first be transliterated to Devanagari with a model such as IndicXlit. Turn “under ₹1,000” into a price filter, re-rank with availability, and measure recall on labelled queries in each language before an A/B test.
Mention the latency budget: precompute product embeddings, use an approximate nearest-neighbour index and cache popular queries.
Design an assistant that answers business questions in plain English by writing SQL over a company’s database.
HardDesign
Give the model a curated view of the schema: retrieved table and column descriptions, sample values and a few verified question-to-SQL examples. Run its query through a read-only role limited to approved views, with a statement timeout and a row limit, and show the SQL beside the answer so analysts can check it; ask back when a question is ambiguous. Test on your own questions by execution accuracy: on the BIRD benchmark, ChatGPT reached 40.08% against 92.96% for humans.
Treat database contents as untrusted too: a product description can carry an injection, which is one more reason the role must be read-only.
Design a pipeline that extracts fields from 50,000 supplier invoices a month, including scanned PDFs and phone photos.
HardDesign
Read each page with OCR or a vision-capable model, then extract into a fixed schema with constrained decoding so the output always parses. Validate what can be computed: line items must add up to the total, tax must match its rate, and dates and IDs must have valid formats. Send failures and low-confidence fields to a reviewer, whose corrections become test data, process in idempotent batches, and track per-field accuracy and cost per invoice.
A strong follow-up answer: match each invoice to its purchase order and goods receipt before payment, as finance teams already do by hand.
Design a policy assistant for a bank’s branch staff
HardDesign
I’d scope it to circulars, products and procedures, with every answer citing the clause and its date. Ingestion parses circulars and policy PDFs, tables too, keeps effective dates and retires superseded versions; retrieval chunks by section, uses hybrid search so exact circular numbers still match, filters by date and department, then re-ranks. Answers quote and cite, decline when nothing covers it, and never advise on a specific customer. Around it go audit logs, role-based access, masking of personal data, upload checks for injection, and a compliance-reviewed golden set.
Practise giving this design answer in about ten minutes.
Design a job that summarises 1,000 news articles every night
HardDesign
One context window can’t hold a thousand articles, so I’d map, then reduce: group near-duplicates, write a summary per article or group, and then summarise those summaries by topic. Operationally it’s a batch job that retries failures, uses steps that can safely run twice, processes only new or changed articles and tracks the cost of each run. Before anything is published, the output gets spot-checked.
Startup rounds probe cost and failure handling, so spell out retries and cost per run.
How would you predict which prepaid customers will churn next month?
HardDesign
First I’d agree the label with the business, say no recharge in the 30 days after the prediction date, and build features like complaints, plan changes, tenure and usage trend only from data before that date. I’d split by time and make sure the model beats a simple baseline. The metric follows the action: if there’s capacity for 1,000 calls a week, what counts is precision among the top 1,000. It ships as a weekly score list, with monitoring, plus a holdout group to measure impact.
Interviewers listen for structure, not for the name of a model.
Design a credit-risk model to approve EMIs for a new product, with no repayment history and no bank data.
HardDesign
With no labels yet, start with a simple rules scorecard on signals the platform already has, such as account age, order and return history, payment behaviour and device stability, with small limits. Each approval becomes a label once repayments fall due, but only for approved users, so approve a small, controlled group more widely to measure that bias. When enough outcomes mature, train gradient-boosted trees with monotonic constraints, so predicted risk can’t fall as missed payments rise, calibrate the default probabilities, and set cut-offs by expected loss.
Expect a follow-up on fairness: compare approval and default rates across groups, and prefer features you can explain to a customer you decline.
Design how a grocery app’s search page decides which filters to show for each query.
HardDesign
First map the query to product categories with a classifier trained on search and purchase logs, because milk needs filters such as fat content and pack size, while atta needs brand and weight. The candidate filters are the attributes the catalogue holds for the matching products. Rank them by how often shoppers use each filter in that category, and by how well its values split the current results: a filter where every product shares one value is useless. Show the top few, and A/B test on search-to-cart conversion.
Vandic and colleagues ordered facets automatically from the specificity and dispersion of their values, and their method generally compared well with a list devised by domain experts.
Design visual search for a fashion marketplace, where a shopper uploads a photo and gets similar products.
HardDesign
Detect and crop the main item in the photo, then embed it with an image model fine-tuned on catalogue images with a metric-learning loss: positives are photos of the same product, and hard negatives are look-alikes. Pre-compute embeddings for every catalogue image, index them for approximate nearest-neighbour search, filter by category and stock, and re-rank by similarity, price and popularity. Offline, measure recall@K on labelled photo-to-product pairs; online, track clicks, add-to-cart and orders from visual search, and latency.
Pinterest reported that its visual search, built by a small team on widely available tools, improved user engagement in live experiments.
Design a question-answering assistant over a company’s internal documents.
HardDesign
Ingest each document with its metadata: owner, date and who may see it. Parse tables and scans carefully and chunk along headings. Retrieve with hybrid keyword and vector search, filtered by the user’s permissions, re-rank the top candidates, and have the model answer only from them, citing sources and saying when nothing covers the question. If live data is needed, such as ticket status, call tools with the user’s own access rights. Measure retrieval and faithfulness on a golden set, monitor feedback, latency and cost, and re-index as documents change.
Interviewers probe access control: filter by permission inside retrieval, never by asking the model to hide what a user mustn’t see.
Design a recommendation system for a large catalogue, such as a short-video feed or a food-delivery app.
HardDesign
Use two stages, as YouTube described. Candidate generation narrows the whole catalogue to a short list, with embedding retrieval, co-engagement and popularity; a ranking model then scores each candidate on predicted engagement, using rich user, item and context features. Train on implicit feedback such as watches, skips and orders, and handle cold start with content features and popular items by segment. Validate offline on a time-based split with recall@K and NDCG, A/B test on long-term outcomes, and retrain as tastes and the catalogue change.
Add a final re-ranking pass for diversity and freshness, so the feed doesn’t show ten near-identical items.
Design the system that chooses which ads to show a user.
HardDesign
Filter eligible ads by targeting, budget and policy, then predict each one’s click, and often conversion, probability with a model trained on impression logs, using user, ad and context features; Facebook found historical user and ad features mattered most. Rank by expected value, the bid times the predicted probability, inside the auction, which is why predictions must be calibrated, not just well ordered. Give new ads priors and some exploration, measure log loss and calibration offline, then revenue, click-through and advertiser returns in A/B tests.
Facebook’s ads team combined boosted decision trees with logistic regression and beat either alone by over 3%.
Design an LLM assistant for a customer in a regulated industry, such as banking or healthcare. What guardrails and governance would you build in?
HardDesign
Start from risk: decide what the assistant may do, keep people approving anything that affects a customer, and mask personal data before it reaches the model. Guardrails sit around the model: input checks for injection and personal data, answers grounded in approved sources with citations, refusals outside scope, and least-privilege tools. Governance covers the lifecycle: versioned prompts and models with sign-off, evaluation sets reviewed by compliance, audit logs of every prompt, response and tool call, and incident reviews, as NIST’s AI Risk Management Framework sets out.
Map your controls to the OWASP Top 10 for LLM Applications, from prompt injection and sensitive information disclosure to excessive agency.
Design a feed that ranks places for a user who has just arrived in a new city. How would you featurise location?
HardDesign
Generate candidates near the user and open now, using a spatial index such as geohash or Uber’s H3 hexagonal cells. Featurise location relative to the user: distance and travel time, popularity in that cell, ratings from locals and from visitors, opening hours against the time of day, and the place’s category and price. With no history in this city, transfer tastes from home, such as cuisines and price levels the user chose, and lean on visitor popularity; rank with a model trained on saves, clicks and visits.
Normalise popularity by area: raw counts favour busy districts, so compare a place with others in the same cell.
Design a video super-resolution model that runs on a phone.
HardDesign
Start from the budget: frames per second at the target resolution, memory, power and heat. Do most of the work at low resolution and upscale only at the end with a sub-pixel convolution, as ESPCN did to super-resolve 1080p video in real time on a single GPU, and reuse features from previous frames to stay consistent. Train on pairs made by degrading high-resolution video realistically, with blur, noise and compression. Measure PSNR, temporal consistency and on-device latency, then quantise, for example to 8-bit with Core ML Tools.
Watch for flicker: per-frame scores such as PSNR can look fine while the video shimmers, so check temporal consistency too.