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
- Clarify requirements and scale: confirm scoring happens inline at payment authorisation with a hard SLA (service-level agreement) under p99 (99th-percentile) latency, extreme imbalance (often 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 transactions per day ( QPS average, QPS peak). If a missed fraud costs and a false decline costs , applying the cost-minimising threshold formula covered in `decision-threshold-with-costs`, , gives (). Above ( of traffic /day) you hard-block; between and you trigger lightweight step-up auth, and route high-value borderline cases ( of volume alerts/day) to analysts, requiring analysts at 120 reviews per shift.
- Define the ML objective and metrics: predict calibrated fraud probability 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. ), 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.
- 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.
- 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.
- 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.
- Architect real-time serving within 100 ms: split the p99 budget into ingress and rule pre-checks, for parallel low-latency feature lookups from an in-memory streaming feature store (updating velocity counters asynchronously on every event via Kafka/Flink), for model inference (with graceful fallback to rules if ML times out), for cost-based tiering (block vs 3DS step-up vs review queue) and 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.
- 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 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.
- 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
- Treating recent transactions with no chargeback yet as negative labels, which trains the model to predict recent transactions as safe simply because disputes take weeks to arrive.
- Computing velocity aggregations (such as transactions in the last hour) without strict point-in-time boundaries, leaking future fraud bursts into training examples.
- Sending too many borderline alerts to a fixed-size analyst team, causing queue backlogs where fraudulent payouts settle before an analyst ever inspects them.
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?