Zero Labs
Industry News / Technology

Designing Real-Time Features for Fraud Detection at Scale

Source · Towards AI By Siva Ganta

From the publisher’s feed, collected in the ZeroLabs newsroom.

IntroductionIn fraud prevention, features are the lifeblood of machine learning models. While algorithm choice matters, in practice, the speed and accuracy of feature computation often determines how effective your system will be in stopping fraud.Fraudsters adapt quickly: some attacks play out over minutes, others over months. To stay ahead, fraud prevention systems must combine near real-time features (minute/hour) with batch-based daily features and serve them seamlessly into models running at scale.In this article, I’ll explain:Types of features used in fraud prevention.How minute/hour features are computed in real time.How daily features are prepared via batch pipelines.The combined architecture that powers these systems in production.Types of Features in Fraud Prevention1. Batch Featureso Aggregated over long-term time windows (days to months).o Capture steady behavioral trends.2. Direct Featureso Attributes directly available from a transaction (amount, card type, device, etc.).3. External Featureso Provided by third-party systems (device fingerprinting, geolocation APIs, blacklists).The real power comes from blending short-window (minute/hour) with long-window (daily) features in one pipeline.Minute/Hour Features (Near Real-Time)These are short-window velocity features, such as:Number of transactions in the last 10 minutes, 30 minutes, 1 hour.Number of login attempts (success/fail) in the past 5 hours.Number of unique devices used in the last 24 hours.How it works in production:Event sources (transactions, logins, devices, IPs) stream into Kafka / Pub-Sub.A feature updater service (Kafka consumer or part of the inference app) writes entity-level raw data or counters into Dynamo db/Cassandra/mysql/Hbase etcAt inference, the scoring API queries(range queries etc) Cassandra using entity IDs (member_id, device_id, payment_id) as partition keys and timestamps as clustering keysTech stack: Python/Flask, Kafka, Cassandra/Dynamo db, Docker/Kubernetes, Grafana/Splunk.Daily Features (Batch Aggregations)Daily features capture longer-term trends such as:Transactions per entity in last 7/30/90/180/360 days.Refund attempts in the last year.Unique geolocations used over 6 months.How it works in production:Airflow orchestrates Spark (PySpark) jobs each night.Aggregations are stored in Hive / BigQuery/Red shift for long-term training (multi-year history).Recent daily aggregates (e.g., last 5 days) are pushed into Cassandra for real-time inference.This ensures one feature pipeline supports both training and inference, minimizing train/serve skew.Tech stack: Spark/PySpark, Airflow, Hive/BigQuery, Cassandra/Dynamo db.Combined ArchitectureThe figure below shows a generic fraud ML system architecture that integrates both real-time and batch features into a single scoring path:Flow:1. Data Sources (logins, transactions, devices, locations) → Streaming Ingest (Kafka).2. Feature Pipelines calculate:o Real-time features (minute/hour) → Cassandra.o Batch daily features (7–360 days) → Hive/BigQuery → Cassandra (short-term).3. Feature Store (Cassandra/Dynamo db+ Hive/BigQuery) serves both training and inference.4. Model Training Pipeline prepares features, tunes hyperparameters, evaluates, and stores models in a Model Registry (MLflow).5. Inference Service (Flask/FastAPI) fetches features from Cassandra and returns predictions.6. Decisioning Layer applies thresholds to Accept, Review, or Reject.7. Monitoring tracks latency, drift, and errors with Grafana/Splunk.Best Practices✅ Schema Design: Use entity IDs as partition keys and timestamps as clustering keys in Cassandra. ✅ Freshness vs Cost: Keep only high-value features real time; aggregate others daily. ✅ Consistency: Use the same pipelines for training and inference to prevent skew. ✅ Latency Budgets: Keep feature fetch + model scoring ✅ Monitoring Drift: Apply KS test, PSI, and summary stats (mean/median) to detect data drift early.Closing thought:Real-time fraud prevention is as much data engineering as it is machine learning. The key lies in balancing fresh, streaming features with stable batch features — and making them both available in a low-latency serving environment.In my next article, I’ll explore complete ML system design for fraud detection using distributed machine learning frameworks.Follow me here and on LinkedIn if you’d like to learn more about building ML for fraud prevention in the real world.Designing Real-Time Features for Fraud Detection at Scale was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.