Every payment API platform manages accounts that hold sensitive credentials: API keys, stored payment methods, bank transfer permissions. When an attacker takes over one of these accounts through stolen credentials, phishing, or SIM (subscriber identity module) swap, they can drain funds, redirect payments, or steal customer data before anyone notices. The challenge is catching that takeover at the moment the attacker tries to do something dangerous, without locking out every legitimate user who travels, switches devices, or changes their workflow.
The first thing I would clarify is the primary detection surface. For a payment API company, the highest-leverage surface is not login, it is the moment a sensitive action fires: a payment-method change, a high-value transfer, an API key rotation. Attackers who phish credentials or perform a SIM swap may log in legitimately and act hours later. Scoring at login alone misses them.
The business objective is not detection recall. It is minimizing expected business cost across four possible actions: allow, step-up authentication, flag for analyst review, or block and lock. False lockouts on high-value merchant accounts are expensive: customers abandon operations, contact support, and may churn. Every design decision downstream sits inside that cost surface.
This is not transaction fraud detection. ATO (account takeover) is about who is using the account, not whether a specific payment is fraudulent. The signals are behavioral (device switches, geo anomalies, login patterns), the labels come from customer reports rather than chargebacks, and the action space is account-level rather than transaction-level.
The ML task is: given an account, session, device, IP, behavioral history, action context, and graph signals, predict calibrated P(ATO | action) and map it through per-action-sensitivity and per-merchant-tier thresholds to one of the four enforcement actions. The consumers are the API gateway, the authentication service, and the analyst review queue.
At a high level, the system has two loops. The online path scores each sensitive action in roughly 100 ms: a rule pre-filter catches known-bad signals, a feature fetch pulls session velocity and account profiles from Redis, a behavioral scorer produces a calibrated probability, and an action mapper applies the threshold ladder. The offline path closes the feedback loop: events, ATO reports, analyst verdicts, and chargeback links flow through Kafka into Flink for nearline aggregation and Spark for batch training, retraining, and threshold governance. Four pressures make this hard: real-time scoring under a tight latency budget, labels that arrive days to weeks late, severe class imbalance at roughly 0.01-0.1% ATO rate, and adversaries who rotate credential-stuffing tools within days.