A real-time fraud detection system for banking transactions using Apache Flink 1.13.
This application monitors bank transaction streams and flags suspicious activities based on four detection rules:
- Alarmed Customers - Transactions from customers on the alarmed list
- Lost Cards - Transactions using reported lost/stolen cards
- Excessive Transactions - More than 10 transactions within a 10-second window
- Frequent City Changes - 2+ city changes within a 10-second window
- BankDataServer.java - Socket server that streams transaction data from
bank_data.txtto port 9090 - Bank.java - Flink streaming job that processes transactions and detects fraud
- AlarmedCustomer.java - POJO for alarmed customer data
- LostCard.java - POJO for lost card data
-
bank_data.txt- Transaction data (53 transactions)- Format:
txn_id,timestamp,city,customer_id,card_id,account_number,amount - Example:
HFXR347924,2018-06-14 23:32:23,Chandigarh,id_347hfx,hf98678167,123302773033,774
- Format:
-
alarmed_cust.txt- List of customers under investigation (17 customers)- Format:
customer_id,card_id - Example:
id_576tck,tc62668365
- Format:
-
lost_cards.txt- Reported lost/stolen cards (35 cards)- Format:
account_number,timestamp,name,status - Example:
130288773617,2018-01-10 23:41:27,John,Under Process
- Format:
Based on the sample data, the following transactions should be flagged:
- id_576tck (line 4 in bank_data.txt) - Customer on alarmed list
- id_158gsb (lines 5, 10, 14) - Customer on alarmed list
- id_909ktr (line 19) - Customer on alarmed list
- Card 130288773617 (lines 6, 11 in bank_data.txt) - Card reported lost by John
- id_741yce - Has 11+ transactions in rapid succession
- id_135pfx - Has 10+ transactions
- id_741yce - Changes: Amsterdam → Paris → Amsterdam
java BankDataServerOutput: Bank Data Server started on port 9090
java BankConsole Output:
- Real-time logging of all fraud detection events
- Flagged transactions printed with
__ALARM__prefix
File Output:
- Flagged transactions saved to:
/Users/alex/javaws/bank_flink_V_1.13/flagged_transaction/ - Files are created with rolling policy (new files created periodically)
alarmed_cust.txtandlost_cards.txtare broadcast to all parallel operators- Allows efficient checking of incoming transactions against reference data
- Tumbling Windows: 10-second non-overlapping windows
- Used for excessive transaction counting and city change detection
All four fraud detection streams are merged into a single output stream for unified processing.
- Port: 9090 (configurable in both BankDataServer and Bank)
- Window Size: 10 seconds (configurable in Bank.java)
- Excessive Transaction Threshold: 10 transactions (configurable in FilterAndMapMoreThan10)
- City Change Threshold: 2 changes (configurable in Citychange)
- Java 8 or higher
- Apache Flink 1.13
- SLF4J for logging
Flagged transactions are output as Tuple2<String, String>:
f0:"__ALARM__"f1: Description of the fraud type and transaction details
Example:
(__ALARM__, Transaction: (id_576tck,TCKV576600,2018-06-14...) is by an ALARMED customer)
(__ALARM__, Transaction: (id_741yce,UXJT427774,2018-06-14...) marked for FREQUENT city changes)