Chargeback monitoring and merchant risk scoring, in Spark.
Every merchant’s chargeback ratio held against monitoring bands, and every merchant scored for chargeback and fraud risk on the 1st. Saved SQL and one scheduled Spark job over your own storage, on a Kubernetes cluster you operate.
Same merchant.
0.1, then 0.55.
chargeback_risk_score of MCH-00000003 at each run of payments-monthly-risk, from the 90 days before it
merchant_risk_scoresMCH-00000003
Merchant risk scoring with a monthly Spark job
At 06:00 on the 1st, payments-monthly-risk reads each active merchant’s 90 days before that morning and writes a chargeback and a fraud score into merchant_risk_scores. A dispute counts while it sits in that window, then drops out.
disputes filed
transactions per day
disputes filed
transactions per day
disputes filed
transactions per day
DSP-0000000387chargeback13.1 24 AprDSP-0000001184chargeback13.1 21 MayDSP-0000000834chargeback13.1 27 MayDSP-0000001286chargeback13.1 31 MayDSP-0000001164chargeback13.1 5 JunDSP-0000001346chargeback13.1 11 JunDSP-0000001514chargeback13.1 14 JunDSP-0000001084chargeback13.1 16 JunDSP-0000001369chargeback13.1 21 JunDSP-0000000653chargeback13.1 26 JunDSP-0000001083chargeback13.1 3 JulDSP-0000000104chargeback13.1 12 JulDSP-0000001347chargeback13.1 14 JulDSP-0000000139chargeback13.1 16 JulDSP-0000000109chargeback13.1 24 JulDSP-0000001335chargeback13.1 26 AugDSP-0000000537chargeback13.1 2 SepDSP-0000000021chargeback13.1 17 SepDSP-0000001281chargeback10.4 18 Oct
DSP-0000001046chargeback13.1 21 MarDSP-0000001126arbitration10.4 7 AprDSP-0000000143chargeback10.4 29 JunDSP-0000000892chargeback13.2 18 JulDSP-0000001317chargeback10.5 18 JulDSP-0000001459chargeback10.4 13 AugDSP-0000001440chargeback10.4 18 AugDSP-0000000461chargeback10.4 22 AugDSP-0000000832retrieval_request10.4 24 AugDSP-0000001071chargeback10.4 25 AugDSP-0000001405chargeback10.4 31 AugDSP-0000001694chargeback10.4 7 SepDSP-0000001304chargeback10.4 14 SepDSP-0000001705chargeback10.4 17 SepDSP-0000001700chargeback10.4 20 SepDSP-0000000199chargeback10.4 23 SepDSP-0000000089chargeback10.4 24 SepDSP-0000001332chargeback10.4 26 SepDSP-0000000520chargeback13.3 28 SepDSP-0000000605chargeback10.4 28 SepDSP-0000001060chargeback10.4 29 SepDSP-0000000155chargeback10.4 30 SepDSP-0000001589chargeback10.4 30 SepDSP-0000000485chargeback10.4 2 OctDSP-0000000569chargeback10.4 4 OctDSP-0000000121chargeback10.4 5 OctDSP-0000001478retrieval_request10.4 7 OctDSP-0000000774chargeback13.6 9 OctDSP-0000000879chargeback10.4 10 OctDSP-0000000138chargeback10.4 18 OctDSP-0000000934chargeback10.4 19 OctDSP-0000000426chargeback10.4 22 OctDSP-0000000166chargeback10.4 25 OctDSP-0000000416chargeback10.4 28 OctDSP-0000000406chargeback10.4 30 OctDSP-0000001732chargeback10.4 1 NovDSP-0000001349chargeback10.4 3 NovDSP-0000000363chargeback10.4 6 NovDSP-0000000967chargeback12.2 6 NovDSP-0000001177chargeback10.4 11 NovDSP-0000001719pre_arbitration10.1 12 NovDSP-0000001025chargeback10.4 13 NovDSP-0000001363chargeback10.4 14 NovDSP-0000000624chargeback10.4 21 NovDSP-0000001334chargeback10.4 24 NovDSP-0000001471chargeback10.4 25 Nov
merchant_risk_scoresscore_date = '2026-06-01'MCH-00000003
written by the job
- txn_count_90d
- 873
- chargeback_count_90d
- 4
- chargeback_ratio_90d
- 0.004582 (0.46%)
- declined_count_90d
- 58
- chargeback_risk_score
- 0.1
- fraud_risk_score
- 0.11
counted by the job, not kept
- refund_count_90d
- 50
- offhours_txn_count_90d
- 21
- ecommerce_count_90d
- 377
- fraud_chargeback_count_90d
- 0
- chargeback_risk_score adds when
- disputes over 1% of transactionsnot met
- disputes over 0.5% of transactionsnot met
- more than five fraud disputes (reason 10.4)not met
- no dispute at all, which lowers the scorenot met
- fraud_risk_score adds when
- declined over 10%not met
- refunds over 5%met
- off-hours over 15%not met
- e-commerce over 90%not met
merchant_risk_scoresscore_date = '2026-07-01'MCH-00000003
written by the job
- txn_count_90d
- 884
- chargeback_count_90d
- 10
- chargeback_ratio_90d
- 0.011312 (1.13%)
- declined_count_90d
- 56
- chargeback_risk_score
- 0.55
- fraud_risk_score
- 0.11
counted by the job, not kept
- refund_count_90d
- 46
- offhours_txn_count_90d
- 18
- ecommerce_count_90d
- 387
- fraud_chargeback_count_90d
- 0
- chargeback_risk_score adds when
- disputes over 1% of transactionsmet
- disputes over 0.5% of transactionsmet
- more than five fraud disputes (reason 10.4)not met
- no dispute at all, which lowers the scorenot met
- fraud_risk_score adds when
- declined over 10%not met
- refunds over 5%met
- off-hours over 15%not met
- e-commerce over 90%not met
merchant_risk_scoresscore_date = '2026-08-01'MCH-00000003
written by the job
- txn_count_90d
- 876
- chargeback_count_90d
- 14
- chargeback_ratio_90d
- 0.015982 (1.6%)
- declined_count_90d
- 59
- chargeback_risk_score
- 0.55
- fraud_risk_score
- 0.11
counted by the job, not kept
- refund_count_90d
- 48
- offhours_txn_count_90d
- 21
- ecommerce_count_90d
- 388
- fraud_chargeback_count_90d
- 0
- chargeback_risk_score adds when
- disputes over 1% of transactionsmet
- disputes over 0.5% of transactionsmet
- more than five fraud disputes (reason 10.4)not met
- no dispute at all, which lowers the scorenot met
- fraud_risk_score adds when
- declined over 10%not met
- refunds over 5%met
- off-hours over 15%not met
- e-commerce over 90%not met
merchant_risk_scoresscore_date = '2026-09-01'MCH-00000003
written by the job
- txn_count_90d
- 872
- chargeback_count_90d
- 12
- chargeback_ratio_90d
- 0.013761 (1.38%)
- declined_count_90d
- 62
- chargeback_risk_score
- 0.55
- fraud_risk_score
- 0.11
counted by the job, not kept
- refund_count_90d
- 47
- offhours_txn_count_90d
- 24
- ecommerce_count_90d
- 401
- fraud_chargeback_count_90d
- 0
- chargeback_risk_score adds when
- disputes over 1% of transactionsmet
- disputes over 0.5% of transactionsmet
- more than five fraud disputes (reason 10.4)not met
- no dispute at all, which lowers the scorenot met
- fraud_risk_score adds when
- declined over 10%not met
- refunds over 5%met
- off-hours over 15%not met
- e-commerce over 90%not met
merchant_risk_scoresscore_date = '2026-10-01'MCH-00000003
written by the job
- txn_count_90d
- 913
- chargeback_count_90d
- 8
- chargeback_ratio_90d
- 0.008762 (0.88%)
- declined_count_90d
- 75
- chargeback_risk_score
- 0.25
- fraud_risk_score
- 0.11
counted by the job, not kept
- refund_count_90d
- 54
- offhours_txn_count_90d
- 23
- ecommerce_count_90d
- 406
- fraud_chargeback_count_90d
- 0
- chargeback_risk_score adds when
- disputes over 1% of transactionsnot met
- disputes over 0.5% of transactionsmet
- more than five fraud disputes (reason 10.4)not met
- no dispute at all, which lowers the scorenot met
- fraud_risk_score adds when
- declined over 10%not met
- refunds over 5%met
- off-hours over 15%not met
- e-commerce over 90%not met
merchant_risk_scoresscore_date = '2026-11-01'MCH-00000003
written by the job
- txn_count_90d
- 904
- chargeback_count_90d
- 4
- chargeback_ratio_90d
- 0.004425 (0.44%)
- declined_count_90d
- 71
- chargeback_risk_score
- 0.1
- fraud_risk_score
- 0.05
counted by the job, not kept
- refund_count_90d
- 44
- offhours_txn_count_90d
- 16
- ecommerce_count_90d
- 412
- fraud_chargeback_count_90d
- 1
- chargeback_risk_score adds when
- disputes over 1% of transactionsnot met
- disputes over 0.5% of transactionsnot met
- more than five fraud disputes (reason 10.4)not met
- no dispute at all, which lowers the scorenot met
- fraud_risk_score adds when
- declined over 10%not met
- refunds over 5%not met
- off-hours over 15%not met
- e-commerce over 90%not met
merchant_risk_scoresscore_date = '2026-06-01'MCH-00000074
written by the job
- txn_count_90d
- 895
- chargeback_count_90d
- 2
- chargeback_ratio_90d
- 0.002235 (0.22%)
- declined_count_90d
- 58
- chargeback_risk_score
- 0.1
- fraud_risk_score
- 0.11
counted by the job, not kept
- refund_count_90d
- 51
- offhours_txn_count_90d
- 19
- ecommerce_count_90d
- 382
- fraud_chargeback_count_90d
- 1
- chargeback_risk_score adds when
- disputes over 1% of transactionsnot met
- disputes over 0.5% of transactionsnot met
- more than five fraud disputes (reason 10.4)not met
- no dispute at all, which lowers the scorenot met
- fraud_risk_score adds when
- declined over 10%not met
- refunds over 5%met
- off-hours over 15%not met
- e-commerce over 90%not met
merchant_risk_scoresscore_date = '2026-07-01'MCH-00000074
written by the job
- txn_count_90d
- 876
- chargeback_count_90d
- 2
- chargeback_ratio_90d
- 0.002283 (0.23%)
- declined_count_90d
- 59
- chargeback_risk_score
- 0.1
- fraud_risk_score
- 0.11
counted by the job, not kept
- refund_count_90d
- 46
- offhours_txn_count_90d
- 20
- ecommerce_count_90d
- 374
- fraud_chargeback_count_90d
- 2
- chargeback_risk_score adds when
- disputes over 1% of transactionsnot met
- disputes over 0.5% of transactionsnot met
- more than five fraud disputes (reason 10.4)not met
- no dispute at all, which lowers the scorenot met
- fraud_risk_score adds when
- declined over 10%not met
- refunds over 5%met
- off-hours over 15%not met
- e-commerce over 90%not met
merchant_risk_scoresscore_date = '2026-08-01'MCH-00000074
written by the job
- txn_count_90d
- 879
- chargeback_count_90d
- 3
- chargeback_ratio_90d
- 0.003413 (0.34%)
- declined_count_90d
- 55
- chargeback_risk_score
- 0.1
- fraud_risk_score
- 0.11
counted by the job, not kept
- refund_count_90d
- 51
- offhours_txn_count_90d
- 20
- ecommerce_count_90d
- 399
- fraud_chargeback_count_90d
- 1
- chargeback_risk_score adds when
- disputes over 1% of transactionsnot met
- disputes over 0.5% of transactionsnot met
- more than five fraud disputes (reason 10.4)not met
- no dispute at all, which lowers the scorenot met
- fraud_risk_score adds when
- declined over 10%not met
- refunds over 5%met
- off-hours over 15%not met
- e-commerce over 90%not met
merchant_risk_scoresscore_date = '2026-09-01'MCH-00000074
written by the job
- txn_count_90d
- 867
- chargeback_count_90d
- 9
- chargeback_ratio_90d
- 0.010381 (1.04%)
- declined_count_90d
- 53
- chargeback_risk_score
- 0.67
- fraud_risk_score
- 0.11
counted by the job, not kept
- refund_count_90d
- 50
- offhours_txn_count_90d
- 20
- ecommerce_count_90d
- 390
- fraud_chargeback_count_90d
- 7
- chargeback_risk_score adds when
- disputes over 1% of transactionsmet
- disputes over 0.5% of transactionsmet
- more than five fraud disputes (reason 10.4)met
- no dispute at all, which lowers the scorenot met
- fraud_risk_score adds when
- declined over 10%not met
- refunds over 5%met
- off-hours over 15%not met
- e-commerce over 90%not met
merchant_risk_scoresscore_date = '2026-10-01'MCH-00000074
written by the job
- txn_count_90d
- 900
- chargeback_count_90d
- 20
- chargeback_ratio_90d
- 0.022222 (2.22%)
- declined_count_90d
- 52
- chargeback_risk_score
- 0.67
- fraud_risk_score
- 0.11
counted by the job, not kept
- refund_count_90d
- 59
- offhours_txn_count_90d
- 23
- ecommerce_count_90d
- 400
- fraud_chargeback_count_90d
- 17
- chargeback_risk_score adds when
- disputes over 1% of transactionsmet
- disputes over 0.5% of transactionsmet
- more than five fraud disputes (reason 10.4)met
- no dispute at all, which lowers the scorenot met
- fraud_risk_score adds when
- declined over 10%not met
- refunds over 5%met
- off-hours over 15%not met
- e-commerce over 90%not met
merchant_risk_scoresscore_date = '2026-11-01'MCH-00000074
written by the job
- txn_count_90d
- 881
- chargeback_count_90d
- 30
- chargeback_ratio_90d
- 0.034052 (3.41%)
- declined_count_90d
- 55
- chargeback_risk_score
- 0.67
- fraud_risk_score
- 0.11
counted by the job, not kept
- refund_count_90d
- 53
- offhours_txn_count_90d
- 20
- ecommerce_count_90d
- 384
- fraud_chargeback_count_90d
- 28
- chargeback_risk_score adds when
- disputes over 1% of transactionsmet
- disputes over 0.5% of transactionsmet
- more than five fraud disputes (reason 10.4)met
- no dispute at all, which lowers the scorenot met
- fraud_risk_score adds when
- declined over 10%not met
- refunds over 5%met
- off-hours over 15%not met
- e-commerce over 90%not met
merchant_risk_scoresscore_date = '2026-06-01'MCH-00000090
written by the job
- txn_count_90d
- 938
- chargeback_count_90d
- 0
- chargeback_ratio_90d
- 0 (0%)
- declined_count_90d
- 74
- chargeback_risk_score
- 0.0
- fraud_risk_score
- 0.11
counted by the job, not kept
- refund_count_90d
- 52
- offhours_txn_count_90d
- 28
- ecommerce_count_90d
- 403
- fraud_chargeback_count_90d
- 0
- chargeback_risk_score adds when
- disputes over 1% of transactionsnot met
- disputes over 0.5% of transactionsnot met
- more than five fraud disputes (reason 10.4)not met
- no dispute at all, which lowers the scoremet
- fraud_risk_score adds when
- declined over 10%not met
- refunds over 5%met
- off-hours over 15%not met
- e-commerce over 90%not met
merchant_risk_scoresscore_date = '2026-07-01'MCH-00000090
written by the job
- txn_count_90d
- 934
- chargeback_count_90d
- 0
- chargeback_ratio_90d
- 0 (0%)
- declined_count_90d
- 75
- chargeback_risk_score
- 0.0
- fraud_risk_score
- 0.11
counted by the job, not kept
- refund_count_90d
- 60
- offhours_txn_count_90d
- 18
- ecommerce_count_90d
- 411
- fraud_chargeback_count_90d
- 0
- chargeback_risk_score adds when
- disputes over 1% of transactionsnot met
- disputes over 0.5% of transactionsnot met
- more than five fraud disputes (reason 10.4)not met
- no dispute at all, which lowers the scoremet
- fraud_risk_score adds when
- declined over 10%not met
- refunds over 5%met
- off-hours over 15%not met
- e-commerce over 90%not met
merchant_risk_scoresscore_date = '2026-08-01'MCH-00000090
written by the job
- txn_count_90d
- 906
- chargeback_count_90d
- 0
- chargeback_ratio_90d
- 0 (0%)
- declined_count_90d
- 72
- chargeback_risk_score
- 0.0
- fraud_risk_score
- 0.11
counted by the job, not kept
- refund_count_90d
- 50
- offhours_txn_count_90d
- 10
- ecommerce_count_90d
- 399
- fraud_chargeback_count_90d
- 0
- chargeback_risk_score adds when
- disputes over 1% of transactionsnot met
- disputes over 0.5% of transactionsnot met
- more than five fraud disputes (reason 10.4)not met
- no dispute at all, which lowers the scoremet
- fraud_risk_score adds when
- declined over 10%not met
- refunds over 5%met
- off-hours over 15%not met
- e-commerce over 90%not met
merchant_risk_scoresscore_date = '2026-09-01'MCH-00000090
written by the job
- txn_count_90d
- 905
- chargeback_count_90d
- 0
- chargeback_ratio_90d
- 0 (0%)
- declined_count_90d
- 68
- chargeback_risk_score
- 0.0
- fraud_risk_score
- 0.11
counted by the job, not kept
- refund_count_90d
- 55
- offhours_txn_count_90d
- 3
- ecommerce_count_90d
- 414
- fraud_chargeback_count_90d
- 0
- chargeback_risk_score adds when
- disputes over 1% of transactionsnot met
- disputes over 0.5% of transactionsnot met
- more than five fraud disputes (reason 10.4)not met
- no dispute at all, which lowers the scoremet
- fraud_risk_score adds when
- declined over 10%not met
- refunds over 5%met
- off-hours over 15%not met
- e-commerce over 90%not met
merchant_risk_scoresscore_date = '2026-10-01'MCH-00000090
written by the job
- txn_count_90d
- 909
- chargeback_count_90d
- 0
- chargeback_ratio_90d
- 0 (0%)
- declined_count_90d
- 61
- chargeback_risk_score
- 0.0
- fraud_risk_score
- 0.05
counted by the job, not kept
- refund_count_90d
- 45
- offhours_txn_count_90d
- 9
- ecommerce_count_90d
- 406
- fraud_chargeback_count_90d
- 0
- chargeback_risk_score adds when
- disputes over 1% of transactionsnot met
- disputes over 0.5% of transactionsnot met
- more than five fraud disputes (reason 10.4)not met
- no dispute at all, which lowers the scoremet
- fraud_risk_score adds when
- declined over 10%not met
- refunds over 5%not met
- off-hours over 15%not met
- e-commerce over 90%not met
merchant_risk_scoresscore_date = '2026-11-01'MCH-00000090
written by the job
- txn_count_90d
- 924
- chargeback_count_90d
- 0
- chargeback_ratio_90d
- 0 (0%)
- declined_count_90d
- 56
- chargeback_risk_score
- 0.0
- fraud_risk_score
- 0.11
counted by the job, not kept
- refund_count_90d
- 50
- offhours_txn_count_90d
- 18
- ecommerce_count_90d
- 417
- fraud_chargeback_count_90d
- 0
- chargeback_risk_score adds when
- disputes over 1% of transactionsnot met
- disputes over 0.5% of transactionsnot met
- more than five fraud disputes (reason 10.4)not met
- no dispute at all, which lowers the scoremet
- fraud_risk_score adds when
- declined over 10%not met
- refunds over 5%met
- off-hours over 15%not met
- e-commerce over 90%not met
The job and its schedule
txn_features = (read_table(spark, "transactions")
.filter((F.col("event_date") >= lookback) & (F.col("event_date") < score_month))
.withColumn("rate_date", F.trunc("event_date", "month"))
.join(F.broadcast(rates), ["currency", "rate_date"], "left")
.groupBy("merchant_id")
.agg(
F.count("*").alias("txn_count_90d"),
F.sum(F.col("amount") * F.col("inverse_rate")).alias("txn_total_90d"),
F.avg(F.col("amount") * F.col("inverse_rate")).alias("avg_txn_amount_90d"),
F.sum(F.when(F.col("status") == "declined", 1).otherwise(0)).alias("declined_count_90d"),
F.sum(F.when(F.col("transaction_type") == "refund", 1).otherwise(0)).alias("refund_count_90d"),
F.sum(F.when((F.hour("event_timestamp") < 5) | (F.hour("event_timestamp") > 22), 1).otherwise(0)).alias("offhours_txn_count_90d"),
F.countDistinct("country").alias("unique_countries_90d"),
F.sum(F.when(F.col("channel") == "ecommerce", 1).otherwise(0)).alias("ecommerce_count_90d"),
F.sum(F.col("processing_fee") * F.col("inverse_rate")).alias("total_fees_90d"),
))
cb_features = (read_table(spark, "disputes")
.filter((F.col("filed_date") >= lookback) & (F.col("filed_date") < score_month))
.withColumn("rate_date", F.trunc("filed_date", "month"))
.join(F.broadcast(rates), ["currency", "rate_date"], "left")
.groupBy("merchant_id")
.agg(
F.count("*").alias("chargeback_count_90d"),
F.sum(F.col("dispute_amount") * F.col("inverse_rate")).alias("chargeback_volume_90d"),
F.sum(F.when(F.col("reason_code") == "10.4", 1).otherwise(0)).alias("fraud_chargeback_count_90d"),
))| Field | Value |
|---|---|
| name | payments-monthly-risk |
| jobClass | monthly_risk_scoring.py |
| cron | 0 6 1 * * |
| maxRetries | 3 |
| tags | team=risk, pipeline=ml-scoring, model=v1.2.0 |
Chargeback ratio monitoring in SQL
The chargeback ratio is the chargebacks of 90 days over the captured and settled purchases of the same 90 days. Chargeback Monitoring measures a merchant from 500 such purchases, where one chargeback moves the ratio by 0.2 points at most.
3 merchants at EXCEEDED - PROGRAM ENTRY
MCH-0000007434 chargebacks on 633 purchases5.37%2,767 more clean purchases to fall to 1%MCH-000000068 chargebacks on 558 purchases1.43%242 more clean purchases to fall to 1%MCH-000000299 chargebacks on 669 purchases1.35%231 more clean purchases to fall to 1%
2 merchants at WARNING
MCH-000000686 chargebacks on 621 purchases0.97%MCH-000000525 chargebacks on 659 purchases0.76%
1 merchant at ELEVATED
MCH-000000033 chargebacks on 594 purchases0.51%
44 merchants at NORMAL
MCH-000000183 chargebacks on 616 purchases0.49%MCH-000000813 chargebacks on 634 purchases0.47%MCH-000000873 chargebacks on 636 purchases0.47%MCH-000000992 chargebacks on 602 purchases0.33%MCH-000000172 chargebacks on 606 purchases0.33%MCH-000000762 chargebacks on 612 purchases0.33%MCH-000000212 chargebacks on 617 purchases0.32%MCH-000000232 chargebacks on 627 purchases0.32%
and 36 more
The queries and the tables
-- name: Payments/Compliance/Chargeback Monitoring
-- engine: SPARK_SQL
-- maxRows: 1000
-- description: Visa and Mastercard monitoring program thresholds per merchant with chargeback rate classification
WITH merchant_txn_90d AS (
SELECT
t.merchant_id,
COUNT(*) AS txn_count_90d,
ROUND(SUM(t.amount * COALESCE(er.inverse_rate, 1.0)), 2) AS gross_volume_eur_90d
FROM payment_processing.transactions t
LEFT JOIN (
SELECT currency, base_currency, rate, inverse_rate,
ROW_NUMBER() OVER (
PARTITION BY currency, base_currency
ORDER BY rate_date DESC
) AS rn
FROM payment_processing.exchange_rates
WHERE base_currency = 'EUR'
) er
ON t.currency = er.currency
AND er.rn = 1
WHERE t.status IN ('captured', 'settled')
AND t.transaction_type = 'purchase'
AND t.event_date >= DATE_ADD(CURRENT_DATE, -90)
GROUP BY t.merchant_id
-- a ratio is measured from 500 paid purchases in the 90 days: below that one chargeback moves it by 0.2 points or more
HAVING COUNT(*) >= 500
),
merchant_chargebacks_90d AS (
SELECT
d.merchant_id,
COUNT(*) AS chargeback_count_90d,
ROUND(SUM(d.dispute_amount), 2) AS chargeback_volume,
SUM(CASE WHEN d.status = 'merchant_lost' THEN 1 ELSE 0 END) AS lost_count,
SUM(CASE WHEN d.status = 'merchant_won' THEN 1 ELSE 0 END) AS won_count,
COUNT(DISTINCT d.reason_code) AS distinct_reason_codes
FROM payment_processing.disputes d
WHERE d.dispute_type = 'chargeback'
AND d.filed_date >= DATE_ADD(CURRENT_DATE, -90)
GROUP BY d.merchant_id
),
combined AS (
SELECT
m.merchant_id,
m.merchant_name,
m.country,
m.mcc_description,
m.segment,
m.risk_category,
mt.txn_count_90d,
mt.gross_volume_eur_90d,
COALESCE(mc.chargeback_count_90d, 0) AS chargeback_count_90d,
COALESCE(mc.chargeback_volume, 0) AS chargeback_volume,
COALESCE(mc.lost_count, 0) AS lost_count,
COALESCE(mc.won_count, 0) AS won_count,
COALESCE(mc.distinct_reason_codes, 0) AS distinct_reason_codes,
ROUND(COALESCE(mc.chargeback_count_90d, 0) * 100.0 / NULLIF(mt.txn_count_90d, 0), 4) AS chargeback_rate_pct
FROM payment_processing.merchants m
INNER JOIN merchant_txn_90d mt
ON m.merchant_id = mt.merchant_id
LEFT JOIN merchant_chargebacks_90d mc
ON m.merchant_id = mc.merchant_id
WHERE m.status = 'active'
)
SELECT
merchant_id,
merchant_name,
country,
mcc_description,
segment,
risk_category,
txn_count_90d,
gross_volume_eur_90d,
chargeback_count_90d,
chargeback_volume,
chargeback_rate_pct,
lost_count,
won_count,
distinct_reason_codes,
CASE
WHEN chargeback_rate_pct > 1.0 THEN 'EXCEEDED - PROGRAM ENTRY'
WHEN chargeback_rate_pct > 0.65 THEN 'WARNING'
WHEN chargeback_rate_pct > 0.5 THEN 'ELEVATED'
ELSE 'NORMAL'
END AS monitoring_status,
CASE
WHEN chargeback_rate_pct > 1.0 THEN 'Immediate action: enter VDMP/ECM program'
WHEN chargeback_rate_pct > 0.65 THEN 'Remediation plan required within 30 days'
WHEN chargeback_rate_pct > 0.5 THEN 'Monitor closely, review fraud controls'
ELSE 'No action required'
END AS recommended_action
FROM combined
ORDER BY chargeback_rate_pct DESC
LIMIT 50
-- Merchant Chargeback Rate & Program Proximity
-- Calculate 90-day chargeback rates and classify merchants by scheme program risk.
WITH merchant_txns AS (
SELECT
t.merchant_id,
m.merchant_name,
m.country,
m.segment,
m.risk_category,
COUNT(*) AS txn_count_90d,
ROUND(SUM(t.amount * COALESCE(fx.inverse_rate, 1.0)), 2) AS txn_volume_90d_eur
FROM payment_processing.transactions t
INNER JOIN payment_processing.merchants m
ON t.merchant_id = m.merchant_id
LEFT JOIN payment_processing.exchange_rates fx
ON t.currency = fx.currency
AND fx.base_currency = 'EUR'
AND fx.rate_date = trunc(t.event_date, 'MM')
WHERE t.event_date >= date_sub(current_date(), 90)
AND t.status IN ('captured', 'settled')
GROUP BY t.merchant_id, m.merchant_name, m.country, m.segment, m.risk_category
-- as in Chargeback Monitoring: a ratio is measured from 500 paid purchases in the 90 days
HAVING COUNT(*) >= 500
),
merchant_disputes AS (
SELECT
d.merchant_id,
COUNT(*) AS chargeback_count_90d,
ROUND(SUM(d.dispute_amount * COALESCE(fx.inverse_rate, 1.0)), 2) AS disputed_amount_eur,
SUM(CASE WHEN d.status = 'merchant_lost' THEN 1 ELSE 0 END) AS lost_count,
ROUND(SUM(
CASE WHEN d.status = 'merchant_lost'
THEN d.dispute_amount * COALESCE(fx.inverse_rate, 1.0)
ELSE 0 END
), 2) AS net_loss_eur
FROM payment_processing.disputes d
LEFT JOIN payment_processing.exchange_rates fx
ON d.currency = fx.currency
AND fx.base_currency = 'EUR'
AND fx.rate_date = trunc(d.filed_date, 'MM')
WHERE d.filed_date >= date_sub(current_date(), 90)
AND d.dispute_type = 'chargeback'
GROUP BY d.merchant_id
)
SELECT
mt.merchant_id,
mt.merchant_name,
mt.country,
mt.segment,
mt.risk_category,
mt.txn_count_90d,
mt.txn_volume_90d_eur,
COALESCE(md.chargeback_count_90d, 0) AS chargeback_count_90d,
ROUND(COALESCE(md.chargeback_count_90d, 0) * 100.0 / NULLIF(mt.txn_count_90d, 0), 3) AS chargeback_rate_pct,
COALESCE(md.disputed_amount_eur, 0) AS disputed_amount_eur,
COALESCE(md.net_loss_eur, 0) AS estimated_net_loss_eur,
CASE
WHEN COALESCE(md.chargeback_count_90d, 0) * 100.0 / NULLIF(mt.txn_count_90d, 0) > 1.0 THEN 'EXCEEDED'
WHEN COALESCE(md.chargeback_count_90d, 0) * 100.0 / NULLIF(mt.txn_count_90d, 0) > 0.65 THEN 'WARNING'
WHEN COALESCE(md.chargeback_count_90d, 0) * 100.0 / NULLIF(mt.txn_count_90d, 0) > 0.5 THEN 'ELEVATED'
ELSE 'NORMAL'
END AS program_status
FROM merchant_txns mt
LEFT JOIN merchant_disputes md
ON mt.merchant_id = md.merchant_id
WHERE COALESCE(md.chargeback_count_90d, 0) > 0
ORDER BY chargeback_rate_pct DESC
LIMIT 20-- Top Reason Codes with Win Rates and Financial Impact
-- Identify the most common dispute reasons and where merchants succeed in reversals.
WITH reason_analysis AS (
SELECT
d.reason_code,
d.reason_description,
d.card_brand,
COUNT(*) AS dispute_count,
ROUND(SUM(d.dispute_amount * COALESCE(fx.inverse_rate, 1.0)), 2) AS total_disputed_eur,
ROUND(AVG(d.dispute_amount * COALESCE(fx.inverse_rate, 1.0)), 2) AS avg_disputed_eur,
SUM(CASE WHEN d.status = 'merchant_won' THEN 1 ELSE 0 END) AS won_count,
SUM(CASE WHEN d.status = 'merchant_lost' THEN 1 ELSE 0 END) AS lost_count,
SUM(CASE WHEN d.status = 'open' THEN 1 ELSE 0 END) AS pending_count,
SUM(CASE WHEN d.liability_shift = 'issuer' THEN 1 ELSE 0 END) AS liability_shift_count
FROM payment_processing.disputes d
LEFT JOIN payment_processing.exchange_rates fx
ON d.currency = fx.currency
AND fx.base_currency = 'EUR'
AND fx.rate_date = trunc(d.filed_date, 'MM')
WHERE d.filed_date >= date_sub(current_date(), 180)
GROUP BY d.reason_code, d.reason_description, d.card_brand
)
SELECT
reason_code,
reason_description,
card_brand,
dispute_count,
total_disputed_eur,
avg_disputed_eur,
won_count,
lost_count,
pending_count,
ROUND(won_count * 100.0 / NULLIF(won_count + lost_count, 0), 1) AS win_rate_pct,
liability_shift_count,
CASE
WHEN LOWER(reason_description) LIKE '%fraud%' OR LOWER(reason_description) LIKE '%unauthorized%' THEN 'FRAUD'
WHEN LOWER(reason_description) LIKE '%not received%' OR LOWER(reason_description) LIKE '%defective%' THEN 'SERVICE'
WHEN LOWER(reason_description) LIKE '%duplicate%' OR LOWER(reason_description) LIKE '%incorrect%' THEN 'PROCESSING'
ELSE 'OTHER'
END AS reason_category
FROM reason_analysis
ORDER BY dispute_count DESC-- Dispute Overview by Type and Status
-- Summary of all disputes with resolution timing and merchant win rates.
WITH dispute_metrics AS (
SELECT
d.dispute_type,
d.status,
COUNT(*) AS dispute_count,
ROUND(AVG(
CASE
WHEN d.resolved_date IS NOT NULL
THEN DATEDIFF(d.resolved_date, d.filed_date)
ELSE NULL
END
), 1) AS avg_resolution_days,
ROUND(MIN(
CASE
WHEN d.resolved_date IS NOT NULL
THEN DATEDIFF(d.resolved_date, d.filed_date)
ELSE NULL
END
), 0) AS min_resolution_days,
ROUND(MAX(
CASE
WHEN d.resolved_date IS NOT NULL
THEN DATEDIFF(d.resolved_date, d.filed_date)
ELSE NULL
END
), 0) AS max_resolution_days,
ROUND(SUM(d.dispute_amount * COALESCE(fx.inverse_rate, 1.0)), 2) AS total_disputed_eur,
SUM(CASE WHEN d.status = 'merchant_won' THEN 1 ELSE 0 END) AS merchant_wins
FROM payment_processing.disputes d
LEFT JOIN payment_processing.exchange_rates fx
ON d.currency = fx.currency
AND fx.base_currency = 'EUR'
AND fx.rate_date = trunc(d.filed_date, 'MM')
GROUP BY d.dispute_type, d.status
)
SELECT
dispute_type,
status,
dispute_count,
avg_resolution_days,
min_resolution_days,
max_resolution_days,
total_disputed_eur,
merchant_wins,
ROUND(merchant_wins * 100.0 / NULLIF(dispute_count, 0), 1) AS merchant_win_rate_pct
FROM dispute_metrics
ORDER BY dispute_type, dispute_count DESC-- Evidence and Response Impact on Dispute Outcomes
-- Analyze how merchant response and evidence submission affect win rates.
WITH evidence_analysis AS (
SELECT
CASE
WHEN d.merchant_responded = true AND d.evidence_submitted IS NOT NULL
THEN d.evidence_submitted
WHEN d.merchant_responded = true AND d.evidence_submitted IS NULL
THEN 'responded_no_evidence'
ELSE 'no_response'
END AS response_category,
d.liability_shift,
COUNT(*) AS dispute_count,
SUM(CASE WHEN d.status = 'merchant_won' THEN 1 ELSE 0 END) AS won_count,
SUM(CASE WHEN d.status = 'merchant_lost' THEN 1 ELSE 0 END) AS lost_count,
ROUND(SUM(d.dispute_amount * COALESCE(fx.inverse_rate, 1.0)), 2) AS total_disputed_eur,
ROUND(SUM(
CASE WHEN d.status = 'merchant_lost'
THEN d.dispute_amount * COALESCE(fx.inverse_rate, 1.0)
ELSE 0 END
), 2) AS total_lost_eur
FROM payment_processing.disputes d
LEFT JOIN payment_processing.exchange_rates fx
ON d.currency = fx.currency
AND fx.base_currency = 'EUR'
AND fx.rate_date = trunc(d.filed_date, 'MM')
WHERE d.filed_date >= date_sub(current_date(), 180)
AND d.status IN ('merchant_won', 'merchant_lost')
GROUP BY
CASE
WHEN d.merchant_responded = true AND d.evidence_submitted IS NOT NULL
THEN d.evidence_submitted
WHEN d.merchant_responded = true AND d.evidence_submitted IS NULL
THEN 'responded_no_evidence'
ELSE 'no_response'
END,
d.liability_shift
)
SELECT
response_category,
liability_shift,
dispute_count,
won_count,
lost_count,
ROUND(won_count * 100.0 / NULLIF(won_count + lost_count, 0), 1) AS win_rate_pct,
total_disputed_eur,
total_lost_eur,
ROUND(total_lost_eur * 100.0 / NULLIF(total_disputed_eur, 0), 1) AS loss_rate_pct
FROM evidence_analysis
ORDER BY win_rate_pct DESCpayment_processing.disputesChargeback and dispute records. Tracks dispute lifecycle from filing through resolution including merchant response and liability assignment.dispute_id | Unique dispute identifier (format: DSP-XXXXXXXXXX) |
|---|---|
transaction_id | FK to transactions table (original disputed transaction) |
merchant_id | FK to merchants table |
dispute_type | Dispute category: chargeback, retrieval_request, pre_arbitration, arbitration |
reason_code | Card scheme reason code (e.g. 10.4 for CNP fraud) |
dispute_amount | Disputed amount in local currency |
filed_date | Date dispute was filed by issuer |
resolved_date | Date dispute was resolved (null if still open) |
status | Dispute outcome: open, merchant_won, merchant_lost, expired, withdrawn |
merchant_responded | Whether merchant submitted a representment response |
evidence_submitted | Type of evidence: compelling_evidence, proof_of_delivery, signed_contract, none |
liability_shift | Party bearing financial liability: issuer, merchant, psp |
card_brand | Card network: visa, mastercard, amex |
payment_processing.transactionsCore payment transaction fact table. All card, SEPA, wallet, and BNPL transactions across all markets.Partitioned by event_month and country.transaction_id | Unique transaction reference (format: PTX-XXXXXXXXXXXX) |
|---|---|
merchant_id | FK to merchants table |
payment_method | Payment instrument: card_visa, card_mastercard, card_amex, sepa_transfer, digital_wallet, bnpl, ideal, giropay |
transaction_type | Transaction category: purchase, refund, payout, fee, chargeback_debit |
amount | Gross transaction amount in local currency |
channel | Origination channel: ecommerce, in_store, mobile_app, recurring, moto |
event_timestamp | Exact timestamp of transaction processing |
status | Processing status: captured, authorized, declined, refunded, settled, failed |
sca_method | Strong Customer Authentication method: 3ds2, exemption_low_value, exemption_tra, exemption_recurring, not_applicable |
payment_processing.merchantsCore merchant dimension. One row per onboarded merchant across all markets.merchant_id | Unique merchant identifier (format: MCH-XXXXXXXX) |
|---|---|
mcc_code | 4-digit Merchant Category Code per ISO 18245 |
segment | Merchant size tier: micro, small, mid_market, enterprise |
risk_category | Risk classification: low, standard, elevated, high |
status | Current merchant status: active, suspended, terminated, under_review |
payment_processing.merchant_risk_scoresWritten by payments-monthly-risk on the 1st: one row per active merchant and month.Partitioned by score_date.merchant_id | The merchant scored |
|---|---|
score_date | The 1st of the month scored |
chargeback_risk_score | Between 0 and 1 |
fraud_risk_score | Between 0 and 1 |
chargeback_count_90d | Disputes filed in the 90 days before |
chargeback_ratio_90d | Those disputes over the transactions of the 90 days |
declined_count_90d | Declined transactions of the 90 days |
| Status | Chargeback ratio | Next step |
|---|---|---|
| EXCEEDED - PROGRAM ENTRY | over 1.0% | Immediate action, program entry |
| WARNING | over 0.65% | Remediation plan required within 30 days |
| ELEVATED | over 0.5% | Monitor closely, review fraud controls |
| NORMAL | 0.5% or less | No action required |
How to run chargeback monitoring on Ilum, step by step
Six steps from an empty cluster to a ratio checked daily, scores on the 1st and a risk team that reads both. Each uses a part of Ilum that comes with the default install.
An empty cluster
A ratio checked daily, scores on the 1st
- Helm chart
Add the chart repository and install it on any CNCF-compliant Kubernetes. Spark, the SQL editor, the Hive Metastore and MinIO come with it.
helm repo add ilum https://charts.ilum.cloud helm install ilum ilum/ilum - Spark
A Spark job reads the exports of your payment platform and the dispute feed from S3, GCS, Azure Blob or HDFS and writes
merchants,transactionsanddisputesintopayment_processingas Delta tables. - SQL editor
Save Chargeback Monitoring in the SQL editor in a folder such as
Payments/Compliance. It runs on Spark SQL, the default engine. - Schedules
Upload
monthly_risk_scoring.pyas a Spark job and schedule it with the cron0 6 1 * *and three retries. Ilum creates a Kubernetes CronJob for the schedule and starts a failed run again. How a schedule fires. - Roles
A
RISK_COMPLIANCE_OFFICERrole holds SQL_EXECUTE, SQLNOTEBOOK_READ and LINEAGE_READ and creates no jobs or schedules. Put the team in a group that carries it. - Tags
Tag
disputesandmerchant_risk_scoresREGULATORY, and the scores’ columns with it, so the Lineage view marks them beside the job that wrote them. A PCI DSS data lake tags cardholder data the same way.
Questions and answers
How is the chargeback ratio calculated?
Chargebacks filed against a merchant in a period over its purchases in the same period. The query here counts chargebacks only, not retrievals or arbitration, over captured and settled purchases of the last 90 days, per active merchant.
What chargeback ratio puts a merchant at risk?
The query marks ELEVATED over 0.5%, WARNING over 0.65% and program entry over 1%. The card schemes’ programs set their own thresholds and counts and change them, so set the band edges to the program your acquirer enrolls you in.
What is reason code 10.4?
Fraud in a card-absent environment, the most common fraud reason on online payments. The monthly risk job counts a merchant’s 10.4 disputes apart and raises its chargeback score when there are more than five in 90 days. Fraud detection with Spark checks the fraud score of the same job against the disputes that followed.
How do I score merchant risk with Spark?
Aggregate 90 days of transactions and disputes per merchant in a Spark job, turn thresholds on the ratios into points of a score, write one row per merchant and month, and schedule it for the 1st. How a Spark job runs on Ilum.
How long does a chargeback dispute take?
A chargeback takes 30 to 45 days, a retrieval request 10 to 20, pre-arbitration 30 and arbitration 45 to 90. Measure your own from filed_date to resolved_date.
Why measure only merchants with enough purchases?
Because one chargeback on a small merchant is a large ratio: on 15 purchases it is 6.7%. Chargeback Monitoring measures merchants from 500 paid purchases in 90 days, where one chargeback moves the ratio by 0.2 points at most, as the card schemes count merchants from a minimum number of disputes.
Is Ilum open source?
No. Ilum Community is free to run under a license from Ilum. It is built on open-source engines such as Apache Spark, Trino and DuckDB.
Contact
Tell us about your cluster.
Name one workload you want to move.
Tell us where it runs today.
We answer with a plan, not a deck.
We reply within two working days.
