DEV Community

Shohruh Sharipov
Shohruh Sharipov

Posted on

How Banks Detect Fraud in 27 Milliseconds (The System Design)

You tap your card in New York. Two minutes later, someone tries to use it in Lagos — and the bank blocks it instantly. How does it decide in under 30 milliseconds, across billions of transactions a day?

I animated the whole pipeline below 👇 — the rest of this post walks through it in text.

The 5-stage pipeline (~27ms total)

1. Ingest — Apache Kafka (~1ms). Millions of transactions per second stream in. Kafka appends each to a log, so nothing is lost and everything is processed in real time.

2. Rules engine (~2ms). Fast, hard-coded checks run first: geo-velocity (NYC → Lagos in 2 minutes = physically impossible), amount vs. the user's historical average, and time-of-day / spending-limit patterns.

3. ML model (~15ms). The heavy lifting. A model trained on 500M+ real transactions takes features — amount, geo distance, merchant category, device fingerprint — and outputs a fraud probability score.

4. Graph database (~8ms). Checks whether this card, merchant, or device is connected to known fraud rings. One fraudster's network can span thousands of cards, and a graph query surfaces that instantly.

5. Decision engine (~1ms). Combine the signals into a score:

  • 0–30 → auto-approve
  • 31–69 → send an OTP challenge
  • 70–89 → human analyst queue
  • 90–100 → instant block + SMS alert

A combined score of 94/100 means BLOCKED, and the cardholder is notified in about a second.

Why it's fast

Every slow decision is pushed off the critical path: Kafka absorbs bursts, the rules engine kills obvious cases before the ML model ever runs, and scoring is precomputed features plus fast inference — never a big database scan on the hot path.


I make animated breakdowns like this — system design, backend & DevOps, visualized — on CodeAnimated.

▶ Full channel: https://www.youtube.com/@CodeAnimatedDev

Top comments (0)