Step 1 Understand it
Why interviewers ask this. It tests real-time ML: low- features, data, thresholds based on costs, labels that arrive late, and .
New words in this topic (tap one to see what it means)
Watch it happen
Read the animation as text
- A £950 card payment must be approved or stopped in milliseconds. It goes to a scoring service.
- Real-time features are fetched from a feature store, kept fresh by a stream processor: 6 payments in the last 10 minutes, 4,000 km from the usual place, a new device.
- Hand-written rules and an ML model (often gradient-boosted trees) both look at the features. The model scores this one 0.91.
- Thresholds turn the score into a decision, tuned by what each mistake costs: above 0.9 block; 0.6–0.9 send to an analyst; below that approve. This one is blocked and queued for review.
- Every decision and its features are logged. Weeks later, chargebacks arrive as the true labels; they are joined to the log to retrain the model, and drift is watched.
Requirements
Functional
- Score every before it's approved.
- Allow, block, or ask for extra verification (such as a ), or send to manual review.
- Learn from confirmed fraud.
Non-functional
- A decision in under about 100 , with very high (fail safely).
- Very imbalanced data: fraud is far below 1%.
- Explainable decisions for regulators and customers.
Estimates
- About 2,000 transactions per second at peak, each needing features such as 'number of transactions on this card in the last 10 minutes'.
API
POST /score {transaction} → {risk_score, decision, reasons}
Data model
- aggregates per card, merchant and device (counts and sums over time windows) in a low-latency .
- Labels arrive later, from and analyst reviews.
Start simple, then scale
- Version 1: hand-written rules (for example, block payments over £5,000 made abroad).
- Version 2: a model trained offline and scored in a service.
- Version 3: streaming features (like transaction counts in the last 10 minutes) in a feature store.
- Version 4: rules plus model plus a review , thresholds tuned by cost, drift monitoring and regular retraining.
Picture it
flowchart LR
TX["Card transaction"] --> SC["Scoring service<br/>rules + model"]
FS[("Feature store<br/>live counts")] --> SC
SC --> DEC{"Risk?"}
DEC -->|"low"| ALLOW["Allow"]
DEC -->|"medium"| STEP["Ask for a one-time code"]
DEC -->|"high"| BLOCK["Block or review"]
STREAM[["Transaction stream"]] --> AGG["Stream processor"] --> FS
CB["Fraud labels<br/>(weeks later)"] --> TRAIN["Retraining"] --> SCThe design, step by step
- Transaction → scoring service: fetch real-time features (how many transactions in the last 10 minutes, distance from usual location, device) and historical features → rules engine plus an ML model (often ) → decision using thresholds.
- A streaming pipeline ( plus a stream processor) keeps the windowed counts and sums up to date.
- Every decision and its features are ; fraud labels arrive later (chargebacks) and are joined for retraining.
- A case-management tool for fraud analysts.
Deep dives
- Class imbalance: choose the –recall trade-off from the cost of fraud versus the cost of blocking good customers.
- Delayed, noisy labels, and fraudsters changing tactics (drift): monitor and retrain often.
- If the model service is down or slow, fall back to rules only.
- correct features, so no future information leaks into training.
Common mistakes
- Using accuracy as the .
- Features calculated with information from the future.
- No when the model service fails.
Step 2 Go further (free, optional)
Optional. The notes above are written to be enough on their own. These free resources give a second explanation and extra practice.
- Read
-
Read
CS329S: Machine Learning Systems Design (lecture notes)
Chip Huyen, Stanford · free
- Code
Step 3 Practise
Try each exercise yourself first: on paper, out loud or in code. Then open the answer and compare it with yours.
-
ExplainSay it in plain words in under a minute, with no notes.
Explain the real-time scoring path and the learning loop.
Show answer
Real-time scoring path (every transaction, in under about 100 ms, before it is approved):
1. The payment arrives at the scoring service: card, amount, merchant, device, location.
2. It fetches features from a low-latency feature store: real-time ones kept up to date by a streaming pipeline ("transactions on this card in the last 10 minutes", "amount spent today", "distance from the usual location") and historical ones ("card age", "typical spend at this merchant type").
3. A rules engine runs (hard rules: blocked cards, sanctions lists, impossible travel), and an ML model (often gradient-boosted trees) gives a risk score.
4. Thresholds turn the score into a decision: allow, ask for extra verification (a one-time code), send to manual review, or block. The decision comes with reasons.
5. If the model is down or slow, the service falls back to rules alone, so payments don't stop.Learning loop (days to weeks):
1. Every decision is logged with the exact features used.
2. Labels arrive later: chargebacks, customer reports, analyst verdicts.
3. They are joined to the logged features (point-in-time correct), and the model is retrained.
4. The new model is evaluated against the old one, released carefully (, then canary), and monitored for drift, because fraudsters change tactics. -
DrawSketch the diagram (or class diagram) from memory.
Draw transaction → scoring service ↔ feature store, the streaming aggregates, and the label feedback loop.
Show answer
The scoring service must answer within the payment's time budget, so it only reads precomputed features; the streaming pipeline keeps the windowed counts fresh. Labels arrive weeks later and flow back into training through the decision log.
textREAL TIME Payment ── transaction ──► Scoring service ──► decision + reasons │ ▲ (allow / verify / │ │ review / block) features│ │ ▼ │ Feature store (low latency) ▲ Transaction events ──► Kafka ──► Stream processor (counts and sums per card, merchant, device over 10 min, 1 h, 24 h windows) Scoring service = rules engine + ML model (+ rules-only fallback) LEARNING LOOP Scoring service ── decision + features used ──► Decision log Chargebacks, customer reports ──┐ Analyst verdicts (case tool) ───┴──► Labels (arrive late) Decision log + labels ── point-in-time join ──► Training ──► evaluation ──► Model registry ──► shadow → canary → live Monitoring: score drift, fraud caught, false positives -
ApplyUse it in a real design question and say exactly where it fits.
On a public credit-card fraud dataset, train logistic regression and report precision and recall at three different thresholds.
Show answer
The usual public dataset is Kaggle's "Credit Card Fraud Detection": 284,807 card transactions, of which 492 (0.17%) are fraud. This answer uses a synthetic stand-in with the same kind of imbalance (0.2% fraud, 100,000 rows), so it runs anywhere; to use the real file, load creditcard.csv and use its column as y.
Logistic regression is trained with plain gradient descent in NumPy. Fraud examples are weighted about 500 times more, otherwise the model learns that "never fraud" is 99.8% accurate. The test set has 48 frauds in 30,000 transactions:
• threshold 0.5: flags 4,904 transactions, catches 40 of 48 frauds. Recall 0.83, but precision 0.01: 99 in 100 alerts are false.
• threshold 0.9: flags 558, catches 22. Recall 0.46, precision 0.04.
• threshold 0.99: flags 21, catches 7. Recall 0.15, precision 0.33.The threshold is a business decision, not a modelling one: each missed fraud costs its amount; each false alarm costs an annoyed customer or an analyst's time. Real systems use several thresholds: auto-block only the very top, send a one-time code for the middle band, allow the rest. And accuracy is useless here: a model that never flags anything scores 99.8%.
pythonimport numpy as np rng = np.random.default_rng(0) n, fraud_rate = 100_000, 0.002 # about as rare as in the real dataset y = (rng.random(n) < fraud_rate).astype(float) X = rng.normal(size=(n, 5)) + y[:, None] * np.array([1.5, 1.0, 0.8, 0.0, 0.5]) # overlapping classes split = int(0.7 * n) # train on the first 70%, test on the rest Xtr, ytr, Xte, yte = X[:split], y[:split], X[split:], y[split:] w, b = np.zeros(5), 0.0 pos_weight = (1 - ytr.mean()) / ytr.mean() # each fraud counts ~500 times sample_w = np.where(ytr == 1, pos_weight, 1.0) for _ in range(500): # logistic regression, gradient descent p = 1 / (1 + np.exp(-(Xtr @ w + b))) grad = sample_w * (p - ytr) w -= 0.5 * (Xtr.T @ grad) / sample_w.sum() b -= 0.5 * grad.sum() / sample_w.sum() scores = 1 / (1 + np.exp(-(Xte @ w + b))) for threshold in (0.5, 0.9, 0.99): flagged = scores >= threshold caught = int(np.sum(flagged & (yte == 1))) precision = caught / max(int(flagged.sum()), 1) recall = caught / yte.sum() print(f"threshold {threshold}: flagged {int(flagged.sum())}, caught {caught} of {int(yte.sum())}, " f"precision {precision:.2f}, recall {recall:.2f}") # threshold 0.5: flagged 4904, caught 40 of 48, precision 0.01, recall 0.83 # threshold 0.9: flagged 558, caught 22 of 48, precision 0.04, recall 0.46 # threshold 0.99: flagged 21, caught 7 of 48, precision 0.33, recall 0.15 -
Trade-offsSay what it costs, when not to use it, and the alternative.
Rules only, ML model only, or both: when does each win?
Show answer
Rules only wins when:
• you are starting out and have no labelled fraud to learn from;
• the rule is a hard requirement: sanctions lists, blocked cards, legal limits;
• a new attack appears today: a rule can be written and deployed in an hour, while a model needs new labels and retraining;
• every decision must be explained in one sentence.
But rules are brittle, rack up false positives, and fraudsters learn them quickly.An ML model only wins when:
• you have plenty of labelled history and patterns too subtle for hand-written rules (combinations of amount, time, device, merchant, velocity);
• you need a better trade-off between catching fraud and annoying customers than rules can give.
But a model alone is slow to react to brand-new attacks, harder to explain, and a if the model service goes down.Both (the usual production answer): rules as (hard blocks, known-bad lists, emergency fixes for a fresh attack), the model's score for everything nuanced, thresholds that route to allow, verify, review or block, and rules-only as the fallback when the model is unavailable. Analysts' verdicts feed both: new rules now, better models later.
Step 4 Interview-ready, then prove it
Your interview answer
About 20 to 40 seconds, said out loud. Practise it until it sounds like you, not like notes.
Each transaction hits a low-latency scoring service that pulls real-time features from a feature store kept fresh by a streaming pipeline, runs rules plus a gradient-boosted model, and returns allow, verify or block within about 100 milliseconds. Thresholds come from the business cost of fraud versus false declines. Decisions are logged, chargeback labels are joined later, and the model is monitored for drift and retrained regularly.
Follow-up questions
Why not just maximise accuracy?
With 0.1% fraud, a model that always says 'not fraud' is 99.9% accurate and useless. Use precision, recall and cost-weighted metrics.
What if the model service is slow?
Time out and fall back to rules, with a safe default for each risk level, so payments never stall.
Tick each check when you can do it without notes
A topic is finished when you pass all four checks, not when you finish a video. Be strict: if you needed your notes, it is not ticked yet.
- Explain Say it in plain words in under a minute, with no notes.
- Draw Sketch the diagram (or class diagram) from memory.
- Apply Use it in a real design question and say exactly where it fits.
- Trade-offs Say what it costs, when not to use it, and the alternative.
0 of 4 checks ticked.
Saved in this browser. Back it up or move it to another device.