Design a Fraud Detection System
hard 50 minJudge 10,000 payments a second, each within 100 ms, when only one in a thousand is fraud and the truth arrives weeks later.
Video lesson · Chapter 1 of 5
A fast decision can still be a terrible decision
A payment is judged in 100 ms
1:30Reel coming soon
Theory
Read or listen first. About 2 min.
What it is
A fraud detection system looks at each payment while it is being made and answers approve, challenge or decline. It combines fixed rules, a model that gives a probability, and people who look at a few doubtful cases.
It is a service like Stripe Radar or Sift. This is an exercise about protecting customers and merchants. It does not describe how any company builds theirs, and it contains no way around such a system.
Why it exists
Fraud costs the merchant the goods, the money and a dispute fee. Stopping everything suspicious also costs: honest people are turned away and do not come back. The job is to choose between two kinds of harm, thousands of times a second.
The other side watches and changes. A system that does not learn gets worse by itself, and its labels arrive late, because a customer first has to notice a strange payment.
A short history
2002
The SMOTE paper appears in the Journal of Artificial Intelligence Research: making more examples of a rare class.
March 2016
The XGBoost paper describes fast boosted decision trees, still a strong first choice for tables of features.
May 2017
The SHAP paper gives one way to say how much each feature added to one prediction.
14 September 2019
The EU technical standards on strong customer authentication apply, with an exemption for payments that a real-time risk analysis finds low risk.
Mid-2022
Stripe writes that Radar moved from an ensemble of XGBoost and a neural network to a neural network alone.
Words to know
- Feature
- One fact given to the model, such as payments with this card in 10 minutes.
- Velocity
- How often something happens within a window of time.
- False positive
- An honest payment that was stopped.
- Recall and precision
- Share of fraud we stop, and share of what we stop that is fraud.
- Chargeback
- The cardholder disputes a payment and the bank takes the money back.
- Challenge (step-up)
- Extra proof from the payer, such as approval in the bank's app.
- Drift
- The world changes, so yesterday's model fits less well.
- Shadow
- A new model scores real payments, but its answers are only recorded.
Solve it like an interview
New to it? Start with Approach. Revising? Go straight to the mock.
- 1ApproachWhat this question tests, where it gets hard, and how to spend the time.
- 2ScopeAsk what changes the design, then commit to a short list.
- 3NumbersWork out a number when the answer changes what you build.
- 4API and dataThe contract first, then the data that serves it.
- 5DesignStart with the smallest system that works. Change it only when something breaks.
- 6Deep divesCompare the options before you open them, then say which you would pick.
- 7Explain your choicesAnswer first. Then compare your reasoning.
- 8By levelThe same question is judged differently for mid, senior and staff.
- 9MockAnswer against the clock, then score yourself.
How it works
Step through the idea, or press Play.
Gather. Five feature rows and fresh counters about card, account, device, address and merchant
Understand it
Throwing away every odd coin would also throw away good ones.
Scope
What are we building?
Fraud checks for a payment company: 288 million card payments a day, judged while the payer waits. The payment itself, with its ledger, belongs to the digital wallet. Card numbers never reach us: we get a token from the payment service.
Score
A probability for each payment, within 100 ms.
Decide
Approve, challenge or decline, with recorded reasons.
Review
A desk for the few cases worth a person's time.
Learn
Labels, training, shadow, rollout, every day.
Similar systems
| System | Kind |
|---|---|
| Stripe Radar | Built into a payment platform |
| PayPal | Payment company with its own checks |
| Sift | Risk service for many kinds of abuse |
| Feedzai | Risk platform for banks |
| Riskified | Risk service for shops |
| Amazon Fraud Detector | Managed; closed to new customers since November 7, 2025 |
The finished system
Where the design ends up
This is the last version. The Design tab starts with one service and one database.
Deciding and learning
When there is no answer in time
Where to read what
| Question | Place |
|---|---|
| How do I open this interview? | Approach |
| What is in and out? | Scope |
| How big is it? | Numbers |
| How is it called? | API and data |
| Velocity, thresholds, labels? | Deep dives |
| Can I defend it? | Explain and By level |
| Can I practise it? | Mock |
Summary
The whole topic in one minute.
The scoring service reads five feature rows, adds to the newest counters, runs rules and a tree model in its own memory, and turns a calibrated probability and the amount into approve, challenge or decline. Each decision is stored with the features it used.
Labels come back from disputes, customers and analysts, over months. Training uses the logged features, corrects for what we declined, and a new model first runs in shadow. If the feature store or model fails, small rules in the payment service decide by amount.
- Start from the base rate. At 1 in 1,000, a 1% false alarm rate means ten false alarms for each fraud.
- Approve, challenge, decline: the limits follow from costs, so they depend on the amount.
- Counters for the last minutes are updated in the request. Longer windows may lag.
- Store the features with the decision. Training then sees exactly what scoring saw.
- Declined payments have no labels. Correct for it on purpose.
- The caller owns the deadline and the fallback.
Sources
- Stripe: how we built it, Stripe Radar
- Stripe: a primer on machine learning for fraud protection
- Stripe documentation: risk evaluation
- Stripe documentation: how disputes work
- Amazon Fraud Detector user guide
- XGBoost (arXiv)
- SHAP (arXiv)
- SMOTE (arXiv)
- EU regulation 2018/389: strong customer authentication
- GDPR, Article 22
- Apache Flink: fraud detection case study