# Fraud detection - a decision that must fit in 120 milliseconds

> Teaches how a risk decision is split between a synchronous call with a hard deadline and an asynchronous review that is allowed to be right. When the deadline…

Source: https://tierslate.com/templates/fraud-detection

Payments & ledgers · System design · deep · 8 step walkthrough · 5 tables

Teaches how a risk decision is split between a synchronous call with a hard deadline and an asynchronous review that is allowed to be right.

**Own this board: 800 credits.** The first act plays on the page. Owned once with credits, never a subscription.

## What this board gets wrong on purpose

The tension: When the deadline is missed the scorer fails OPEN - it allows the payment - and that is the correct choice, because a risk engine able to block revenue will eventually block all of it. It is also the exact behaviour an attacker wants, and the attack is cheap: make the feature store slow and every decision becomes an allow. Nothing on this board distinguishes "the feature store is degraded" from "somebody is degrading the feature store", and the timeout rate is a dashboard rather than a circuit breaker. The second unresolved thing is feature freshness: velocity counters are written from a stream that is seconds to minutes behind at peak, so the six-card-attempts-in-one-minute pattern the rules exist to catch is invisible for exactly as long as the lag lasts - and the lag is worst precisely during the traffic spike an attack produces. Reading the counters synchronously from the write path would fix it and would also put a 40 ms dependency inside a 120 ms budget, so the design accepts staleness and does not measure what it costs.

## Practise this as an interview

Take Fraud detection - a decision that must fit in 120 milliseconds as a timed system design interview on a blank board - on your own, with the requirements to check yourself against, or with a candidate you invite.

## Start here

### Why this design

Fraud detection looks like a machine-learning question and is really a latency-budget question: the decision has to fit inside somebody else's payment, in about 120 ms including every feature it reads. Interviewers use it to probe whether you can split a system into a fast synchronous path with a defined default and a slow asynchronous path that is allowed to be right, and whether you can put a money value on a false positive. Payment companies such as Stripe, Adyen and PayPal run exactly this split.

### What you will learn

- How a**120 ms budget**is spent - network, 14 pipelined feature reads in 25 ms, rules, model, slack - and why the slack goes first.
- Why the deadline guard**fails open to ALLOW**, and what that costs when an attacker slows the feature store on purpose.
- Why the feature store is its own tier:**2,139 lookups/s on average and 25,667/s at peak**, against only 153 decisions/s.
- Why**REVIEW**is the outcome that makes the economics work - and why 0.4% of traffic is 165 full-time analysts.
- Why every decision stores**the feature vector it saw**, not just the score, and why that table is 79% of the bytes.
- Why the training signal is a chargeback that arrives**45 to 120 days**later, and how that biases the model.

### How to read this board

1. Press play once: the walkthrough follows one payment from the clock starting to the label arriving sixty days later.
2. **IN THE PAYMENT PATH**: everything that shares the 120 ms - scorer, features, rules, model, deadline guard.
3. **BESIDE THE PATH**: the streaming features, the review queue and the analyst - the half that has hours.
4. **LEARNING**: labels, offline training and how a new model reaches the path.
5. **DATA MODEL**: store what the model saw, not just what it said.
6. Then pages 1 to 6 in order: requirements, capacity, storage, availability, how it works, deployment.

## 1 · Requirements

This system answers one question - should this payment proceed - inside somebody else’s latency budget, and then answers it again more carefully when nobody is waiting.

### Ask these before designing

- **What does a false positive cost, in money?**Until that number exists, no threshold can be chosen and every argument about the model is an argument about taste. Here: average basket 68 EUR, and about 40% of falsely declined customers never come back, so a false decline costs roughly 2.4x a basket in lifetime terms.
- **Who owns the loss?**If the merchant eats the chargeback, they will accept a looser threshold than the gateway would. If we eat it, we will not. The threshold is a commercial decision wearing an engineering costume.
- **Is a "review" outcome usable at all?**Holding a payment for a human is only possible if the product can say "we are checking" without shipping. A digital-goods merchant has no such state, and for them the three-way decision collapses to two.
- **How fresh must features be?**"Six attempts in the last minute" is a different system from "spend in the last 30 days". The first needs a synchronous counter; the second is a nightly batch. Most teams build one pipeline and are surprised that it serves neither well.
- **What is the deadline, and what happens at it?**Not "the model is fast". A hard number, and a stated default for when it is exceeded.

### Functional

- Score a payment and return ALLOW, REVIEW or DECLINE within the deadline.
- Record what the model saw, not just what it said, for every decision.
- Queue REVIEW decisions for human analysts with the evidence attached.
- Accept chargeback labels weeks later and attach them to the original decision.
- Let a rule be added, shadowed and enabled without a deploy.

### Non-functional

- **p99 of 120 ms end to end**, measured at the caller, not at the model server.
- **Fail open at the deadline.**Stated as a requirement rather than discovered as a behaviour. A risk engine that can block revenue will one day block all of it.
- **Every decision is explainable.**A stored feature vector and a rule trace, kept for the length of the dispute window. "The model said so" is not an answer to a regulator or to a merchant.
- **99.99% availability, with a defined answer when unavailable**- which is ALLOW, and which is why the availability number matters less here than anywhere else on these boards.
- **No PII in the feature store.**Hashed identifiers only. The feature store is replicated to every region and is therefore the easiest thing here to leak.

### Explicitly out of scope

Model training infrastructure, the payment rails themselves, chargeback representment workflow, identity verification and KYC. This board is about the shape of the decision, not about the mathematics inside it.

## The rest of this board

This page publishes the question. The answer - 5 more written pages, an 8-step narrated walkthrough and a 5-table schema - is the board itself, and it opens in Tierslate.

- 5 written pages
- 8 walkthrough steps
- 5 tables (32 columns)

5 pages behind this one:

- Capacity estimation
- Storage estimation
- Availability
- How it works
- Deployment plan

## Related system design templates

- [Double-entry ledger system design](https://tierslate.com/templates/double-entry-ledger) - Teaches why money is stored as immutable movements and read as a derived sum, and what it costs to never update a total.
- [Payment gateway system design](https://tierslate.com/templates/payment-gateway) - Teaches how a payment system stays correct when its authoritative dependency can fail in a way that tells you nothing.
- [Matching engine system design](https://tierslate.com/templates/stock-exchange) - Teaches why an exchange assigns order with a sequence number instead of measuring it with a clock, and what a single-threaded book buys in return.
- [Wallet transfers system design](https://tierslate.com/templates/wallet-transfers) - Teaches how money moves between two accounts in one system without ever being in both places or neither, and what it costs to make every step undoable.
- [OTP verification system design](https://tierslate.com/templates/otp-verification) - How a one-time code is issued, rate limited and checked, and why the SMS bill is the attack surface.
- [Subscription billing system design](https://tierslate.com/templates/subscription-billing) - How a recurring charge is driven by a billing clock, proration and dunning, and why plan changes are the hard part.
- [Currency exchange system design](https://tierslate.com/templates/currency-exchange) - Why a quoted FX rate is a short-lived promise with an expiry, and how rounding is a ledger decision.
- [Loyalty points system design](https://tierslate.com/templates/loyalty-points) - Why points are a ledger with expiry and liability, and why a balance column is the wrong answer again.

All 100 system design templates: https://tierslate.com/templates (Markdown: https://tierslate.com/templates.md)
