How would you design a real-time payment fraud detection system?

ML system design, Case studies
Level L4 Advanced. Length Long. Nature Th+Mat Both.

What's being asked

Whether you can design an ultra-low-latency scoring system under extreme class imbalance, weeks-long label delay, cost-based thresholding and strict analyst queue limits.

Key idea

Payment fraud must be scored inline during card authorisation in under 100 ms, where blocking a genuine customer (false decline) costs lost sales and churn, while missing fraud brings chargeback losses. Production systems combine deterministic policy rules with a calibrated ML model using point-in-time velocity and entity-graph features, set action tiers via expected-cost thresholding, handle weeks-delayed chargeback labels via maturity windows, and size human review to analyst throughput.

Steps

  1. Clarify requirements and scale: confirm scoring happens inline at payment authorisation with a hard SLA (service-level agreement) under 100 ms p99 (99th-percentile) latency, extreme imbalance (often 0.1% fraud or lower) and actions (approve, step-up verification via 3DS (3-D Secure) or OTP (one-time password), hard block, or post-authorisation manual review). Back-of-envelope operational estimate: suppose a gateway processes 2×107 transactions per day (≈231 QPS average, ∼1,000 QPS peak). If a missed fraud costs CFN=USD 200 and a false decline costs CFP=USD 10, applying the cost-minimising threshold formula covered in `decision-threshold-with-costs`, t∗=CFPCFP+CFN, gives t∗=1010+200=121≈0.0476 (4.8%). Above p≥0.80 (0.1% of traffic =20,000/day) you hard-block; between t∗≈0.048 and 0.80 you trigger lightweight step-up auth, and route high-value borderline cases (0.03% of volume =2×107×0.0003=6,000 alerts/day) to analysts, requiring 6,000/120=50 analysts at 120 reviews per shift.
  2. Define the ML objective and metrics: predict calibrated fraud probability p=P(fraud∣x) trained with weighted binary cross-entropy (or dollar-weighted loss so high-ticket frauds matter more). Offline, report PR-AUC (precision–recall area under the curve) and recall at fixed low FPR (false-positive rate, e.g. ≤0.1%), plus transaction-value-weighted capture rate and ECE (expected calibration error). Online, measure chargeback rate (dollar and count basis), false-decline rate, step-up conversion drop-off and authorisation p99 latency.
  3. Handle delayed and incomplete labels: chargebacks often arrive weeks to a few months after a transaction, and declined transactions never produce chargebacks (selection/censoring bias). Never label yesterday's un-disputed transactions as legitimate; wait for a maturity window (e.g. 30–60 days) for clean ground truth, or pair mature labels with fast proxy labels (analyst escalations, early issuer fraud alerts, customer disputes) and exploration/holdout slices (letting a tiny controlled low-risk slice pass with guardrails) to observe counterfactual outcomes.
  4. Engineer point-in-time velocity and graph features: compute four feature groups: (1) streaming velocity features over sliding windows (5 minutes, 1 hour, 24 hours, 7 days): transaction count and total spend per card, device fingerprint, IP (Internet Protocol) address, email and merchant; (2) transaction and mismatch signals: amount vs user/merchant baseline, billing-vs-IP country distance, BIN (bank identification number) country, AVS/CVV (address verification / card verification value) result and time since account creation; (3) network/graph features: how many distinct cards share one device or shipping address, or whether an entity links to previously charged-back nodes; (4) merchant and global network history. Every historical and velocity aggregate must be computed strictly point-in-time during training to prevent future leakage.
  5. Design rules plus ML models: start with an interpretable rule engine (sanctions/velocity caps, known stolen cards, compliance blocks) and a calibrated logistic regression baseline. Upgrade to GBDT (gradient-boosted decision trees) or a multi-branch DNN (deep neural network) over tabular and embedded categorical features (for instance, Stripe Radar moved from a hybrid XGBoost+DNN setup, where XGBoost is extreme gradient boosting, to a pure multi-branch DNN to simplify continuous retraining and cut training time), paired with post-hoc calibration (isotonic or Platt scaling) and human-readable reason codes so merchants and analysts understand why a payment was flagged.
  6. Architect real-time serving within 100 ms: split the 100 ms p99 budget into 10 ms ingress and rule pre-checks, 35 ms for parallel low-latency feature lookups from an in-memory streaming feature store (updating velocity counters asynchronously on every event via Kafka/Flink), 30 ms for model inference (with graceful fallback to rules if ML times out), 10 ms for cost-based tiering (block vs 3DS step-up vs review queue) and 15 ms network/logging overhead. Interviewers will probe feature-store freshness vs p99 tail latency and how you keep the review queue strictly bounded to analyst capacity.
  7. Evaluate and launch safely: validate offline on strict chronological splits shifted by the label-maturity gap, sliced by card network, merchant category, transaction amount and geography. Run shadow scoring in production to catch training–serving skew in streaming velocity counters, then canary on 1–5% of low-risk volume while watching false-decline rates, step-up abandonment and latency before rolling out via merchant- or traffic-level A/B tests.
  8. Monitor and iterate against adversarial drift: track PSI (population stability index) on predicted scores and key velocity features, sudden surges in step-up failures or merchant decline complaints, and emerging fraud rings via daily analyst feedback. Retrain frequently using a blend of mature chargebacks and high-confidence analyst/early-alert labels, and be ready to discuss interviewer trade-offs: false declines vs fraud loss, threshold tuning per merchant margin, and black-box DNN accuracy vs rule/SHAP (SHapley Additive exPlanations) explainability.

Common mistakes

How long your answer should be

8–10 minutes; cover the 100 ms serving path, cost-threshold queue math, velocity stores and delayed chargeback labels.

Read this

Previous in ML system design: How would you design a search ranking system for a large e-commerce site?
Next in ML system design: How would you design a retrieval-augmented question answering system over a company's internal documents? As part of the prompt budget, if the model has an 8,000-token context window, 1,000 tokens are reserved for system instructions and the user question, and 500 tokens are reserved for the answer, how many 400-token chunks fit?