DEV Community

Cover image for Your Fraud Model Missed a 5-Account Ring. One Graph Query Found It.
Luis M
Luis M

Posted on Originally published at synapcores.com

Your Fraud Model Missed a 5-Account Ring. One Graph Query Found It.

Fraud models have a blind spot built into how they work: they score one row at a time.

That's exactly right for the lone fraudster, whose payments are huge, at 3am, from abroad. It does nothing against a fraud ring: five accounts that each spend like a normal customer but share one phone and a couple of stolen card numbers. The ring isn't in any row. It's in the connections between rows.

Here's a worked example with real numbers. I re-ran every query below this morning on a fresh install, and the data, model and queries are all in a recipe you can run yourself.

The setup: 40 ordinary accounts, one lone fraudster, one hidden ring

  • 123 transactions. Every account makes three ordinary payments ($20–$199, daytime, domestic).
  • One lone fraudster. ACC-33 also makes three large 3am cross-border payments.
  • One ring. ACC-11 to ACC-15 behave exactly like everyone else, but they share two devices and two card numbers in a chain.
  • One confirmed chargeback, on ACC-13.

No fraud labels anywhere.

Step 1: the machine-learning view

Train an isolation forest (unsupervised, so no labels needed) on amount, hour and a cross-border flag:

CREATE EXPERIMENT recipe_ring_exp AS
  SELECT amount, hour_of_day, cross_border
  FROM recipe_ring_tx
WITH (
  task_type   = 'anomaly_detection',
  algorithms  = ['isolation_forest'],
  max_trials  = 5,
  random_seed = 42
);

DEPLOY MODEL recipe_ring_model FROM EXPERIMENT recipe_ring_exp;
Enter fullscreen mode Exit fullscreen mode

Then score every transaction, right inside a SELECT:

SELECT account_id, amount, hour_of_day, cross_border,
       ANOMALY_SCORE('recipe_ring_model', amount, hour_of_day, cross_border) AS score
FROM recipe_ring_tx
ORDER BY score DESC
LIMIT 10;
Enter fullscreen mode Exit fullscreen mode
account_id amount hour cross_border score
ACC-33 2840 3 1 0.817
ACC-33 3120 3 1 0.817
ACC-33 2975 3 1 0.806
ACC-36 198 19 0 0.527
ACC-39 23 17 0 0.518
…

The model nails the lone fraudster. Now ask it about the ring:

SELECT account_id, amount, hour_of_day,
       ANOMALY_SCORE('recipe_ring_model', amount, hour_of_day, cross_border) AS score
FROM recipe_ring_tx
WHERE account_id IN ('ACC-11','ACC-12','ACC-13','ACC-14','ACC-15')
ORDER BY score DESC;
Enter fullscreen mode Exit fullscreen mode

All 15 ring payments score between 0.445 and 0.508, the same band as honest customers.

The model isn't wrong. Each of those payments is ordinary. A ring isn't a property of any single transaction, so a per-transaction model can't see it.

Step 2: the graph view

Model the same accounts as a graph: accounts, devices and cards as nodes, USES and PAYS_WITH as relationships. The ring chains together: ACC-11 and ACC-12 share a phone, ACC-12 and ACC-13 share a card, and so on. As a control, two honest accounts (ACC-21, ACC-22) share a household tablet.

Start from the one thing you know for sure, the chargeback on ACC-13, and walk outward 2 to 4 hops:

MATCH p = (s:Account {id: 'ACC-13'})-[*2..4]-(x:Account)
WHERE x.id <> 'ACC-13'
RETURN x.id AS linked_account, [n IN nodes(p) | n.id] AS via
ORDER BY length(p);
Enter fullscreen mode Exit fullscreen mode
linked_account via
ACC-14 ACC-13 → DEV-778 → ACC-14
ACC-12 ACC-13 → CARD-4242 → ACC-12
ACC-15 ACC-13 → DEV-778 → ACC-14 → CARD-9001 → ACC-15
ACC-11 ACC-13 → CARD-4242 → ACC-12 → DEV-777 → ACC-11

One seed, the whole ring, each with the exact path that links it. The household pair isn't returned: sharing a device isn't fraud, but being connected to a chargeback is worth a look.

In plain SQL this would be a recursive CTE over a union of account–device and account–card link tables. Here it's one pattern.

Step 3: one review queue

Neither signal is enough alone, so merge them. Save the graph hits in a table (recipe_ring_members), then keep every account the model or the graph flagged:

SELECT s.account_id, ROUND(s.max_anomaly, 2) AS max_anomaly, r.linked_via
FROM (
  SELECT account_id, MAX(score) AS max_anomaly
  FROM (
    SELECT account_id,
           ANOMALY_SCORE('recipe_ring_model', amount, hour_of_day, cross_border) AS score
    FROM recipe_ring_tx
  ) t
  GROUP BY account_id
) s
LEFT JOIN recipe_ring_members r ON r.account_id = s.account_id
WHERE s.max_anomaly > 0.7 OR r.account_id IS NOT NULL
ORDER BY s.max_anomaly DESC;
Enter fullscreen mode Exit fullscreen mode
account_id max_anomaly linked_via
ACC-33 0.82 (caught by the model)
ACC-15 0.51 DEV-778 > CARD-9001
ACC-12 0.51 CARD-4242
ACC-13 0.49 chargeback
ACC-14 0.48 DEV-778
ACC-11 0.48 CARD-4242 > DEV-777

Six accounts to review instead of 40, each with a reason. Five of the six would never have crossed a 0.7 threshold. The model found one fraudster; the graph found five.

ML vs graph, side by side

Anomaly model Graph traversal
Catches Unusual behaviour: amount, time, location Collusion: shared devices, cards, addresses
Doesn't see Rings that look normal row by row Fraudsters with no links to known fraud
Needs labels? No (isolation forest) No (one seed)
Output A score per transaction The accounts and the path linking them

Practical notes

  • Seed traversals from confirmed fraud. Known cases plus shared-infrastructure links surface new candidates.
  • Send graph hits to review, not to auto-block. Families share devices.
  • Calibrate thresholds on your own data. 0.7 fits this dataset; check your own score distribution first.

Run it yourself

Most fraud stacks put these two signals in separate systems: a feature pipeline and model server for the ML, a graph database for the links, and a sync job between them. I ran all of the above in one engine, SynapCores, against the same tables: ANOMALY_SCORE() in SQL and the traversal in Cypher. No AI model or labels are needed for this demo.

curl -fsSL https://get.synapcores.com | sh
# or
docker pull synapcores/community:v2.5.1-ce
Enter fullscreen mode Exit fullscreen mode

It's the free, self-hosted Community Edition. The full dataset, graph setup and cleanup are in the recipe: Fraud rings your ML model misses (about 12 minutes). There's also a browser Playground if you'd rather not install anything yet.

Here's the 3-minute walkthrough:

The original write-up is on synapcores.com.

How does your team catch collusion today: graph queries, rules on shared identifiers, or a second model?

Top comments (0)