AlgoViz

Design a Fraud Detection System

hard 50 min

Judge 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

0:00 / 4:57

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

  1. 2002

    The SMOTE paper appears in the Journal of Artificial Intelligence Research: making more examples of a rare class.

  2. March 2016

    The XGBoost paper describes fast boosted decision trees, still a strong first choice for tables of features.

  3. May 2017

    The SHAP paper gives one way to say how much each feature added to one prediction.

  4. 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.

  5. 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.

  1. 1ApproachWhat this question tests, where it gets hard, and how to spend the time.
  2. 2ScopeAsk what changes the design, then commit to a short list.
  3. 3NumbersWork out a number when the answer changes what you build.
  4. 4API and dataThe contract first, then the data that serves it.
  5. 5DesignStart with the smallest system that works. Change it only when something breaks.
  6. 6Deep divesCompare the options before you open them, then say which you would pick.
  7. 7Explain your choicesAnswer first. Then compare your reasoning.
  8. 8By levelThe same question is judged differently for mid, senior and staff.
  9. 9MockAnswer against the clock, then score yourself.

How it works

Step through the idea, or press Play.

Step 1 of 3

Gather. Five feature rows and fresh counters about card, account, device, address and merchant

Understand it

The coin sorter at the market
three wait

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

SystemKind
Stripe RadarBuilt into a payment platform
PayPalPayment company with its own checks
SiftRisk service for many kinds of abuse
FeedzaiRisk platform for banks
RiskifiedRisk service for shops
Amazon Fraud DetectorManaged; 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

The payment service asks the scoring service, which holds rules and a model in memory and reads the feature store. Decisions go to Kafka. A stream job updates long windows in the feature store, all decisions are kept in object storage, and doubtful ones go to the case service, where analysts work. Training reads object storage.
Blue is the payment waiting, orange is work after the answer, pink is learning. Dashed arrows delay nobody.

When there is no answer in time

The payment service asks the scoring service with a deadline. When there is no answer, small rules inside the payment service decide by amount.
The deadline and the fallback live with the caller, so they work when we do not.

Where to read what

QuestionPlace
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
Ideas with their own pages: stream processing, log-based queues, circuit breaker, fallbacks, idempotency.

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