支付欺詐偵測系統設計面試逐步講解
Design a payment fraud detection system: the system design interview walkthrough
文章以系統設計面試 walkthrough 講解支付欺詐偵測系統,核心是把即時評分與離線特徵計算、模型訓練拆成兩條流程。即時評分須在約 100–200ms 的授權時限內完成,模型超時時可退回只用規則評分。退款爭議標籤可能延遲 30–90 天,設計因此包括成熟度窗口、分析員代理標籤及漂移偵測。
Design a payment fraud detection system: the system design interview walkthrough
The request to design a payment fraud detection system sounds like a machine-learning problem — train a classifier on past fraud, ship it, done. That instinct is exactly the trap. The interview asks you to decide approve, decline, or challenge on a live payment inside the hundred-or-so milliseconds the card networks allow, using features that are fresh to the second, while the only honest answer to "was that transaction fraud?" arrives as a chargeback thirty to ninety days later — so you are training on stale ground truth, scoring against adversaries who adapt, and paying a real cost every time you block a good customer or wave a bad one through. This is one of the sharper system design interview prompts because the obvious "build an ML pipeline" answer misses the two things that actually decide it: a hard real-time path and a broken label clock.
The round turns on three decisions. First, the real-time scoring path — how a transaction gets a risk score and a decision inside the authorization latency budget, with rules and a model working together and a fallback when the model is slow. Second, features — how you compute fresh velocity signals (how many attempts from this card, device, or IP in the last few minutes) off a stream and serve them in single-digit milliseconds. Third, labels and the feedback loop — how you train and retrain a model when the truth shows up months late and your own past decisions bias the data you learn from. This walkthrough follows the path a strong candidate draws on the whiteboard — requirements, estimate, API and data model, high-level design, then the deep dives — and at each step it names the follow-up the interviewer uses to tell a memorised answer from an engineer who has run a real system.
How the fraud detection round is actually run
A fraud detection round runs about 60 minutes on a shared canvas — you draw the boxes and arrows while you talk, and the interviewer interrupts. It is a favourite for a payments loop because the one-line problem hides two systems, not one: a real-time path that must answer in under ~150ms or the payment network times out, and an offline path that computes features and trains models over hours to days. Most candidates draw only the ML pipeline and get ambushed when the interviewer asks about latency. Get the two-lane split, the feature path and the label-delay problem clean and you have shown you have operated a real risk system, not read about one.
The interviewer rarely lets "train a fraud classifier and score transactions" stand. "You score this payment as fine. The cardholder disputes it as fraud sixty days from now. How did you train the model that made today's decision, and how do you even know it's wrong before the chargeback lands?" That question — a label clock that runs months behind the decision clock — is the one a copied answer can never rehearse, and the one this round is really testing.
The rounds here are modelled on how the loop runs, not scraped from any candidate's recall. What matters for prep is the shape: a blank canvas, a clock, and a follow-up after every decision you make.
The five-step framework for any HLD round
Every high-level design answer fits the same spine. Say it out loud at the start so the interviewer knows you have a plan, then walk it:
- Clarify requirements — functional and non-functional, and what you are explicitly not building.
- Estimate — transactions per second, the latency budget, the fraud base rate and the label delay, to justify every later choice.
- High-level design — the boxes and arrows: the two lanes — real-time scoring, and offline features/training — and the feature store that joins them.
- Deep dive — the two or three decisions that actually decide this system.
- Follow-ups — bottlenecks, failure modes, and what you would change at ten times the scale.
What the debrief measures
The score is not "right or wrong design." A good HLD debrief reads on four dimensions, and every move below maps to one: problem solving (did you split real-time from offline before drawing anything, and give the scorer a fallback), communication (did you separate risk estimation from action policy, and name the cost of a false positive vs a false negative, in a sentence), technical execution (an online feature store on the hot path, streaming velocity features, rules plus a gradient-boosted model, delayed labels handled with proxies and drift detection), and time management (did you spend your 60 minutes on the latency path, features and labels, not on model hyperparameters). Reading a walkthrough teaches the design; it does not teach you to deliver it on the clock while someone pushes back.
Step 1 — Requirements: what a fraud detection system must do
Spend the first few minutes here. Jumping to boxes before you have scoped the problem is the fastest way to design the wrong system — and here the first question is what kind of fraud and what action can you take.
| Type | Requirement |
|---|---|
| Functional | Score each incoming payment for fraud risk in real time and return a decision — approve, decline, or step-up challenge — plus flag borderline cases for human review; compute fresh features about the card, user, device, merchant and recent velocity; let analysts review cases and feed outcomes back; retrain as patterns change. |
| Functional (optional) | Reason codes/explanations for a decision, per-merchant customisation, graph analysis for fraud rings — call these out, then scope most of them for later. |
| Non-functional | Hard latency budget on the scoring path (end-to-end auth window ~100–200ms); fresh features (seconds, not hours); the system must degrade gracefully if the model or feature store is slow; fraud is rare and imbalanced (well under 1%); labels arrive weeks to months late; adversaries adapt; auditable decisions. |
The sentence that earns points: "This is two systems — a real-time scorer that must decide inside the auth latency budget with a safe fallback, and an offline lane that computes features and retrains against labels that arrive months late — joined by a feature store, and I'll separate risk estimation from the action policy." Say that and you have framed the entire design before drawing a box.
Step 2 — Capacity estimation (back of the envelope)
Estimation here is about proving one thing: the hard axis is latency and label timing, not throughput — the volume is modest, but the decision window is tiny and the truth is late.
| Quantity | Assumption | Result |
|---|---|---|
| Transactions | ~millions/day | ~100s/sec average, size for 10–20x peak (flash sales, holidays) → low thousands/sec |
| Latency budget | card-network auth window ~100–200ms | scoring must finish in ~150ms p99 → every hot-path read is a budget line item |
| Fraud base rate | well under 1% of transactions | severe class imbalance → precision/recall and thresholds matter more than raw accuracy |
| Label delay | chargebacks arrive 30–90 days later | ground truth is months stale → naive supervised training is impossible |
| Feature freshness | velocity over seconds–minutes | features must be streamed, not batch-computed overnight |
Two conclusions fall out, and you should say both out loud. First, the real-time path lives on a latency budget — you cannot read a relational database or recompute aggregates on the hot path; features are precomputed and served from a low-latency online store, the model runs behind a strict timeout, and if it misses you fall back to rules (a degraded decision beats no decision). Second, the label clock is broken — because chargebacks land months after the transaction, you cannot train on last week's data as if you knew its outcome, so the offline lane leans on proxy labels, label-maturity windows and drift detection, not a nightly supervised retrain. You have now pointed the interview at the latency path, the feature stream and the label problem — the real deep dives — before anyone asked.
Step 3 — API and data model
The interface is a single synchronous scoring call plus the asynchronous machinery behind it; the design lives in how fast the call is served and how the labels come back, not in the API surface.
| Call | Operation |
|---|---|
POST /score(transaction) → {score, decision, reasons}
|
synchronous: fetch features, run rules + model, return approve / decline / challenge within the latency budget |
ingest(transaction_event) |
append the event to the stream for feature computation and later training |
getFeatures(entity_ids) → vector
|
low-latency read of precomputed features from the online store (card, device, merchant, velocity) |
submitLabel(txn_id, outcome) |
record a matured label — chargeback, dispute, or analyst decision — for retraining |
reviewCase(txn_id, decision) |
an analyst resolves a flagged case; the decision is a fast proxy label |
The data model is the transaction event, the features it is scored against, the decision, and the labels that arrive late:
| Entity | Notes |
|---|---|
transaction |
id, user, card, device, ip, merchant, amount, currency, ts. The thing being scored, and later a training row. |
feature_vector |
precomputed signals keyed by entity: card/user history, device familiarity, merchant risk, and velocity windows (counts over recent minutes/hours). Served from the online store. |
decision |
txn_id, score, action (approve/decline/challenge/review), model_version, rules_fired. Logged against the exact versions that made it. |
label |
txn_id, outcome (fraud/legit/unknown), source (chargeback/dispute/analyst), matured_at. Arrives late; the source and maturity are first-class, not collapsed into one target. |
Step 4 — High-level design: the two-lane architecture
Now the boxes. Draw the two swim lanes first — everything else fills in around them:
- Real-time lane (the hot path): a transaction hits the scoring service, which fetches features from the online feature store, runs the rules engine and the ML model, combines them into a score, and the decision engine maps the score to an action — hard block, step-up challenge, allow, or send to review — all inside the latency budget. The model runs behind a strict timeout with a rules-only fallback.
- Streaming lane (fresh features): every transaction is also emitted to a log/stream (Kafka); a stream processor (Flink/Spark) computes rolling-window velocity aggregates and writes them to the online feature store, so the next transaction scores against up-to-the-second signals.
- Offline lane (training): matured labels (chargebacks, disputes) and analyst review outcomes flow into a training pipeline that builds features point-in-time, trains the model, and publishes a new version to the model registry for deployment — on a cadence driven by drift, not a fixed nightly job.
- Review & feedback: borderline cases go to an analyst queue; their decisions are fast proxy labels that close the loop sooner than chargebacks, and confirmed cases become new rules or features.
Say explicitly that you separate risk estimation from action policy — the model and rules produce a score, and a separate, tunable decision layer turns that score into block / challenge / allow, so you can move the operating point (for a merchant, a segment, a risk appetite) without retraining. And say the hot path never touches a relational database — features are read from the online store in single-digit milliseconds. Naming the two lanes, the fallback, and the estimation/policy split unprompted is a signal the interviewer is listening for.
Deep dive: real-time scoring inside the latency budget
This is the first decision that actually decides the round, because it is the one most candidates forget until the interviewer asks about latency. The scorer has roughly 150 milliseconds, end to end, and every component spends part of it.
The budget, line by line. A rough split: an online feature read (~5ms from an in-memory store like Redis), the rules engine (~10ms), and model inference (~20ms), leaving headroom for network and the decision. The consequence is non-negotiable: you never read a relational database or recompute an aggregate on the hot path — all features are precomputed and served from the online store. The model runs as its own service behind a strict timeout; if it is slow or down, you fall back to rules-only scoring rather than stall the payment, because a degraded decision is better than a missed auth window.
Rules and model together. Rules handle the things you know — blocklists, hard limits, impossible-travel, cold-start cases where the model has no history — and run fast and explainably. The model (a gradient-boosted tree like XGBoost or LightGBM, the right default for tabular fraud) generalises across the long tail of subtle, interacting signals and returns a calibrated probability. You combine them, then the decision engine applies a three-tier policy: hard block the obvious fraud, add friction (a step-up challenge) to the gray zone so the human review queue does not drown, and allow the rest — with borderline cases routed to analysts.
"The model service gets slow and your p99 blows past the auth window — what does the scorer return?" It falls back to rules-only scoring within the budget: a degraded decision beats no decision, because missing the card-network window fails the payment outright. The hot path reads only the online feature store (single-digit ms), never a relational DB. Name the strict timeout, the rules fallback, and the budget breakdown.
Deep dive: streaming features and velocity
This is the decision that makes the real-time path possible. The most predictive fraud signals are velocity — how many attempts from this card in the last minute, how many distinct merchants this device has hit in an hour, whether this is a first-seen device for the account — and those cannot be computed inside the 150ms budget, so they are computed ahead of time on a stream and read as precomputed features.
Compute on the stream, serve from the store. Every transaction flows to a log (Kafka), and a stream processor (Flink or Spark Streaming) maintains rolling-window aggregates per card, device, IP and merchant — counts, distinct-counts and sums over several time windows — updating an online feature store (Redis-class, sub-10ms reads) continuously. When the next transaction arrives, the scorer reads those windows as a plain feature lookup; the heavy aggregation already happened.
Point-in-time correctness. The subtle trap the interviewer probes is feature leakage: a training row for a payment at 10:00 must use only what was known at 10:00 — not an aggregate recomputed with later events, and certainly not the chargeback filed weeks later. So the offline feature computation must reproduce the online values as of decision time (point-in-time joins), and you validate offline-online parity so the model trains on the same features it serves on. And you define fallback behaviour for missing or stale features — a safe default, a simpler model, or extra verification — because "the feature store always works" is not a design.
"Which features actually move the needle, and how do you compute them without blowing the latency budget?" Velocity windows — attempts and distinct merchants/devices/IPs over recent minutes — computed on a Kafka+Flink stream and served from an online feature store as a sub-10ms lookup, never computed on the hot path. Guard point-in-time correctness and offline-online parity so you don't leak the future into training. Name velocity, the stream, and point-in-time joins.
System Design
HLD · Payments · 60 min
Design a payment fraud detection system out loud, with follow-ups
Deep dive: labels, the feedback loop and retraining
This is the decision that separates candidates who have run a real risk system from everyone else. The label clock is broken, and naive supervised learning quietly falls apart on it.
The label-delay problem. A chargeback arrives 30 to 90 days after the fraudulent transaction, so you cannot train on last week's payments as if you knew their outcomes — your supervised ground truth is always months stale, and fraud patterns have moved on by the time labels mature. Two mitigations carry the answer. Proxy labels: analyst review decisions (from the gray-zone queue) land within hours, noisier than chargebacks but fresh enough to train more often. Drift detection: you watch the model's score distribution and input features for shifts (a population-stability-index-style check) and retrain when they drift — without waiting for labels, because the distribution moving is itself the alarm. Use a label-maturity window so you only train and evaluate on examples old enough for the outcome to be observed.
The feedback loop and its bias. Your own decisions poison your data: analysts only review transactions the current system flagged, and declined transactions never get the outcome they would have had if approved — so the training set is a biased sample the model itself shaped. You acknowledge this (no technique removes it), split train/validation chronologically rather than randomly to avoid leaking future behaviour into the past, and evaluate on a recent out-of-time slice because adversaries adapt. And because fraud is rare and imbalanced, you optimise thresholds against cost, not accuracy — a false positive blocks a paying customer and loses a sale, a false negative is a fraud loss and a chargeback, and the card networks penalise a chargeback rate above a floor, which sets your recall target.
"Chargebacks arrive two months late — how do you train and know the model is drifting before the labels land?" Train on matured labels within a maturity window, supplement with faster analyst proxy labels, and detect drift from score/feature-distribution shifts so you retrain before labels confirm it. Split chronologically, evaluate out-of-time, and tune thresholds on the cost of false positives vs false negatives. Name the label delay, proxy labels, and drift detection.
System Design
HLD · Payments · 60 min
Defend the latency path, features and label loop out loud
The follow-ups that decide the fraud detection round
Scan the probes from each deep dive and they rhyme. Master these five and you are ready for a version of the question that is not drawn exactly like this one.
- "The model service slows past the auth window — what does the scorer do?" → Fall back to rules-only within the budget; a degraded decision beats a missed auth. The hot path reads only the online feature store, never a relational DB. (problem solving)
- "Which features matter, and how do you compute them in time?" → Velocity windows (attempts, distinct merchants/devices/IPs) computed on a Kafka+Flink stream and served from the online store as a fast lookup, with point-in-time correctness. (technical execution)
- "Chargebacks arrive two months late — how do you train?" → Matured labels within a maturity window, plus faster analyst proxy labels, plus drift detection to retrain before labels confirm it; split chronologically. (problem solving)
- "How do you set the decline threshold?" → On cost, not accuracy — a false positive loses a paying customer, a false negative is a fraud loss and a chargeback; tune the operating point per segment, separate from the model. (communication)
- "What catches a fraud ring that each transaction alone looks normal?" → Offline graph analysis over shared devices/IPs across accounts, writing risk signals back to the feature store for the next real-time score. (technical execution)
Each maps to a debrief dimension. Reading this list teaches you the answers; it does not teach you to deliver them while someone interrupts — that only comes from saying them out loud.
How to prepare: a one-week plan
You do not need fifty systems. You need this one cold and the framework automatic, so the next "design X" is just new nouns in the same five steps.
- Days 1–2: Learn the five-step framework until it is reflex. Do the fraud system end to end on paper — requirements, estimate, data model, the two-lane architecture (real-time scoring, streaming features, offline training) joined by the feature store.
- Days 3–4: Drill the real-time path: the latency budget line by line, online feature store on the hot path, rules + model, the strict timeout and rules fallback, and the three-tier decision policy. Say each tradeoff in one sentence.
- Days 5–6: Own features and labels — streaming velocity and point-in-time correctness, the chargeback label delay, proxy labels, drift detection, chronological splits, and cost-based thresholds. Answer each of the five follow-ups out loud.
- Day 7: A full timed 60-minute round, narrating the whole way, with someone (or something) interrupting. This is the rep that counts.
This post is the deep walkthrough behind one row of the broader Top 25 system design interview questions — once the fraud design is automatic, the same spine carries the rest of the list.
Frequently asked questions
How do I design a payment fraud detection system step by step?
Follow the five-step HLD framework. Clarify requirements (score each payment in real time to approve/decline/challenge, flag borderline cases, retrain as patterns change — hard latency budget, rare imbalanced fraud, labels that arrive months late); estimate to show the hard axis is latency and label timing, not throughput; define the scoring API and the transaction/feature/decision/label model; draw the two-lane architecture (a real-time scorer over an online feature store with rules + model and a fallback, a streaming lane computing velocity features, and an offline lane training on matured labels), joined by the feature store; then deep-dive the three decisions that matter — real-time scoring inside the latency budget, streaming velocity features, and labels with the feedback loop.
Why is fraud detection a real-time and an offline system, not one pipeline?
Because the two halves have opposite constraints. The real-time path must return a decision inside the card-network authorization window (~100–200ms), so it only reads precomputed features and runs a fast rules-plus-model scorer with a fallback — there is no time to compute anything heavy. The offline path runs over hours to days: it computes rolling features on a stream, trains and retrains models against labels that mature slowly, and runs expensive analyses like graph detection of fraud rings. Drawing those two swim lanes first, and showing the feature store that joins them, is the structure that separates a strong answer from a candidate who designs one monolithic ML pipeline and gets ambushed by the latency question.
How do you handle the chargeback label delay when training a fraud model?
Chargebacks arrive 30 to 90 days after the transaction, so you can never treat recent payments as labeled — the ground truth is months stale and fraud patterns have already shifted. You train and evaluate only on examples old enough for the outcome to be observed (a label-maturity window), supplement slow chargeback labels with faster analyst review decisions as proxy labels, and detect drift from shifts in score and feature distributions so you retrain before the labels confirm the model has degraded. You also split train and validation chronologically rather than randomly, because a random split leaks future behaviour and repeated entities into the past, and you acknowledge the feedback-loop bias — the model only sees outcomes for transactions it did not block.
What features matter most in fraud detection and how are they served fast?
Velocity features dominate — how many attempts from this card, device or IP in the last minute, how many distinct merchants a device has hit in an hour, whether this is a first-seen device for the account — because coordinated or stolen-instrument fraud shows up as abnormal rates, not abnormal single transactions. They cannot be computed inside the latency budget, so a stream processor (Flink or Spark on a Kafka log) maintains rolling-window aggregates continuously and writes them to an online feature store that the scorer reads in single-digit milliseconds. The critical correctness property is point-in-time accuracy: training must use the feature values as they were at decision time, and offline and online computations must match, or the model leaks the future and looks great offline while failing in production.
How do you decide whether to block, challenge, or allow a transaction?
Separate risk estimation from action policy. The rules and model produce a score; a distinct, tunable decision layer maps that score to a three-tier action — hard block the clear fraud, add friction (a step-up verification challenge) in the gray zone so the human review queue does not drown, and allow the rest, with borderline cases routed to analysts. You set the thresholds on cost rather than accuracy: a false positive blocks a paying customer and loses a sale, a false negative is a fraud loss plus a chargeback, and the card networks penalise a chargeback rate above a floor, which effectively sets a recall target. Keeping the policy separate from the model lets you shift the operating point per merchant, segment, or risk appetite without retraining.
How do I practise a system design interview out loud?
Reading a walkthrough is not the same as defending a design while someone interrupts. On Zynter, the HLD track runs live voice rounds modelled on how real system design loops run — you talk through a shared design on the canvas, and a voice interviewer pushes with the follow-ups above one at a time, then gives you a debrief on problem solving, communication, technical execution, and time management. The score is a practice signal, not a hiring decision.
Practise it on Zynter
You can draw the ML pipeline. The round is won on the latency path and the broken label clock.
Pick the Fraud Detection round, draw the two-lane architecture on the canvas, and defend it out loud to a voice interviewer that keeps asking "what does the scorer return when the model is slow?" and "how do you train when the labels arrive two months late?" — then read the debrief. Zynter.ai is on-demand mock interviews modelled on real company loops, with 150+ rounds across 20 companies including the HLD system design track (Sep 2026).
Practise the Fraud Detection round →
Browse all interview tracks
來源:DEV Community · dev.to



