KatInterview

Build a Real-Time Risk Scoring Gateway for Card Payments

System DesignModel answer
MediumModel answerSystem Designsystem-designfraud-detectionfeature-store

Last updated

Design a low-latency, highly available service that scores each payment attempt using analyst-owned rules plus ML models and returns an explainable approve, block, step-up, or review verdict.

Problem

You are building the risk scoring gateway for a payments company. Before the platform authorizes or captures a charge, it calls your service synchronously. Your service must reply with one of four verdicts:

  • approve: let the payment proceed
  • block: reject it
  • step-up: require extra verification (for example, 3-D Secure or an OTP)
  • review: hold it for a human analyst

The verdict should draw on signals such as:

  • amount and merchant
  • account history and chargeback history
  • device fingerprint, IP address, and geolocation
  • the payment instrument used
  • velocity (how often a card, device, or account has appeared recently)
  • known fraud patterns

The design must blend deterministic rules (authored and owned by risk analysts) with ML model scores. It must stay fast, explainable, auditable, and available. Analysts must be able to write, test, and ship new rules and models safely. Confirmed fraud, chargebacks, and manual-review results must return to the system as training labels.

Constraints

  • The check sits on the payment critical path. Target p99 under roughly 100-200 ms.
  • Peak load is tens of thousands of requests per second, and traffic is bursty.
  • High availability is mandatory, because an outage here stalls all payments.
  • Labels are delayed and noisy. Chargebacks can arrive 30+ days later, and some fraud is never labeled.
  • Every block or review needs reason codes usable by support, compliance, and dispute teams.
  • Rule and model changes must roll out gradually, never as a big-bang deploy.
  • Card numbers and other sensitive data must be tokenized or minimized. PCI and privacy requirements are hard constraints.

What to deliver

Walk through your requirements, the synchronous decision path, feature and data architecture, the rules and model lifecycles, scaling and failure handling, auditing and monitoring, and security. Call out the trade-offs you make. Before designing, list the clarifying questions you would ask (call pattern, business priorities for fraud loss versus approval rate, QPS and latency budgets, rule ownership and speed, available labels, compliance, and reusable infrastructure).

Hints

Hint 1

Frame everything around the business trade-off: fraud losses versus false declines. Thresholds for the four verdicts come from that trade-off, not from the model alone.

Hint 2

Split the work into a hot path (fetch precomputed features, run rules and model, combine) and a cold path (stream processing, feature computation, label ingestion, training). Keep anything slow or heavy off the hot path.

Hint 3

Decide explicitly what happens when a dependency is slow or down: per-call timeouts, a rules-only fallback, and a fail-open versus fail-closed policy that depends on transaction risk tier.

Hint 4

Plan for training-serving skew and delayed labels: share feature definitions between online and offline, snapshot the features used for each decision, and use shadow and canary stages before a model or rule goes live.