AML transaction monitoring in Spark SQL, on premises.
Structuring, amounts over 15,000 EUR and deposits moved on within the hour, screened in Spark SQL on a Kubernetes cluster you operate. No transaction leaves your infrastructure.
Each under 10,000.
37,746.54 in a day.
Screen 2 of AML Screening on CUST-00003536: the 24 hours up to 16:38 on 23 Nov 2026 in EUR, each and stacked
window_total_eur > 10,000Screen 2, structuring: flags this row
Structuring detection with a rolling 24-hour window
Structuring splits money into transactions that each stay under a reporting threshold, so no single one looks wrong. A window function sums each customer’s last 24 hours at every transaction, and the pattern only shows in the sum.
PARTITION BY customer_id ORDER BY event_timestampPick a row: the window ends at it.
the screens’ 30 daysUTC
card purchase609.77 SEK 54.50 EUR
Screen 2, structuringdoes not flag it
- not met
window_total_eur > 10,00054.50 - met
max_single_txn <= 10,00054.50 - not met
txn_count_in_window >= 21
Screen 1, large transactiondoes not flag it
- not met
amount_eur > 15,00054.50
Screen 3, rapid movementdoes not flag it
- not met
this row is a depositcard purchase - not met
the next row is a transferpayment - not met
within 3,600 seconds8 days
payment389.90 SEK 34.79 EUR
Screen 2, structuringdoes not flag it
- not met
window_total_eur > 10,00034.79 - met
max_single_txn <= 10,00034.79 - not met
txn_count_in_window >= 21
Screen 1, large transactiondoes not flag it
- not met
amount_eur > 15,00034.79
Screen 3, rapid movementdoes not flag it
- not met
this row is a depositpayment - not met
the next row is a transfercard purchase - not met
within 3,600 seconds10 days
card purchase70.98 SEK 6.33 EUR
Screen 2, structuringdoes not flag it
- not met
window_total_eur > 10,0006.33 - met
max_single_txn <= 10,0006.33 - not met
txn_count_in_window >= 21
Screen 1, large transactiondoes not flag it
- not met
amount_eur > 15,0006.33
Screen 3, rapid movementdoes not flag it
- not met
this row is a depositcard purchase - not met
the next row is a transferdeposit - not met
within 3,600 seconds7 days
deposit106,411.49 SEK 9,494.03 EUR
Screen 2, structuringdoes not flag it
- not met
window_total_eur > 10,0009,494.03 - met
max_single_txn <= 10,0009,494.03 - not met
txn_count_in_window >= 21
Screen 1, large transactiondoes not flag it
- not met
amount_eur > 15,0009,494.03
Screen 3, rapid movementdoes not flag it
- met
this row is a depositdeposit - not met
the next row is a transferdeposit - not met
within 3,600 seconds2 h 36 min
deposit108,726.00 SEK 9,700.53 EUR
Screen 2, structuringflags this row
- met
window_total_eur > 10,00019,194.57 - met
max_single_txn <= 10,0009,700.53 - met
txn_count_in_window >= 22
Screen 1, large transactiondoes not flag it
- not met
amount_eur > 15,0009,700.53
Screen 3, rapid movementdoes not flag it
- met
this row is a depositdeposit - not met
the next row is a transferdeposit - not met
within 3,600 seconds1 h 18 min
deposit100,752.19 SEK 8,989.11 EUR
Screen 2, structuringflags this row
- met
window_total_eur > 10,00028,183.68 - met
max_single_txn <= 10,0009,700.53 - met
txn_count_in_window >= 23
Screen 1, large transactiondoes not flag it
- not met
amount_eur > 15,0008,989.11
Screen 3, rapid movementdoes not flag it
- met
this row is a depositdeposit - not met
the next row is a transferdeposit - not met
within 3,600 seconds2 h 32 min
deposit107,182.96 SEK 9,562.86 EUR
Screen 2, structuringflags this row
- met
window_total_eur > 10,00037,746.54 - met
max_single_txn <= 10,0009,700.53 - met
txn_count_in_window >= 24
Screen 1, large transactiondoes not flag it
- not met
amount_eur > 15,0009,562.86
Screen 3, rapid movementflags this row
- met
this row is a depositdeposit - met
the next row is a transfertransfer - met
within 3,600 seconds40 min
transfer403,498.80 SEK 36,000.16 EUR
Screen 2, structuringdoes not flag it
- met
window_total_eur > 10,00073,746.70 - not met
max_single_txn <= 10,00036,000.16 - met
txn_count_in_window >= 25
Screen 1, large transactionflags this row
- met
amount_eur > 15,00036,000.16
Screen 3, rapid movementdoes not flag it
- not met
this row is a deposittransfer - not met
the next row is a transfercard purchase - not met
within 3,600 seconds2 h 39 min
card purchase220.46 SEK 19.67 EUR
Screen 2, structuringdoes not flag it
- met
window_total_eur > 10,00073,766.37 - not met
max_single_txn <= 10,00036,000.16 - met
txn_count_in_window >= 26
Screen 1, large transactiondoes not flag it
- not met
amount_eur > 15,00019.67
Screen 3, rapid movementdoes not flag it
- not met
this row is a depositcard purchase - not met
the next row is a transferno next row in the 30 days - not met
within 3,600 seconds
payment815.55 NOK 68.25 EUR
Screen 2, structuringdoes not flag it
- not met
window_total_eur > 10,00068.25 - met
max_single_txn <= 10,00068.25 - not met
txn_count_in_window >= 21
Screen 1, large transactiondoes not flag it
- not met
amount_eur > 15,00068.25
Screen 3, rapid movementdoes not flag it
- not met
this row is a depositpayment - not met
the next row is a transfercard purchase - not met
within 3,600 seconds18 days
card purchase628.63 NOK 52.15 EUR
Screen 2, structuringdoes not flag it
- not met
window_total_eur > 10,00052.15 - met
max_single_txn <= 10,00052.15 - not met
txn_count_in_window >= 21
Screen 1, large transactiondoes not flag it
- not met
amount_eur > 15,00052.15
Screen 3, rapid movementdoes not flag it
- not met
this row is a depositcard purchase - not met
the next row is a transferdeposit - not met
within 3,600 seconds3 days
deposit119,229.34 NOK 9,891.74 EUR
Screen 2, structuringdoes not flag it
- not met
window_total_eur > 10,0009,891.74 - met
max_single_txn <= 10,0009,891.74 - not met
txn_count_in_window >= 21
Screen 1, large transactiondoes not flag it
- not met
amount_eur > 15,0009,891.74
Screen 3, rapid movementdoes not flag it
- met
this row is a depositdeposit - not met
the next row is a transferdeposit - not met
within 3,600 seconds3 h 42 min
deposit111,250.83 NOK 9,229.81 EUR
Screen 2, structuringflags this row
- met
window_total_eur > 10,00019,121.56 - met
max_single_txn <= 10,0009,891.74 - met
txn_count_in_window >= 22
Screen 1, large transactiondoes not flag it
- not met
amount_eur > 15,0009,229.81
Screen 3, rapid movementdoes not flag it
- met
this row is a depositdeposit - not met
the next row is a transferdeposit - not met
within 3,600 seconds4 h 43 min
deposit117,863.33 NOK 9,778.41 EUR
Screen 2, structuringflags this row
- met
window_total_eur > 10,00028,899.97 - met
max_single_txn <= 10,0009,891.74 - met
txn_count_in_window >= 23
Screen 1, large transactiondoes not flag it
- not met
amount_eur > 15,0009,778.41
Screen 3, rapid movementdoes not flag it
- met
this row is a depositdeposit - met
the next row is a transfertransfer - not met
within 3,600 seconds5 h 56 min
transfer335,554.60 NOK 27,838.95 EUR
Screen 2, structuringdoes not flag it
- met
window_total_eur > 10,00056,738.92 - not met
max_single_txn <= 10,00027,838.95 - met
txn_count_in_window >= 24
Screen 1, large transactionflags this row
- met
amount_eur > 15,00027,838.95
Screen 3, rapid movementdoes not flag it
- not met
this row is a deposittransfer - not met
the next row is a transfercard purchase - not met
within 3,600 seconds5 days
card purchase1,012.88 NOK 84.03 EUR
Screen 2, structuringdoes not flag it
- not met
window_total_eur > 10,00084.03 - met
max_single_txn <= 10,00084.03 - not met
txn_count_in_window >= 21
Screen 1, large transactiondoes not flag it
- not met
amount_eur > 15,00084.03
Screen 3, rapid movementdoes not flag it
- not met
this row is a depositcard purchase - not met
the next row is a transferno next row in the 30 days - not met
within 3,600 seconds
withdrawal272.62 DKK 36.32 EUR
Screen 2, structuringdoes not flag it
- not met
window_total_eur > 10,00036.32 - met
max_single_txn <= 10,00036.32 - not met
txn_count_in_window >= 21
Screen 1, large transactiondoes not flag it
- not met
amount_eur > 15,00036.32
Screen 3, rapid movementdoes not flag it
- not met
this row is a depositwithdrawal - not met
the next row is a transfercard purchase - not met
within 3,600 seconds3 days
card purchase545.26 DKK 71.93 EUR
Screen 2, structuringdoes not flag it
- not met
window_total_eur > 10,00071.93 - met
max_single_txn <= 10,00071.93 - not met
txn_count_in_window >= 21
Screen 1, large transactiondoes not flag it
- not met
amount_eur > 15,00071.93
Screen 3, rapid movementdoes not flag it
- not met
this row is a depositcard purchase - not met
the next row is a transferdeposit - not met
within 3,600 seconds16 h 36 min
deposit70,712.99 DKK 9,328.88 EUR
Screen 2, structuringdoes not flag it
- not met
window_total_eur > 10,0009,400.82 - met
max_single_txn <= 10,0009,328.88 - met
txn_count_in_window >= 22
Screen 1, large transactiondoes not flag it
- not met
amount_eur > 15,0009,328.88
Screen 3, rapid movementdoes not flag it
- met
this row is a depositdeposit - not met
the next row is a transferdeposit - not met
within 3,600 seconds2 h 25 min
deposit73,030.27 DKK 9,634.59 EUR
Screen 2, structuringflags this row
- met
window_total_eur > 10,00019,035.41 - met
max_single_txn <= 10,0009,634.59 - met
txn_count_in_window >= 23
Screen 1, large transactiondoes not flag it
- not met
amount_eur > 15,0009,634.59
Screen 3, rapid movementdoes not flag it
- met
this row is a depositdeposit - not met
the next row is a transferdeposit - not met
within 3,600 seconds2 h 20 min
deposit69,162.12 DKK 9,124.28 EUR
Screen 2, structuringflags this row
- met
window_total_eur > 10,00028,159.69 - met
max_single_txn <= 10,0009,634.59 - met
txn_count_in_window >= 24
Screen 1, large transactiondoes not flag it
- not met
amount_eur > 15,0009,124.28
Screen 3, rapid movementdoes not flag it
- met
this row is a depositdeposit - not met
the next row is a transferdeposit - not met
within 3,600 seconds14 days
deposit72,753.75 DKK 9,598.11 EUR
Screen 2, structuringdoes not flag it
- not met
window_total_eur > 10,0009,598.11 - met
max_single_txn <= 10,0009,598.11 - not met
txn_count_in_window >= 21
Screen 1, large transactiondoes not flag it
- not met
amount_eur > 15,0009,598.11
Screen 3, rapid movementdoes not flag it
- met
this row is a depositdeposit - not met
the next row is a transferdeposit - not met
within 3,600 seconds1 h 35 min
deposit70,835.10 DKK 9,344.99 EUR
Screen 2, structuringflags this row
- met
window_total_eur > 10,00018,943.10 - met
max_single_txn <= 10,0009,598.11 - met
txn_count_in_window >= 22
Screen 1, large transactiondoes not flag it
- not met
amount_eur > 15,0009,344.99
Screen 3, rapid movementdoes not flag it
- met
this row is a depositdeposit - not met
the next row is a transferdeposit - not met
within 3,600 seconds2 h 41 min
deposit73,812.30 DKK 9,737.76 EUR
Screen 2, structuringflags this row
- met
window_total_eur > 10,00028,680.86 - met
max_single_txn <= 10,0009,737.76 - met
txn_count_in_window >= 23
Screen 1, large transactiondoes not flag it
- not met
amount_eur > 15,0009,737.76
Screen 3, rapid movementflags this row
- met
this row is a depositdeposit - met
the next row is a transfertransfer - met
within 3,600 seconds25 min
transfer204,868.45 DKK 27,027.48 EUR
Screen 2, structuringdoes not flag it
- met
window_total_eur > 10,00055,708.34 - not met
max_single_txn <= 10,00027,027.48 - met
txn_count_in_window >= 24
Screen 1, large transactionflags this row
- met
amount_eur > 15,00027,027.48
Screen 3, rapid movementdoes not flag it
- not met
this row is a deposittransfer - not met
the next row is a transferno next row in the 30 days - not met
within 3,600 seconds
deposit 9,378.24 EUR
Screen 2, structuringdoes not flag it
- not met
window_total_eur > 10,0009,378.24 - met
max_single_txn <= 10,0009,378.24 - not met
txn_count_in_window >= 21
Screen 1, large transactiondoes not flag it
- not met
amount_eur > 15,0009,378.24
Screen 3, rapid movementdoes not flag it
- met
this row is a depositdeposit - not met
the next row is a transferdeposit - not met
within 3,600 seconds10 h 15 min
deposit 9,173.48 EUR
Screen 2, structuringflags this row
- met
window_total_eur > 10,00018,551.72 - met
max_single_txn <= 10,0009,378.24 - met
txn_count_in_window >= 22
Screen 1, large transactiondoes not flag it
- not met
amount_eur > 15,0009,173.48
Screen 3, rapid movementdoes not flag it
- met
this row is a depositdeposit - not met
the next row is a transferno next row in the 30 days - not met
within 3,600 seconds
The query
-- Screen 2: Structuring Detection
-- Identify customers whose rolling 24-hour transaction total exceeds 10,000 EUR
-- while no single transaction exceeds 10,000 EUR — classic structuring behavior.
-- Amounts in EUR at the rate of the transaction's month (inverse_rate: EUR per unit).
WITH txn_with_eur AS (
SELECT
a.customer_id,
c.customer_name,
t.transaction_id,
t.event_timestamp,
t.amount * fx.inverse_rate AS amount_eur
FROM core_banking.transactions t
INNER JOIN core_banking.accounts a
ON t.account_id = a.account_id
INNER JOIN core_banking.customers c
ON a.customer_id = c.customer_id
LEFT JOIN core_banking.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(), 30)
),
rolling_windows AS (
SELECT
customer_id,
customer_name,
transaction_id,
event_timestamp,
amount_eur,
SUM(amount_eur) OVER (
PARTITION BY customer_id
ORDER BY event_timestamp
RANGE BETWEEN INTERVAL 24 HOURS PRECEDING AND CURRENT ROW
) AS window_total_eur,
COUNT(*) OVER (
PARTITION BY customer_id
ORDER BY event_timestamp
RANGE BETWEEN INTERVAL 24 HOURS PRECEDING AND CURRENT ROW
) AS txn_count_in_window,
MAX(amount_eur) OVER (
PARTITION BY customer_id
ORDER BY event_timestamp
RANGE BETWEEN INTERVAL 24 HOURS PRECEDING AND CURRENT ROW
) AS max_single_txn
FROM txn_with_eur
)
SELECT DISTINCT
customer_id,
customer_name,
ROUND(window_total_eur, 2) AS window_total_eur,
txn_count_in_window,
ROUND(max_single_txn, 2) AS max_single_txn,
'STRUCTURING: Rolling 24h sum exceeds 10,000 EUR with no single txn over threshold' AS alert_reason
FROM rolling_windows
WHERE window_total_eur > 10000
AND max_single_txn <= 10000
AND txn_count_in_window >= 2
ORDER BY window_total_eur DESCAML screening rules and their thresholds
A threshold decides how much work lands on the compliance team each morning, and which of the customers worth a look it reaches. The same 30 days of transactions give very different queues depending on which rule reads them.
a row of a customer Screen 2 flagsany other row
38 rows in 30 days, 3 of them by the four structuring customers, out of 84,771 transactions by 34,027 customers.
10 rows in 30 days, 10 of them by the four structuring customers, out of 84,771 transactions by 34,027 customers.
8 rows in 30 days, 2 of them by the four structuring customers, out of 84,771 transactions by 34,027 customers.
2 rows in 30 days, 0 of them by the four structuring customers, out of 84,771 transactions by 34,027 customers.
4 rows in 30 days, 4 of them by the four structuring customers, out of 84,771 transactions by 34,027 customers.
The queries and the tables
-- Screen 1: Large Transaction Detection
-- Flag all transactions exceeding 15,000 EUR equivalent.
-- exchange_rates holds one rate per currency and month: inverse_rate is EUR per unit of the currency.
WITH latest_scores AS (
SELECT
customer_id,
fraud_risk_score,
ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY score_date DESC) AS rn
FROM core_banking.customer_risk_scores
)
SELECT
t.transaction_id,
a.customer_id,
c.customer_name,
ROUND(t.amount * fx.inverse_rate, 2) AS amount_eur,
t.amount,
t.currency,
c.country,
t.channel,
c.risk_tier,
ls.fraud_risk_score,
t.event_date,
t.transaction_type
FROM core_banking.transactions t
INNER JOIN core_banking.accounts a
ON t.account_id = a.account_id
INNER JOIN core_banking.customers c
ON a.customer_id = c.customer_id
LEFT JOIN core_banking.exchange_rates fx
ON t.currency = fx.currency
AND fx.base_currency = 'EUR'
AND fx.rate_date = trunc(t.event_date, 'MM')
LEFT JOIN latest_scores ls
ON a.customer_id = ls.customer_id
AND ls.rn = 1
WHERE t.amount * fx.inverse_rate > 15000
AND t.event_date >= date_sub(current_date(), 30)
ORDER BY amount_eur DESC-- Screen 3: Rapid Movement Detection
-- Find deposit-then-transfer patterns within a 1-hour window for the same customer.
WITH ordered_txns AS (
SELECT
a.customer_id,
c.customer_name,
t.transaction_id,
t.transaction_type,
t.amount * fx.inverse_rate AS amount_eur,
t.event_timestamp,
LEAD(t.transaction_id) OVER (
PARTITION BY a.customer_id ORDER BY t.event_timestamp
) AS next_txn_id,
LEAD(t.transaction_type) OVER (
PARTITION BY a.customer_id ORDER BY t.event_timestamp
) AS next_txn_type,
LEAD(t.amount * fx.inverse_rate) OVER (
PARTITION BY a.customer_id ORDER BY t.event_timestamp
) AS next_amount_eur,
LEAD(t.event_timestamp) OVER (
PARTITION BY a.customer_id ORDER BY t.event_timestamp
) AS next_txn_date
FROM core_banking.transactions t
INNER JOIN core_banking.accounts a
ON t.account_id = a.account_id
INNER JOIN core_banking.customers c
ON a.customer_id = c.customer_id
LEFT JOIN core_banking.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(), 30)
)
SELECT
customer_id,
customer_name,
transaction_id AS deposit_txn_id,
ROUND(amount_eur, 2) AS deposit_amount_eur,
next_txn_id AS transfer_txn_id,
ROUND(next_amount_eur, 2) AS transfer_amount_eur,
ROUND(
(unix_timestamp(next_txn_date) - unix_timestamp(event_timestamp)) / 60.0, 1
) AS time_gap_minutes
FROM ordered_txns
WHERE transaction_type = 'deposit'
AND next_txn_type = 'transfer'
AND (unix_timestamp(next_txn_date) - unix_timestamp(event_timestamp)) <= 3600
AND (unix_timestamp(next_txn_date) - unix_timestamp(event_timestamp)) > 0
ORDER BY time_gap_minutes ASC-- Screen 4: Geographic Anomalies
-- Customers transacting in more than 3 distinct countries within a 7-day window.
-- Spark has no COUNT(DISTINCT) over a window frame: the size of the set of countries in the frame is the same count.
WITH latest_scores AS (
SELECT
customer_id,
fraud_risk_score,
ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY score_date DESC) AS rn
FROM core_banking.customer_risk_scores
),
geo_activity AS (
SELECT
a.customer_id,
c.customer_name,
t.event_date,
t.country AS txn_country,
size(collect_set(t.country) OVER (
PARTITION BY a.customer_id
ORDER BY t.event_timestamp
RANGE BETWEEN INTERVAL 7 DAYS PRECEDING AND CURRENT ROW
)) AS distinct_countries_7d,
ls.fraud_risk_score
FROM core_banking.transactions t
INNER JOIN core_banking.accounts a
ON t.account_id = a.account_id
INNER JOIN core_banking.customers c
ON a.customer_id = c.customer_id
LEFT JOIN latest_scores ls
ON a.customer_id = ls.customer_id
AND ls.rn = 1
WHERE t.event_date >= date_sub(current_date(), 30)
),
flagged AS (
SELECT
customer_id,
customer_name,
MAX(distinct_countries_7d) AS max_countries_in_7d,
AVG(fraud_risk_score) AS avg_fraud_risk_score,
COUNT(*) AS total_transactions,
MIN(event_date) AS first_flagged_date,
MAX(event_date) AS last_flagged_date
FROM geo_activity
WHERE distinct_countries_7d > 3
GROUP BY customer_id, customer_name
)
SELECT
customer_id,
customer_name,
max_countries_in_7d,
ROUND(avg_fraud_risk_score, 3) AS avg_fraud_risk_score,
total_transactions,
first_flagged_date,
last_flagged_date
FROM flagged
ORDER BY max_countries_in_7d DESC, avg_fraud_risk_score DESCWITH txn_with_eur AS (
SELECT
t.transaction_id,
t.account_id,
a.customer_id,
t.amount,
t.currency,
t.transaction_type,
t.channel,
t.event_timestamp,
t.event_date,
t.country AS txn_country,
c.country AS customer_country,
c.customer_name,
c.risk_tier,
t.amount * er.inverse_rate AS amount_eur
FROM core_banking.transactions t
INNER JOIN core_banking.accounts a
ON t.account_id = a.account_id
INNER JOIN core_banking.customers c
ON a.customer_id = c.customer_id
-- the rate of the transaction's month; inverse_rate is EUR per unit of the currency
LEFT JOIN core_banking.exchange_rates er
ON t.currency = er.currency
AND er.base_currency = 'EUR'
AND er.rate_date = trunc(t.event_date, 'MM')
WHERE t.status = 'completed'
),
-- Pattern 1: Structuring - multiple transactions just below 10,000 EUR on the same day
structuring_candidates AS (
SELECT
customer_id,
customer_name,
customer_country,
risk_tier,
event_date AS txn_date,
COUNT(*) AS txn_count_near_threshold,
ROUND(SUM(amount_eur), 2) AS total_amount_eur,
ROUND(AVG(amount_eur), 2) AS avg_amount_eur,
'STRUCTURING' AS pattern_type
FROM txn_with_eur
WHERE amount_eur BETWEEN 8000 AND 9999
GROUP BY customer_id, customer_name, customer_country, risk_tier, event_date
HAVING COUNT(*) >= 2
),
-- Pattern 2: Rapid movement - deposit followed by immediate transfer within same day
rapid_movement AS (
SELECT
a.customer_id,
a.customer_name,
a.customer_country,
a.risk_tier,
a.event_date AS txn_date,
COUNT(DISTINCT a.transaction_id) AS deposit_count,
COUNT(DISTINCT b.transaction_id) AS subsequent_transfer_count,
ROUND(SUM(DISTINCT a.amount_eur), 2) AS total_deposits_eur,
ROUND(SUM(DISTINCT b.amount_eur), 2) AS total_transfers_eur,
'RAPID_MOVEMENT' AS pattern_type
FROM txn_with_eur a
INNER JOIN txn_with_eur b
ON a.customer_id = b.customer_id
AND a.transaction_type = 'deposit'
AND b.transaction_type = 'transfer'
AND a.event_date = b.event_date
AND b.event_timestamp >= a.event_timestamp
AND a.transaction_id != b.transaction_id
WHERE a.amount_eur > 5000
GROUP BY a.customer_id, a.customer_name, a.customer_country, a.risk_tier, a.event_date
),
-- Pattern 3: High-risk corridor activity - unusual cross-border patterns
high_risk_corridors AS (
SELECT
customer_id,
customer_name,
customer_country,
risk_tier,
txn_country,
COUNT(*) AS corridor_txn_count,
ROUND(SUM(amount_eur), 2) AS corridor_volume_eur,
COUNT(DISTINCT event_date) AS active_days,
'HIGH_RISK_CORRIDOR' AS pattern_type
FROM txn_with_eur
WHERE customer_country != txn_country
GROUP BY customer_id, customer_name, customer_country, risk_tier, txn_country
HAVING SUM(amount_eur) > 50000 OR COUNT(*) > 20
)
-- Combine all patterns
SELECT
pattern_type,
customer_id,
customer_name,
customer_country,
risk_tier,
txn_count_near_threshold AS event_count,
total_amount_eur,
avg_amount_eur,
txn_date AS detection_date,
CASE
WHEN risk_tier = 'high' THEN 'CRITICAL'
WHEN txn_count_near_threshold >= 4 THEN 'CRITICAL'
WHEN txn_count_near_threshold >= 3 THEN 'HIGH'
ELSE 'MEDIUM'
END AS alert_severity
FROM structuring_candidates
UNION ALL
SELECT
pattern_type,
customer_id,
customer_name,
customer_country,
risk_tier,
subsequent_transfer_count AS event_count,
total_deposits_eur AS total_amount_eur,
ROUND(total_deposits_eur / NULLIF(deposit_count, 0), 2) AS avg_amount_eur,
txn_date AS detection_date,
CASE
WHEN risk_tier = 'high' THEN 'CRITICAL'
WHEN total_deposits_eur > 50000 THEN 'CRITICAL'
ELSE 'HIGH'
END AS alert_severity
FROM rapid_movement
UNION ALL
SELECT
pattern_type,
customer_id,
customer_name,
customer_country,
risk_tier,
corridor_txn_count AS event_count,
corridor_volume_eur AS total_amount_eur,
ROUND(corridor_volume_eur / corridor_txn_count, 2) AS avg_amount_eur,
CURRENT_DATE AS detection_date,
CASE
WHEN risk_tier = 'high' THEN 'CRITICAL'
WHEN corridor_volume_eur > 100000 THEN 'CRITICAL'
ELSE 'HIGH'
END AS alert_severity
FROM high_risk_corridors
ORDER BY
CASE alert_severity
WHEN 'CRITICAL' THEN 1
WHEN 'HIGH' THEN 2
WHEN 'MEDIUM' THEN 3
ELSE 4
END,
total_amount_eur DESCcore_banking.transactionsCore transaction fact table. All payment, transfer, withdrawal, deposit, and card transactions across all markets.Partitioned by event_month and country.transaction_id | Unique transaction reference (format: TXN-XXXXXXXXXXXX) |
|---|---|
account_id | Originating account FK |
counterparty_id | Receiving/counterparty account FK |
transaction_type | Transaction category: payment, transfer, withdrawal, deposit, card_purchase |
amount | Transaction amount in account currency |
currency | Transaction currency |
country | Country where transaction originated |
event_timestamp | Exact timestamp of transaction processing |
event_date | Date component of event_timestamp |
status | Processing status: completed, pending, failed, reversed |
channel | Origination channel: mobile_app, online_banking, pos_terminal, atm, branch |
core_banking.accountsAll bank accounts across checking, savings, business, mortgage, investment, and pension products.account_id | Unique account identifier (format: ACCT-XXXXXXXXXX) |
|---|---|
customer_id | FK to customers table |
account_type | Product type: checking, savings, business, mortgage, investment, pension |
currency | Account currency |
status | Account status: active, frozen, closed |
current_balance | Current ledger balance in account currency |
core_banking.customersCore customer dimension. One row per retail or corporate customer across all markets.customer_id | Unique customer identifier (format: CUST-XXXXXXXX) |
|---|---|
customer_name | Full legal name of the customer |
country | ISO 2-letter country code of customer domicile |
segment | Customer segmentation tier: retail, premium, private_banking, corporate |
risk_tier | KYC risk classification: low, medium, high |
status | Current relationship status: active, dormant, closed |
core_banking.customer_risk_scoresWritten by banking-monthly-risk on the 1st: one row per active customer and month.Partitioned by score_date.customer_id | The customer scored |
|---|---|
score_date | The 1st of the month scored |
credit_risk_score | Between 0 and 1 |
fraud_risk_score | Between 0 and 1 |
txn_count_90d | Transactions in the 90 days before |
offhours_txn_count_90d | Of them, before 06:00 or after 22:00 |
core_banking.exchange_ratesMonthly EUR-base exchange rates for supported currencies. Used for cross-currency reporting and normalization.The screens join the rate of the transaction’s month and multiply by inverse_rate.rate_date | First day of the month this rate applies to |
|---|---|
currency | Currency code |
rate | Units of currency per 1 EUR |
inverse_rate | EUR per 1 unit of currency |
| Screen | Threshold | Rationale |
|---|---|---|
| Large Transaction | > 15,000 EUR | EU reporting threshold |
| Structuring | Multiple txns summing > 10,000 EUR within 24h | Deliberate avoidance of reporting limits |
| Rapid Movement | Deposit-to-transfer < 1 hour | Layering indicator |
| Off-hours Activity | 23:00 to 05:00 local time | Unusual behavioral pattern |
| Multi-country | > 3 countries in 7 days | Geographic dispersion anomaly |
Alert severity, review deadlines and the case flow
Every alert gets a risk level, and the level sets how long compliance has to look at it. The level of a large transaction depends on more than its amount.
CRITICALreviewed within 4 hoursHead of Compliance, at once
none of the 30 days landed here
HIGHreviewed within 24 hoursSenior Compliance Analyst
1 of the 30 days’ large transactions landed here
MEDIUMreviewed within 72 hoursCompliance Analyst
37 of the 30 days’ large transactions landed here
The query and the review process
-- Consolidated Alert Summary
-- Aggregate all screening results into a priority-ranked alert dashboard.
-- Each alert type applies the rule of its screen above to the same 30 days.
WITH txn_eur AS (
SELECT
t.transaction_id,
a.customer_id,
t.transaction_type,
t.country,
t.event_timestamp,
t.amount * fx.inverse_rate AS amount_eur
FROM core_banking.transactions t
INNER JOIN core_banking.accounts a
ON t.account_id = a.account_id
LEFT JOIN core_banking.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(), 30)
),
latest_scores AS (
SELECT
customer_id,
fraud_risk_score,
ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY score_date DESC) AS rn
FROM core_banking.customer_risk_scores
),
large_txn_alerts AS (
SELECT
'LARGE_TRANSACTION' AS alert_type,
te.customer_id,
CASE
WHEN ls.fraud_risk_score > 0.7 THEN 'CRITICAL'
WHEN HOUR(te.event_timestamp) >= 23
OR HOUR(te.event_timestamp) < 5 THEN 'HIGH'
ELSE 'MEDIUM'
END AS risk_level
FROM txn_eur te
LEFT JOIN latest_scores ls
ON te.customer_id = ls.customer_id
AND ls.rn = 1
WHERE te.amount_eur > 15000
),
structuring_alerts AS (
SELECT
'STRUCTURING' AS alert_type,
w.customer_id,
CASE
WHEN MAX(ls.fraud_risk_score) > 0.5 THEN 'CRITICAL'
ELSE 'HIGH'
END AS risk_level
FROM (
SELECT
customer_id,
SUM(amount_eur) OVER (
PARTITION BY customer_id
ORDER BY event_timestamp
RANGE BETWEEN INTERVAL 24 HOURS PRECEDING AND CURRENT ROW
) AS window_total_eur,
MAX(amount_eur) OVER (
PARTITION BY customer_id
ORDER BY event_timestamp
RANGE BETWEEN INTERVAL 24 HOURS PRECEDING AND CURRENT ROW
) AS max_single_txn,
COUNT(*) OVER (
PARTITION BY customer_id
ORDER BY event_timestamp
RANGE BETWEEN INTERVAL 24 HOURS PRECEDING AND CURRENT ROW
) AS txn_count_in_window
FROM txn_eur
) w
LEFT JOIN latest_scores ls
ON w.customer_id = ls.customer_id
AND ls.rn = 1
WHERE w.window_total_eur > 10000
AND w.max_single_txn <= 10000
AND w.txn_count_in_window >= 2
GROUP BY w.customer_id
),
rapid_movement_alerts AS (
SELECT DISTINCT
'RAPID_MOVEMENT' AS alert_type,
customer_id,
'MEDIUM' AS risk_level
FROM (
SELECT
customer_id,
transaction_type,
event_timestamp,
LEAD(transaction_type) OVER (
PARTITION BY customer_id ORDER BY event_timestamp
) AS next_txn_type,
LEAD(event_timestamp) OVER (
PARTITION BY customer_id ORDER BY event_timestamp
) AS next_txn_date
FROM txn_eur
) o
WHERE transaction_type = 'deposit'
AND next_txn_type = 'transfer'
AND (unix_timestamp(next_txn_date) - unix_timestamp(event_timestamp)) <= 3600
AND (unix_timestamp(next_txn_date) - unix_timestamp(event_timestamp)) > 0
),
geo_alerts AS (
SELECT DISTINCT
'GEOGRAPHIC_ANOMALY' AS alert_type,
customer_id,
'LOW' AS risk_level
FROM (
SELECT
customer_id,
size(collect_set(country) OVER (
PARTITION BY customer_id
ORDER BY event_timestamp
RANGE BETWEEN INTERVAL 7 DAYS PRECEDING AND CURRENT ROW
)) AS distinct_countries_7d
FROM txn_eur
) g
WHERE distinct_countries_7d > 3
),
all_alerts AS (
SELECT * FROM large_txn_alerts
UNION ALL
SELECT * FROM structuring_alerts
UNION ALL
SELECT * FROM rapid_movement_alerts
UNION ALL
SELECT * FROM geo_alerts
)
SELECT
alert_type,
risk_level,
COUNT(*) AS alert_count,
COUNT(DISTINCT customer_id) AS unique_customers
FROM all_alerts
GROUP BY alert_type, risk_level
ORDER BY
CASE risk_level
WHEN 'CRITICAL' THEN 1
WHEN 'HIGH' THEN 2
WHEN 'MEDIUM' THEN 3
WHEN 'LOW' THEN 4
END,
alert_count DESC| Risk level | Review within | Goes to |
|---|---|---|
| CRITICAL | 4 hours | Head of Compliance, at once |
| HIGH | 24 hours | Senior Compliance Analyst |
| MEDIUM | 72 hours | Compliance Analyst |
| LOW | 5 business days | Automated review and a spot check |
How to run AML screening on Ilum, step by step
Six steps from an empty Kubernetes cluster to screens that run on their own and alerts compliance can read. Each uses a part of Ilum that comes with the default install.
An empty Kubernetes cluster
Alerts compliance can read
- Helm chart
Add the chart repository and install. Spark, the SQL editor, the Hive Metastore, MinIO and lineage come up in the default install, on any CNCF-compliant Kubernetes.
helm repo add ilum https://charts.ilum.cloud helm install ilum ilum/ilum - Spark
A Spark job reads the exports of your core banking system from S3, GCS, Azure Blob or HDFS and writes
transactions,accountsandcustomersinto the databasecore_banking, as Delta tables by default. - SQL editor
In the SQL editor, create a notebook in a folder such as
Banking/Complianceand give each screen a statement of its own. Each runs on Spark SQL and shows its rows under it. - Schedules
Put the screens into a PySpark job that calls
spark.sqland writes the alerts to a table, then schedule it on a five-field cron,*/15 * * * *for every 15 minutes. A schedule is a Kubernetes CronJob, and a failed run starts again until its retries are used. How a schedule fires. - Roles
A
COMPLIANCE_OFFICERrole holds SQL_EXECUTE, SQLNOTEBOOK_READ, LINEAGE_READ and EVENTLOG_READ_ALL, and neither JOB_CREATE nor SCHEDULE_CREATE: it runs the screens, reads every user’s Event Log and changes no pipeline. Tag customer names PII. A PCI DSS data lake keeps cardholder data in scope with the same tags and roles. - Lineage
Open the alerts table in Lineage: the OpenLineage listener Ilum adds to every Spark job records which tables the job read and which it wrote, down to columns. How lineage works.
Questions and answers
What is structuring in AML, and how do you detect it in SQL?
Structuring splits money into transactions that each stay under a reporting threshold. Sum each customer’s transactions over a rolling 24 hours with a window function and flag a window over 10,000 EUR in which no single transaction passes 10,000 and there are at least two.
How do I compute a rolling 24-hour sum per customer in Spark SQL?
Use SUM(amount) OVER (PARTITION BY customer_id ORDER BY event_timestamp RANGE BETWEEN INTERVAL 24 HOURS PRECEDING AND CURRENT ROW). RANGE takes every row in the 24 hours, however many. COUNT(*) and MAX over the same frame give the count and the largest transaction.
Which rules does AML transaction monitoring start with?
Single transactions over 15,000 EUR, structuring over 10,000 EUR in 24 hours, a deposit moved on as a transfer within an hour, activity between 23:00 and 05:00, and more than three countries in a week. Each alert then gets a risk level and a review deadline.
Can AML transaction monitoring run on premises?
Yes. Ilum installs with Helm on any CNCF-compliant Kubernetes, bare metal, OpenShift and Rancher included, and the screens are SQL over tables in the object storage you give it, MinIO by default. Transactions never leave your cluster.
How often should AML screens run?
As often as your review deadlines need. CRITICAL alerts are reviewed within 4 hours, so a schedule every 15 minutes leaves room. In Ilum a schedule is a five-field cron that runs a Spark job as a Kubernetes CronJob. How a schedule fires.
Who should see AML alerts, and how is that enforced?
The compliance group, through a role that may run SQL and read notebooks and lineage but not create jobs or schedules. Tags mark personal data on the tables. Masking customer names for other roles takes Apache Ranger, an Enterprise module.
How do you convert transactions to EUR before an AML threshold applies?
Join each transaction to the exchange rate of its month and multiply by the rate that gives EUR per unit of its currency. The screens compare the converted amount, so a 106,411.49 SEK deposit counts as 9,494.03 EUR, under the 10,000 line.
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.
