
Information Security and Anti-Fraud, Part 6: Rules and Scoring — How to Build an Anti-Fraud System from Scratch
🌐 Machine-translated from Russian. Show original
In this part:
Simple anti-fraud system architecture#
- Event — registration, login, payment, withdrawal, change of details.
- Signal collection — data about the user, device, network, history.
- Rules and scoring — risk assessment calculation.
- The solution is to skip, request confirmation, send for manual review, or reject.
- Feedback — the result (confirmed or not) is returned to the system for rules configuration.
You can start with a module in your own code and a table in the database — specialized platforms are needed when the volume grows.
Signals#
| Group | Examples |
|---|---|
| Account | account age, whether email and phone number are confirmed, transaction history, |
| Device | is a new device for the account, how many accounts are there |
| Network | IP from a data center or VPN, IP country, matching address |
| Velocity | number of operations per 10 minutes, hour, day, |
| Amount | deviation from the user's regular receipt |
| Contacts | shared phone numbers, addresses, maps, devices with known scammers, |
Use personal data signals within the framework of consent and legal requirements and keep them as long as necessary for protection.
Velocity SQL rules#
The most useful rules are about speed. Example: how many different maps were tried on one device in an hour:
SELECT device_id, count(DISTINCT card_fingerprint) AS cards
FROM payment_attempts
WHERE created_at > now() - interval '1 hour'
GROUP BY device_id
HAVING count(DISTINCT card_fingerprint) >= 3;
How many accounts are registered with one IP per day:
SELECT ip, count(*) AS signups
FROM signups
WHERE created_at > now() - interval '1 day'
GROUP BY ip HAVING count(*) > 5;
Scoring points#
Instead of a single hard rule — the sum of points from several signals:
type Ctx = { accountAgeDays: number; newDevice: boolean; ipCountry: string; cardCountry: string;
amount: number; avgAmount: number; attemptsLastHour: number };
function riskScore(c: Ctx) {
let s = 0;
if (c.accountAgeDays < 1) s += 20;
if (c.newDevice) s += 15;
if (c.ipCountry !== c.cardCountry) s += 20;
if (c.avgAmount > 0 && c.amount > c.avgAmount * 5) s += 25;
if (c.attemptsLastHour >= 3) s += 30;
return s;
}
function decide(score: number) {
if (score >= 70) return "decline"; // отклонить
if (score >= 40) return "review"; // ручная проверка или доп. подтверждение
return "allow";
}
Advantages of the approach: transparent, easy to explain the solution to the client and support, easy to change weights.
Decisions: not just "yes" and "no"#
| Risk | Solution |
|---|---|
| Low | skip without friction for the customer |
| Medium | additional step: SMS code, 3-D Secure, confirmation in the |
| High | manual verification or failure with clear message |
Additional confirmation for medium risk is the best balance: an honest client will pass in 10 seconds, while a fraudster with stolen data usually does not.
Setup and feedback#
- Each trigger is logged with points for each signal — to understand why the decision was made.
- The results of manual checks and chargebacks mark operations: fraud or not.
- Once a week, check the precision and recall rules (part 5: the rule that mostly blocks honest customers needs to be relaxed.
- First, run the new rules in " observe-only" mode: count how many blocks you want, but don't block them.
When to switch to machine learning#
ML models are justified when there is a marked history (thousands of confirmed fraud cases), a stable flow of operations, and a team that will support the model. Even then, the rules remain: for new schemas, for explainability, and as insurance. Skills from the "SQL for Business" post will help prepare data for such a transition.
Comments · 0
No comments yet.Sign in to comment, rate and see all comments.