Prompt
How do I score transaction risk in real time?
Latest observation
To score transaction risk in real time, you typically combine fast rules, behavioral signals, and a lightweight ML model in a low-latency decisioning pipeline.
1) Define the scoring goal
Decide what “risk” means for your use case:
- Fraud risk: likelihood a transaction is unauthorized or stolen
- AML risk: likelihood the transaction is suspicious from a compliance perspective
- Chargeback risk: likelihood of reversal/dispute
- Account takeover risk: likelihood the account/session is compromised
Each has different labels, features, and thresholds.
2) Build the real-time feature set
Use features available at decision time, ideally in under a few milliseconds:
Transaction features
- Amount
- Currency
- Merchant/category
- Payment method
- Device type
- Channel: web, app, POS, API
User/account features
- Account age
- Historical spend
- Chargeback/fraud history
- Prior declined transactions
- Login risk score
- Profile changes recently made
Behavioral features
- Velocity counts:
- transactions in last 5 min / 1 hr / 24 hr
- distinct merchants in last hour
- failed attempts in last 10 min
- Deviation from normal:
- amount vs user’s usual amount
- location vs usual geography
- time-of-day anomaly
Device/network signals
- IP reputation
- Proxy/VPN/TOR detection
- Device fingerprint stability
- Geolocation mismatch
- Browser/app integrity signals
Graph / relationship features
- Shared device across many accounts
- Shared card across many merchants
- Connected risky entities
3) Use a layered decisioning approach
A common pattern:
Layer A: hard rules
Examples:
- Block if card is on a denylist
- Block if impossible travel detected
- Require step-up if IP reputation is bad
- Decline if amount exceeds a hard threshold for certain MCCs
Rules are useful for:
- obvious abuse
- compliance requirements
- explainability
Layer B: model score
A supervised model outputs a probability/risk score:
- Logistic regression for simplicity and interpretability
- Gradient-boosted trees for strong performance
- Neural models if you have more complex data and mature infra
Layer C: policy action
Convert score into an action:
- Approve
- Challenge / step-up authentication
- Manual review
- Decline
Thresholds can vary by:
- customer segment
- country
- merchant
- transaction type
- current attack conditions
4) Train the model correctly
Labeling
Use historical outcomes:
- confirmed fraud
- chargebacks
- manual review results
- confirmed legitimate transactions
Be careful with:
- label delay
- false negatives
- data leakage
Split data by time
Always validate on later time periods, not random splits.
Handle class imbalance
Fraud is rare, so use:
- class weighting
- downsampling negatives
- precision/recall-oriented metrics
- calibrated probability outputs
Evaluate with operational metrics
Don’t just use AUC. Also measure:
- precision at top K
- recall at fixed false-positive rate
- fraud dollars saved
- false decline rate
- review queue volume
- latency
5) Architecture for real-time scoring
A typical flow:
- Transaction arrives
- Feature service enriches data
- account history
- recent velocity aggregates
- device/IP intelligence
- Rules engine checks hard rules
- Model service computes risk score
- Policy engine decides action
- Log decision and features
- Feed outcomes back into training loop
Infrastructure components
- Event stream: Kafka / Kinesis / PubSub
- Feature store: Redis, Cassandra, DynamoDB, Feast, Tecton
- Model serving: REST/gRPC low-latency service
- Decision engine: rules + thresholds
- Monitoring: drift, latency, approval rates, fraud capture
Target latency is often:
- <50 ms for many fintech/payment flows
- sometimes <10 ms if embedded in checkout authorization
6) Use real-time aggregates
A lot of fraud detection depends on very recent behavior, so precompute rolling aggregates:
- transactions per user in last 5 minutes
- total amount spent in last hour
- number of unique devices in last day
- number of failed logins in last 15 minutes
Use streaming jobs or fast counters so you can look these up instantly at scoring time.
7) Calibrate and threshold the score
A raw model probability is not always well-calibrated. You may need:
- Platt scaling
- isotonic regression
- segment-specific thresholds
Then map scores to actions like:
- 0–0.2: approve
- 0.2–0.6: step-up
- 0.6–1.0: decline
These thresholds should be tuned to business cost:
- false decline cost
- fraud loss cost
- manual review cost
- customer friction cost
8) Monitor and retrain continuously
Fraud patterns change quickly.
Monitor:
- score distributions
- approval/decline rates
- fraud capture rate
- false positives
- feature drift
- latency and errors
- attack spikes by geography/merchant/device
Retrain:
- daily, weekly, or continuously depending on volume and drift
- with recent confirmed labels
- with champion/challenger models
9) Practical scoring formula
A simple real-time risk score might combine:
- model probability
- rule hits
- velocity penalties
- device/IP reputation
- account anomaly score
For example:
final_risk = 0.6 * model_prob + 0.2 * velocity_score + 0.1 * device_risk + 0.1 * rules_penalty
Then apply thresholding:
final_risk < 0.3→ approve0.3–0.7→ challenge/manual review> 0.7→ decline
10) Best practices
- Keep features available at decision time only
- Avoid using labels or future information
- Design for explainability if compliance requires it
- Use human review for borderline cases
- Create per-segment policies
- Log every score, rule, and decision for audits
- Test with shadow mode before enforcing declines
If you want, I can also give you:
- a reference architecture diagram,
- a Python example of a real-time risk scoring service, or
- a feature list and model design for fraud detection.