I am building real time processing for detecting fraud ATM card transaction. in order to efficiently detect fraud, logic requires to have last transaction date by card, sum of transaction amount by day (or last 24 Hrs.)
One of usecase is if card transaction outside native country for more than a 30 days of last transaction in that country then send alert as possible fraud
So tried to look at Spark streaming as a solution. In order to achieve this (probably I am missing idea about functional programming) below is my psudo code
stream=ssc.receiverStream() //input receiver
s1=stream.mapToPair() // creates key with card and transaction date as value
s2=stream.reduceByKey() // applies reduce operation for last transaction date
s2.checkpoint(new Duration(1000));
s2.persist();
I am facing two problem here
1) how to use this last transaction date further for future comparison from same card
2) how to persist data so even if restart drive program then old values of s2 restores back
3) updateStateByKey
can used to maintain historical state?
I think I am missing key point of spark streaming/functional programming that how to implement this kind of logic.