Design a fraud detector

Real-time features, feature stores, extreme imbalance, precision/recall cost asymmetry, feedback loops from analyst labels. Fintech-heavy India loves this one.

About 23 min read3-question knowledge check

The mental model

A fraud detector is airport security, not a courtroom. It does not have to prove guilt beyond doubt in real time — it has to decide, in under 100 ms, whether to wave a transaction through, block it, or send it for a closer look. The whole design is shaped by two brutal facts: the classes are wildly imbalanced (roughly 1 fraud per 580 legitimate transactions) and the two errors cost wildly different amounts (a missed fraud can cost 30x a false alarm). So accuracy is meaningless — a model that approves everything is 99.8% accurate and catches zero fraud — and the entire problem is picking an operating point on the precision/recall curve that matches the business cost, not maximising a symmetric metric.

The second shaping force is time. Fraud must be scored before the transaction settles, so features have to be computed in real time from a stream — "how many transactions on this card in the last 60 seconds" is a feature you cannot precompute. And the labels arrive late and asymmetrically: a chargeback confirming fraud can land 30–90 days after the transaction. So you are training on stale, delayed, partially-missing labels and serving under a hard latency budget. That gap between fast decisions and slow truth is the defining engineering challenge.

The insight interviewers reward: fraud is adversarial and non-stationary. Unlike churn or recommendations, an intelligent opponent is actively probing your model and adapting to evade it, so today's patterns are stale tomorrow (concept drift you cause by being good). A design that treats fraud as a static classification problem has missed the point — the system is a loop: model → block → attacker adapts → analyst labels → retrain, running forever.

The full lesson continues with 15 more sections
  • Deep dive — a full worked design
  • Internal architecture
  • Real-world use cases
  • Best practices
  • Common mistakes
  • Performance
  • Security
  • Production troubleshooting
  • Advantages & disadvantages
  • Alternatives
  • Interview expectations
  • Interview questions
  • Facts to remember
  • Cheat sheet
  • Quick revision