Skip to content

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.

Customer

PARTITION BY customer_id ORDER BY event_timestampPick a row: the window ends at it.

CUST-00003536
CUST-00016047
CUST-00015509
CUST-00016851

the screens’ 30 daysUTC

24 hours PRECEDING AND CURRENT ROW24 hours+1 h+1 h+1 h+1 h+1 h+1 h+1 h+1 h+1 h+1 h+1 h+1 h+1 h+1 h+1 h10,00015,000
54.5034.796.339,494.039,700.539,700.538,989.118,989.119,562.869,562.8636,000.1636,000.1619.67
68.2552.159,891.749,229.819,229.819,778.419,778.4127,838.9527,838.9584.03
36.3271.939,328.889,634.599,634.599,124.289,124.289,598.119,598.119,344.999,344.999,737.769,737.7627,027.4827,027.48
9,378.249,173.489,173.48
from 28 Oct 22:20from 6 Nov 01:05from 15 Nov 17:45from 22 Nov 10:12from 22 Nov 12:47from 22 Nov 14:05from 22 Nov 16:38from 22 Nov 17:18from 22 Nov 19:57from 27 Oct 22:18from 14 Nov 18:06from 17 Nov 09:20from 17 Nov 13:02from 17 Nov 17:45from 17 Nov 23:41from 22 Nov 18:13from 28 Oct 22:06from 31 Oct 18:29from 1 Nov 11:05from 1 Nov 13:30from 1 Nov 15:50from 15 Nov 10:40from 15 Nov 12:15from 15 Nov 14:55from 15 Nov 15:20from 10 Nov 21:40from 11 Nov 07:55
54.50
34.79
6.33
9,494.03
19,194.57
28,183.68
37,746.54
73,746.70
73,766.37
68.25
52.15
9,891.74
19,121.56
28,899.97
56,738.92
84.03
36.32
71.93
9,400.82
19,035.41
28,159.69
9,598.11
18,943.10
28,680.86
55,708.34
9,378.24
18,551.72
window total

card purchase609.77 SEK 54.50 EUR

Screen 2, structuringdoes not flag it

  • not metwindow_total_eur > 10,00054.50
  • metmax_single_txn <= 10,00054.50
  • not mettxn_count_in_window >= 21

Screen 1, large transactiondoes not flag it

  • not metamount_eur > 15,00054.50

Screen 3, rapid movementdoes not flag it

  • not metthis row is a depositcard purchase
  • not metthe next row is a transferpayment
  • not metwithin 3,600 seconds8 days

payment389.90 SEK 34.79 EUR

Screen 2, structuringdoes not flag it

  • not metwindow_total_eur > 10,00034.79
  • metmax_single_txn <= 10,00034.79
  • not mettxn_count_in_window >= 21

Screen 1, large transactiondoes not flag it

  • not metamount_eur > 15,00034.79

Screen 3, rapid movementdoes not flag it

  • not metthis row is a depositpayment
  • not metthe next row is a transfercard purchase
  • not metwithin 3,600 seconds10 days

card purchase70.98 SEK 6.33 EUR

Screen 2, structuringdoes not flag it

  • not metwindow_total_eur > 10,0006.33
  • metmax_single_txn <= 10,0006.33
  • not mettxn_count_in_window >= 21

Screen 1, large transactiondoes not flag it

  • not metamount_eur > 15,0006.33

Screen 3, rapid movementdoes not flag it

  • not metthis row is a depositcard purchase
  • not metthe next row is a transferdeposit
  • not metwithin 3,600 seconds7 days

deposit106,411.49 SEK 9,494.03 EUR

Screen 2, structuringdoes not flag it

  • not metwindow_total_eur > 10,0009,494.03
  • metmax_single_txn <= 10,0009,494.03
  • not mettxn_count_in_window >= 21

Screen 1, large transactiondoes not flag it

  • not metamount_eur > 15,0009,494.03

Screen 3, rapid movementdoes not flag it

  • metthis row is a depositdeposit
  • not metthe next row is a transferdeposit
  • not metwithin 3,600 seconds2 h 36 min

deposit108,726.00 SEK 9,700.53 EUR

Screen 2, structuringflags this row

  • metwindow_total_eur > 10,00019,194.57
  • metmax_single_txn <= 10,0009,700.53
  • mettxn_count_in_window >= 22

Screen 1, large transactiondoes not flag it

  • not metamount_eur > 15,0009,700.53

Screen 3, rapid movementdoes not flag it

  • metthis row is a depositdeposit
  • not metthe next row is a transferdeposit
  • not metwithin 3,600 seconds1 h 18 min

deposit100,752.19 SEK 8,989.11 EUR

Screen 2, structuringflags this row

  • metwindow_total_eur > 10,00028,183.68
  • metmax_single_txn <= 10,0009,700.53
  • mettxn_count_in_window >= 23

Screen 1, large transactiondoes not flag it

  • not metamount_eur > 15,0008,989.11

Screen 3, rapid movementdoes not flag it

  • metthis row is a depositdeposit
  • not metthe next row is a transferdeposit
  • not metwithin 3,600 seconds2 h 32 min

deposit107,182.96 SEK 9,562.86 EUR

Screen 2, structuringflags this row

  • metwindow_total_eur > 10,00037,746.54
  • metmax_single_txn <= 10,0009,700.53
  • mettxn_count_in_window >= 24

Screen 1, large transactiondoes not flag it

  • not metamount_eur > 15,0009,562.86

Screen 3, rapid movementflags this row

  • metthis row is a depositdeposit
  • metthe next row is a transfertransfer
  • metwithin 3,600 seconds40 min

transfer403,498.80 SEK 36,000.16 EUR

Screen 2, structuringdoes not flag it

  • metwindow_total_eur > 10,00073,746.70
  • not metmax_single_txn <= 10,00036,000.16
  • mettxn_count_in_window >= 25

Screen 1, large transactionflags this row

  • metamount_eur > 15,00036,000.16

Screen 3, rapid movementdoes not flag it

  • not metthis row is a deposittransfer
  • not metthe next row is a transfercard purchase
  • not metwithin 3,600 seconds2 h 39 min

card purchase220.46 SEK 19.67 EUR

Screen 2, structuringdoes not flag it

  • metwindow_total_eur > 10,00073,766.37
  • not metmax_single_txn <= 10,00036,000.16
  • mettxn_count_in_window >= 26

Screen 1, large transactiondoes not flag it

  • not metamount_eur > 15,00019.67

Screen 3, rapid movementdoes not flag it

  • not metthis row is a depositcard purchase
  • not metthe next row is a transferno next row in the 30 days
  • not metwithin 3,600 seconds

payment815.55 NOK 68.25 EUR

Screen 2, structuringdoes not flag it

  • not metwindow_total_eur > 10,00068.25
  • metmax_single_txn <= 10,00068.25
  • not mettxn_count_in_window >= 21

Screen 1, large transactiondoes not flag it

  • not metamount_eur > 15,00068.25

Screen 3, rapid movementdoes not flag it

  • not metthis row is a depositpayment
  • not metthe next row is a transfercard purchase
  • not metwithin 3,600 seconds18 days

card purchase628.63 NOK 52.15 EUR

Screen 2, structuringdoes not flag it

  • not metwindow_total_eur > 10,00052.15
  • metmax_single_txn <= 10,00052.15
  • not mettxn_count_in_window >= 21

Screen 1, large transactiondoes not flag it

  • not metamount_eur > 15,00052.15

Screen 3, rapid movementdoes not flag it

  • not metthis row is a depositcard purchase
  • not metthe next row is a transferdeposit
  • not metwithin 3,600 seconds3 days

deposit119,229.34 NOK 9,891.74 EUR

Screen 2, structuringdoes not flag it

  • not metwindow_total_eur > 10,0009,891.74
  • metmax_single_txn <= 10,0009,891.74
  • not mettxn_count_in_window >= 21

Screen 1, large transactiondoes not flag it

  • not metamount_eur > 15,0009,891.74

Screen 3, rapid movementdoes not flag it

  • metthis row is a depositdeposit
  • not metthe next row is a transferdeposit
  • not metwithin 3,600 seconds3 h 42 min

deposit111,250.83 NOK 9,229.81 EUR

Screen 2, structuringflags this row

  • metwindow_total_eur > 10,00019,121.56
  • metmax_single_txn <= 10,0009,891.74
  • mettxn_count_in_window >= 22

Screen 1, large transactiondoes not flag it

  • not metamount_eur > 15,0009,229.81

Screen 3, rapid movementdoes not flag it

  • metthis row is a depositdeposit
  • not metthe next row is a transferdeposit
  • not metwithin 3,600 seconds4 h 43 min

deposit117,863.33 NOK 9,778.41 EUR

Screen 2, structuringflags this row

  • metwindow_total_eur > 10,00028,899.97
  • metmax_single_txn <= 10,0009,891.74
  • mettxn_count_in_window >= 23

Screen 1, large transactiondoes not flag it

  • not metamount_eur > 15,0009,778.41

Screen 3, rapid movementdoes not flag it

  • metthis row is a depositdeposit
  • metthe next row is a transfertransfer
  • not metwithin 3,600 seconds5 h 56 min

transfer335,554.60 NOK 27,838.95 EUR

Screen 2, structuringdoes not flag it

  • metwindow_total_eur > 10,00056,738.92
  • not metmax_single_txn <= 10,00027,838.95
  • mettxn_count_in_window >= 24

Screen 1, large transactionflags this row

  • metamount_eur > 15,00027,838.95

Screen 3, rapid movementdoes not flag it

  • not metthis row is a deposittransfer
  • not metthe next row is a transfercard purchase
  • not metwithin 3,600 seconds5 days

card purchase1,012.88 NOK 84.03 EUR

Screen 2, structuringdoes not flag it

  • not metwindow_total_eur > 10,00084.03
  • metmax_single_txn <= 10,00084.03
  • not mettxn_count_in_window >= 21

Screen 1, large transactiondoes not flag it

  • not metamount_eur > 15,00084.03

Screen 3, rapid movementdoes not flag it

  • not metthis row is a depositcard purchase
  • not metthe next row is a transferno next row in the 30 days
  • not metwithin 3,600 seconds

withdrawal272.62 DKK 36.32 EUR

Screen 2, structuringdoes not flag it

  • not metwindow_total_eur > 10,00036.32
  • metmax_single_txn <= 10,00036.32
  • not mettxn_count_in_window >= 21

Screen 1, large transactiondoes not flag it

  • not metamount_eur > 15,00036.32

Screen 3, rapid movementdoes not flag it

  • not metthis row is a depositwithdrawal
  • not metthe next row is a transfercard purchase
  • not metwithin 3,600 seconds3 days

card purchase545.26 DKK 71.93 EUR

Screen 2, structuringdoes not flag it

  • not metwindow_total_eur > 10,00071.93
  • metmax_single_txn <= 10,00071.93
  • not mettxn_count_in_window >= 21

Screen 1, large transactiondoes not flag it

  • not metamount_eur > 15,00071.93

Screen 3, rapid movementdoes not flag it

  • not metthis row is a depositcard purchase
  • not metthe next row is a transferdeposit
  • not metwithin 3,600 seconds16 h 36 min

deposit70,712.99 DKK 9,328.88 EUR

Screen 2, structuringdoes not flag it

  • not metwindow_total_eur > 10,0009,400.82
  • metmax_single_txn <= 10,0009,328.88
  • mettxn_count_in_window >= 22

Screen 1, large transactiondoes not flag it

  • not metamount_eur > 15,0009,328.88

Screen 3, rapid movementdoes not flag it

  • metthis row is a depositdeposit
  • not metthe next row is a transferdeposit
  • not metwithin 3,600 seconds2 h 25 min

deposit73,030.27 DKK 9,634.59 EUR

Screen 2, structuringflags this row

  • metwindow_total_eur > 10,00019,035.41
  • metmax_single_txn <= 10,0009,634.59
  • mettxn_count_in_window >= 23

Screen 1, large transactiondoes not flag it

  • not metamount_eur > 15,0009,634.59

Screen 3, rapid movementdoes not flag it

  • metthis row is a depositdeposit
  • not metthe next row is a transferdeposit
  • not metwithin 3,600 seconds2 h 20 min

deposit69,162.12 DKK 9,124.28 EUR

Screen 2, structuringflags this row

  • metwindow_total_eur > 10,00028,159.69
  • metmax_single_txn <= 10,0009,634.59
  • mettxn_count_in_window >= 24

Screen 1, large transactiondoes not flag it

  • not metamount_eur > 15,0009,124.28

Screen 3, rapid movementdoes not flag it

  • metthis row is a depositdeposit
  • not metthe next row is a transferdeposit
  • not metwithin 3,600 seconds14 days

deposit72,753.75 DKK 9,598.11 EUR

Screen 2, structuringdoes not flag it

  • not metwindow_total_eur > 10,0009,598.11
  • metmax_single_txn <= 10,0009,598.11
  • not mettxn_count_in_window >= 21

Screen 1, large transactiondoes not flag it

  • not metamount_eur > 15,0009,598.11

Screen 3, rapid movementdoes not flag it

  • metthis row is a depositdeposit
  • not metthe next row is a transferdeposit
  • not metwithin 3,600 seconds1 h 35 min

deposit70,835.10 DKK 9,344.99 EUR

Screen 2, structuringflags this row

  • metwindow_total_eur > 10,00018,943.10
  • metmax_single_txn <= 10,0009,598.11
  • mettxn_count_in_window >= 22

Screen 1, large transactiondoes not flag it

  • not metamount_eur > 15,0009,344.99

Screen 3, rapid movementdoes not flag it

  • metthis row is a depositdeposit
  • not metthe next row is a transferdeposit
  • not metwithin 3,600 seconds2 h 41 min

deposit73,812.30 DKK 9,737.76 EUR

Screen 2, structuringflags this row

  • metwindow_total_eur > 10,00028,680.86
  • metmax_single_txn <= 10,0009,737.76
  • mettxn_count_in_window >= 23

Screen 1, large transactiondoes not flag it

  • not metamount_eur > 15,0009,737.76

Screen 3, rapid movementflags this row

  • metthis row is a depositdeposit
  • metthe next row is a transfertransfer
  • metwithin 3,600 seconds25 min

transfer204,868.45 DKK 27,027.48 EUR

Screen 2, structuringdoes not flag it

  • metwindow_total_eur > 10,00055,708.34
  • not metmax_single_txn <= 10,00027,027.48
  • mettxn_count_in_window >= 24

Screen 1, large transactionflags this row

  • metamount_eur > 15,00027,027.48

Screen 3, rapid movementdoes not flag it

  • not metthis row is a deposittransfer
  • not metthe next row is a transferno next row in the 30 days
  • not metwithin 3,600 seconds

deposit 9,378.24 EUR

Screen 2, structuringdoes not flag it

  • not metwindow_total_eur > 10,0009,378.24
  • metmax_single_txn <= 10,0009,378.24
  • not mettxn_count_in_window >= 21

Screen 1, large transactiondoes not flag it

  • not metamount_eur > 15,0009,378.24

Screen 3, rapid movementdoes not flag it

  • metthis row is a depositdeposit
  • not metthe next row is a transferdeposit
  • not metwithin 3,600 seconds10 h 15 min

deposit 9,173.48 EUR

Screen 2, structuringflags this row

  • metwindow_total_eur > 10,00018,551.72
  • metmax_single_txn <= 10,0009,378.24
  • mettxn_count_in_window >= 22

Screen 1, large transactiondoes not flag it

  • not metamount_eur > 15,0009,173.48

Screen 3, rapid movementdoes not flag it

  • metthis row is a depositdeposit
  • not metthe next row is a transferno next row in the 30 days
  • not metwithin 3,600 seconds

The four customers Screen 2 flags, with every transaction of the screens’ 30 days in the currency it was made in and in EUR. Pick a row: the window ends there. Four deposits of 100,752.19 to 108,726.00 SEK in one afternoon stay under 10,000 EUR each and fill the window to 37,746.54 EUR, and the 403,498.80 SEK sent on 40 minutes later is Screen 1’s and Screen 3’s. One customer paid in 9,378.24 EUR at 21:40 and 9,173.48 the next morning: each calendar day stays under 10,000, the 24 hours do not.
The query
Screen 2: Structuring DetectionNotebook Banking/Compliance/AML Screening · Spark SQL
-- 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 DESC

AML 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.

Rule

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.

Each rule’s rows over the 30 days, a square a row, the rows of the four structuring customers in cyan. The 15,000 EUR line hands over 38 transactions and reaches three of the four, through the money they sent on. Only the 24-hour window reaches all four. AML Suspicious Patterns counts deposits on one calendar day and misses the customer who paid in either side of midnight.
The queries and the tables
Screen 1: Large Transaction DetectionNotebook Banking/Compliance/AML Screening · Spark SQL
-- 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 DetectionNotebook Banking/Compliance/AML Screening · Spark SQL
-- 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 AnomaliesNotebook Banking/Compliance/AML Screening · Spark SQL
-- 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 DESC
AML Suspicious PatternsSaved query Banking/Compliance · Spark SQL
WITH 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 DESC
core_banking.transactionsCore transaction fact table. All payment, transfer, withdrawal, deposit, and card transactions across all markets.Partitioned by event_month and country.
transaction_idUnique transaction reference (format: TXN-XXXXXXXXXXXX)
account_idOriginating account FK
counterparty_idReceiving/counterparty account FK
transaction_typeTransaction category: payment, transfer, withdrawal, deposit, card_purchase
amountTransaction amount in account currency
currencyTransaction currency
countryCountry where transaction originated
event_timestampExact timestamp of transaction processing
event_dateDate component of event_timestamp
statusProcessing status: completed, pending, failed, reversed
channelOrigination channel: mobile_app, online_banking, pos_terminal, atm, branch
core_banking.accountsAll bank accounts across checking, savings, business, mortgage, investment, and pension products.
account_idUnique account identifier (format: ACCT-XXXXXXXXXX)
customer_idFK to customers table
account_typeProduct type: checking, savings, business, mortgage, investment, pension
currencyAccount currency
statusAccount status: active, frozen, closed
current_balanceCurrent ledger balance in account currency
core_banking.customersCore customer dimension. One row per retail or corporate customer across all markets.
customer_idUnique customer identifier (format: CUST-XXXXXXXX)
customer_nameFull legal name of the customer
countryISO 2-letter country code of customer domicile
segmentCustomer segmentation tier: retail, premium, private_banking, corporate
risk_tierKYC risk classification: low, medium, high
statusCurrent 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_idThe customer scored
score_dateThe 1st of the month scored
credit_risk_scoreBetween 0 and 1
fraud_risk_scoreBetween 0 and 1
txn_count_90dTransactions in the 90 days before
offhours_txn_count_90dOf 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_dateFirst day of the month this rate applies to
currencyCurrency code
rateUnits of currency per 1 EUR
inverse_rateEUR per 1 unit of currency
Screening thresholds
ScreenThresholdRationale
Large Transaction> 15,000 EUREU reporting threshold
StructuringMultiple txns summing > 10,000 EUR within 24hDeliberate avoidance of reporting limits
Rapid MovementDeposit-to-transfer < 1 hourLayering indicator
Off-hours Activity23:00 to 05:00 local timeUnusual behavioral pattern
Multi-country> 3 countries in 7 daysGeographic 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.

Hour of a transaction over 15,000 EUR

none of the 38 came in at this hour

none of the 38 came in at this hour

none of the 38 came in at this hour

none of the 38 came in at this hour

none of the 38 came in at this hour

none of the 38 came in at this hour

none of the 38 came in at this hour

3 of the 38 came in at this hour

4 of the 38 came in at this hour

2 of the 38 came in at this hour

1 of the 38 came in at this hour

4 of the 38 came in at this hour

1 of the 38 came in at this hour

1 of the 38 came in at this hour

3 of the 38 came in at this hour

2 of the 38 came in at this hour

3 of the 38 came in at this hour

2 of the 38 came in at this hour

1 of the 38 came in at this hour

5 of the 38 came in at this hour

2 of the 38 came in at this hour

1 of the 38 came in at this hour

2 of the 38 came in at this hour

1 of the 38 came in at this hour

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 summary statement’s CASE for transactions over 15,000 EUR, read as a clock, with the hours the 38 of the 30 days came in. Move the hour: at 10:00 the transaction waits up to 72 hours, at 03:00 the same one is due within 24. One came in at 23:41, the transfer a structuring customer sent on the night of the deposits, and it is the summary’s one HIGH. A fraud score over 0.7 would make any of them CRITICAL, and no customer of the 30 days had one.
The query and the review process
Consolidated Alert SummaryNotebook Banking/Compliance/AML Screening · Spark SQL
-- 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
Review deadline by risk level
Risk levelReview withinGoes to
CRITICAL4 hoursHead of Compliance, at once
HIGH24 hoursSenior Compliance Analyst
MEDIUM72 hoursCompliance Analyst
LOW5 business daysAutomated 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

  1. 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
  2. Spark

    A Spark job reads the exports of your core banking system from S3, GCS, Azure Blob or HDFS and writes transactions, accounts and customers into the database core_banking, as Delta tables by default.

  3. SQL editor

    In the SQL editor, create a notebook in a folder such as Banking/Compliance and give each screen a statement of its own. Each runs on Spark SQL and shows its rows under it.

  4. Schedules

    Put the screens into a PySpark job that calls spark.sql and 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.

  5. Roles

    A COMPLIANCE_OFFICER role 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.

  6. 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.

[email protected]

We reply within two working days.