System Design Interview: Real-Time Payment Fraud Detection
5 views
"Design a system that flags fraudulent card transactions in real time" appears in interviews at fintech companies, marketplaces and banks. It combines low-latency serving, streaming features and machine learning in one design.
1. Requirements
Functional: score every transaction before it is approved, return allow, review or block, and let analysts review flagged cases. Non-functional: decision within about 100 ms at p99, tens of thousands of transactions per second at peak, high availability (a fraud system outage must not stop all payments), and an auditable record of every decision.
2. High-level flow
Payment service -> fraud scoring API -> feature lookup + rules engine + ML model -> decision -> response. Every request and decision is also written to an event stream for analytics, training and audits.
3. Features
Good fraud signals compare a transaction with recent behavior:
- Velocity: number of transactions on this card in the last 1 minute, 1 hour and 24 hours.
- Amount compared with the customer's typical spend.
- New device, new shipping address, or a location far from the last purchase.
- Merchant risk score.
Velocity features are computed by a stream processor (Flink or Kafka Streams) with windowed aggregations and written to a low-latency feature store such as Redis or a key-value database. The scoring path only reads precomputed values, which keeps latency predictable.
4. Rules plus models
Rules catch known patterns and can be changed quickly by analysts ("block if more than five declines in ten minutes"). A gradient-boosted model or neural network catches subtler patterns. Combine both: hard rules can block immediately, while the model score decides between allow and manual review based on thresholds tuned to business cost.
5. Failure handling
If the feature store or model times out, fall back to a simpler rule set rather than failing open or blocking everything. Set strict timeouts and use circuit breakers. Mention that the fallback policy is a business decision about acceptable risk.
6. Feedback loop
Chargebacks arrive days or weeks later. Join them back to the original decisions to label training data. Watch out for label delay and for selection bias: transactions you blocked never get a true label, so keep a small random holdout or use analyst reviews.
7. Analyst tooling
Flagged cases go to a review queue with the features and rule hits that triggered them, which helps analysts decide quickly and also explains decisions for compliance.
8. Monitoring
Track decision latency, approval rate, fraud rate, false positives and model drift. A sudden drop in approvals is often a bug, not a fraud wave.
Wrap up with the trade-offs: precomputed features for latency, rules for agility, models for coverage, and a safe fallback. During live system design rounds, Linkjob AI (https://linkjob.ai) offers real-time help in technical interviews, reminding you of pieces like the label-delay problem when the discussion moves fast.