Design a Fraud Detection System: Real-Time ML System Design

ML system design for real-time payment fraud detection: imbalanced, delayed labels, streaming velocity features, rules plus models and review queues.

Advanced 4 min read · Updated

The question: design a system that decides, in real time, whether a card payment is fraudulent before it's authorised. Missing fraud costs money and trust; blocking good customers costs revenue and goodwill. Labels arrive weeks late, fraudsters adapt, and positives are rare. It's a favourite ML design question at payments companies, banks and marketplaces because it tests all of that at once.

1. Clarify requirements

QuestionAnswer
Decision?Approve, decline, or step-up (ask for 3-D Secure / an OTP), plus send to manual review for some
Scale?20K transactions per second at peak, 500M per day
Latency?Decision in under 100 ms (it sits inside the card authorisation path)
Fraud rate?About 0.1% of transactions; fraud amount matters more than count
Labels?Chargebacks (arrive 30-90 days later), confirmed reports, manual review outcomes
Costs?A missed fraud loses the amount plus fees; a false decline loses the margin and may lose the customer

2. Frame it as an ML problem

Binary classification: p(fraud | transaction, history). The decision is a cost-based threshold, not 0.5: decline when the expected loss of approving exceeds the expected loss of declining. Different thresholds for amount bands and merchant types are common.

expected loss if approved = p(fraud) × amount
expected loss if declined = (1 − p(fraud)) × margin_lost × churn_factor
decline when p × amount > (1 − p) × margin × churn
→ a $2,000 laptop needs a much lower p to decline than a $5 coffee

3. Data and labels

  • Rows: every scored transaction with the features used at decision time (logged, to avoid skew).
  • Label delay: chargebacks take weeks, so training data is 2-3 months old, and recent labels are incomplete. Train on matured windows; use review outcomes and confirmed reports as faster partial labels.
  • Selection bias: declined transactions never get a chargeback, so you can't tell if they were fraud. Let a tiny random sample of would-be declines through (or step them up) to learn; see feedback loops.
  • Imbalance: 0.1% positives; weight by amount and use PR-AUC. See training data.

4. Architecture

uncertainAuthorisation requestFeature servicevelocity · historyOnline storecard · device · merchantRules engineblocklists · limitsFraud modelGBDT · < 20 msDecision enginecost thresholdsReview queueApprove / step-up / decline
The decision path: rules catch known patterns, the model scores everything else with fresh velocity features, and a decision engine applies thresholds. Uncertain cases go to review, whose outcomes become labels.

5. Features

GroupExamplesComputed by
VelocityTransactions per card in last 1 min / 1 h / 24 h; distinct merchants in 1 h; amount sum in 24 hStream processor, per-key windows
Device and networkNew device for this card? IP country vs card country, proxy/VPN flagRequest + device history
Behavioural deviationAmount vs card's typical amount; unusual hour; distance from last transaction / time elapsed (impossible travel)Stream + profile store
MerchantMerchant category, merchant's historical fraud rate (smoothed, lagged)Batch daily
GraphCard shares a device, email or address with known fraudGraph job, batch + incremental

Velocity features must be fresh to the second: a fraudster testing a stolen card fires many small transactions quickly. They come from a stream processor writing to a low-latency store. See feature engineering and feature stores.

6. Models

  • Rules first: sanctions lists, known-bad devices and hard limits. Fast to change when an attack starts; analysts own them.
  • Gradient-boosted trees on tabular features: accurate, fast on CPU, and they give feature contributions for explanations to reviewers.
  • Optional deep or graph models for sequences of transactions and fraud rings, often as features into the tree model.
  • Anomaly detection (unsupervised) to flag new patterns nobody has labelled yet.

7. Latency and reliability

Budget (100 ms total, inside authorisation):
  feature fetch (parallel)  15 ms   online store p99
  rules                      5 ms
  model                     15 ms   trees on CPU
  decision + logging         5 ms   logging async
  network + headroom        60 ms
Fallback: if the model or features time out → rules-only decision with a
conservative threshold for high amounts; never block all traffic on an outage

The fraud service is in the payment path, so it gets the same treatment as any critical dependency: timeouts, a circuit breaker and a fallback.

8. Human review loop

  • Mid-score transactions go to analysts (or are held briefly); queue size is set by reviewer capacity.
  • The queue is ordered by expected loss (p × amount), not by arrival time.
  • Reviewer decisions are fast labels and feed retraining; their disagreement rates are tracked.
  • Customers' disputes and "this was me" confirmations are labels too.

9. Evaluation

OfflineOnline
PR-AUC; recall at a fixed false-positive rateFraud loss in basis points of volume
Dollar-weighted recall (share of fraud amount caught)False decline rate and approval rate
Performance by slice: merchant type, country, new cardsManual review rate and reviewer precision

Online A/B tests are delicate: a control arm with a weaker model loses real money. Use small allocations, shadow scoring of the challenger, and backtests on matured data. See ML evaluation.

10. Adapting to adversaries

  • Monitor score distributions and decline rates per merchant and BIN range hourly; a sudden shift often signals a new attack.
  • Retrain regularly on matured labels, and let analysts push rules within minutes in between; see continual learning.
  • Keep some features secret and avoid exposing exact decline reasons to the requester.

Where it’s used

Card payments

Scoring inside the authorisation path with velocity features and cost-based thresholds.

Marketplaces

Account takeover, fake listings and promo abuse use the same rules-plus-model-plus-review pattern.

Banking

Transfer fraud and money-mule detection, often adding graph features.

In an interview

  • Set thresholds from the cost of each error, varying with the amount.
  • Explain delayed labels and selection bias from declines, and how you get labels anyway.
  • Design second-fresh velocity features from a stream into an online store.
  • Combine rules, a model and human review, with a safe fallback inside the latency budget.

Frequently asked questions

How do you design a real-time fraud detection system?

Compute fresh velocity and behaviour features from a stream into a low-latency store, score each transaction with rules and a model within the authorisation latency budget, decide with cost-based thresholds, and send uncertain cases to human review whose outcomes become labels.

Why are fraud labels hard to get?

Chargebacks arrive weeks after the transaction, and declined transactions never produce a chargeback, so the model cannot learn from its own blocks without some exploration or review sampling.

Further reading