Card fraud: a verdict in 100 ms
A card network sees 5,000 req/s. 20% are payments waiting for a yes or no, and the shop's till won't wait more than 100 ms. Each check asks whether this card is linked to known fraud rings, and today it's a join on a join in SQL.
Play this levelPart of Bugpit Pro. It runs in your browser: build the design, press Run, and watch what breaks.
The lesson
Fraud rarely looks wrong on its own. It shows up in links: one phone number on 40 cards, one device used by 12 accounts. Following links is a graph database's job, and each hop is a short step instead of another join.
Some checks need many events at once: "this card made 6 payments in 2 minutes in 3 countries". That's a running total over a window, which a Stream Processor keeps for every card as payments flow past.
The verdict has to be fast, but the charge doesn't. Answer the till, then put the payment in a stream. A worker charges the card and saves the record at the provider's pace.
So the slow, careful work happens beside the request, and the request only reads answers that are already worked out.
What you have to achieve
5,000 requests a second at the busiest hour, 2% of them writes.
- No broken or illegal connections
- Use a Graph DB with at least 2 instances
- Use a Stream Processor
- Use a Payment API
- Every event reaches both services
- No component is overloaded
- Workers clear the queue within the day
- Fewer than 0.1% of requests fail
- p99 response time under 100 ms
What you learn
The verdict now takes a few milliseconds: a hop in a graph and a lookup of totals the stream processor already worked out. Fraud systems are built this way: work done ahead of time, so the question in the moment is cheap.
Check yourself
Why a Graph DB for fraud checks?
- Fraud shows up as links between cards, phones and devices
- It stores more data
- It's faster for every query
Show the answer
Fraud shows up as links between cards, phones and devices. Following a link is one short hop in a graph, instead of another join in SQL.
The till waits 100 ms. What should happen inside that time?
- Charge the card
- Save the payment and send a receipt
- Only read answers that are already worked out
Show the answer
Only read answers that are already worked out. Charging, saving and running totals happen beside the request, so the verdict itself is cheap.