RETURN TO INSIGHTS JOURNAL
INS-17 // DATA ANALYTICS13 MIN READ2026-07-24

Sub-50ms Financial Fraud Detection via Streaming Feature Engineering with Apache Flink and Redis

Detecting credit card fraud and malicious transactions in real time using stateful stream processing, sliding window aggregations, and in-memory feature stores.

AUTHOR: FINTECH LABS // XIYOR
#Apache Flink#Redis#Stream Processing#Fraud Detection#FinTech#Java

01 // THE RACE AGAINST TRANSACTION FRAUD

In global financial processing, credit card fraud evaluation is a high-stakes, time-critical engineering problem. When a customer swipes their payment card at a point-of-sale terminal, the payment gateway must authorize or decline the transaction within 200 milliseconds total round-trip time. Evaluating fraud after a transaction completes is too late—the money has already left the merchant bank account. The evaluation engine must evaluate risk during the active authorization hold window. At XIYOR, we engineer streaming financial fraud detection platforms. By pairing Apache Flink stateful event processing with Redis cluster caching, we evaluate over 50 real-time transaction features (e.g. 5-minute velocity count, geographic distance delta, high-risk merchant scores) and output risk scores in under 35 milliseconds.
"Batch fraud detection is post-mortem auditing. Real-time streaming feature engineering prevents fraud at the instant of swipe."

02 // THE APACHE FLINK STATEFUL ARCHITECTURE

Traditional databases cannot compute rolling aggregations (e.g., "count of card swipes in the last 120 seconds") across 100,000 concurrent credit cards without crushing disk I/O. Apache Flink solves this by maintaining stateful sliding window aggregations directly in RAM, backed by RocksDB incremental checkpoints for fault tolerance: 1. Ingestion Layer (Kafka): Streams raw payment authorization events into Flink processing jobs. 2. Flink Stateful Window Engine: Computes sliding temporal aggregations (e.g. sum of dollar amounts spent by cardholder in last 10 minutes). 3. Real-Time Feature Store (Redis): Caches aggregate features for sub-millisecond lookup by ML scoring models. 4. Evaluation Microservice: Evaluates XGBoost risk models against feature vectors and returns `APPROVE`, `CHALLENGE_MFA`, or `DECLINE`.
XIYOR Apache Flink Stateful 5-Minute Velocity Aggregator (Java)java
import org.apache.flink.streaming.api.functions.KeyedProcessFunction;
import org.apache.flink.api.common.state.ValueState;
import org.apache.flink.api.common.state.ValueStateDescriptor;
import org.apache.flink.util.Collector;

public class CardVelocityAggregator extends KeyedProcessFunction<String, TransactionEvent, FeatureVector> {

    // RocksDB backed state storing swipe count in last 300 seconds
    private transient ValueState<Integer> swipeCountState;

    @Override
    public void open(org.apache.flink.configuration.Configuration parameters) {
        ValueStateDescriptor<Integer> descriptor = 
            new ValueStateDescriptor<>("swipeCount", Integer.class, 0);
        swipeCountState = getRuntimeContext().getState(descriptor);
    }

    @Override
    public void processElement(TransactionEvent value, Context ctx, Collector<FeatureVector> out) throws Exception {
        int currentCount = swipeCountState.value();
        currentCount += 1;
        swipeCountState.update(currentCount);

        // Schedule timer to decay count after 300,000ms (5 minutes)
        ctx.timerService().registerEventTimeTimer(value.timestamp + 300000);

        // Emit updated feature vector to Redis sink
        out.collect(new FeatureVector(value.cardId, currentCount, value.amount));
    }
}
  • Sub-Millisecond State Access: RocksDB memory-mapped state permits millions of state reads/writes per second per node.
  • Exactly-Once Semantics: Flink two-phase commit sinks guarantee feature counts are never duplicated during cluster failover.
  • Low Latency Evaluation: End-to-end feature aggregation latency is under 4 milliseconds.

03 // REDIS CLUSTER CRAWLING & MODEL INFERENCE

Once Flink computes updated feature vectors, it writes them directly to a Redis Cluster using pipeline batching. When the Payment Gateway API processes an incoming swipe, it executes a single MGET command to pull card features from Redis, passes the feature array to a high-speed C++ XGBoost inference library, and returns an approval decision before the payment network times out.

04 // METRICS & FINANCIAL IMPACT

Deployed across a digital banking gateway processing $4 Billion in annual transaction volume, XIYOR's streaming fraud engine achieved: - 32ms P99 end-to-end fraud scoring decision latency. - $14.8M in prevented fraudulent chargebacks within the first 12 months of operation. - 42% reduction in false-positive transaction declines.