Volume 12 · Chapter 3 — System Design Case Studies

Case Study: Real-Time Fraud Detection Pipeline

Goutham Mayaluri 8 min read AWSCloudSystem Design

3.1 The Problem and Requirements

Design a system that detects fraudulent transactions in real time. Requirements: functionally, it must analyze each transaction as it happens, score it for fraud risk, and act on high-risk transactions (block, flag, or route for review). Non-functionally, it must process a high, continuous volume of transactions with low latency (fraud decisions need to be fast to be useful), be highly available, scale with transaction volume, and allow the fraud models and rules to evolve (including reprocessing historical transactions when a model improves). The defining characteristics are high-volume continuous data and real-time processing, which point toward a streaming architecture rather than simple request/response.

3.2 High-Level Architecture

Transactions flow into a Kinesis stream as they occur - an ordered, retained, high-throughput feed. Multiple consumers process the stream independently: a real-time scoring service evaluates each transaction against fraud models and rules, producing a risk score; high-risk transactions are routed (via a queue or event) to blocking or manual-review workflows; and other consumers feed analytics and archive transactions to S3 for model training and compliance. Enrichment data (account history, patterns) is served from fast stores (DynamoDB, cache) for low-latency lookups during scoring. The streaming design lets several consumers process the same ordered feed and, crucially, replay it when models improve.

flowchart TB
  Txn[Transactions] --> Stream[(Kinesis stream - ordered, retained)]
  Stream --> Score[Real-time scoring service]
  Score --> Enrich[(DynamoDB / cache - fast enrichment lookups)]
  Score -->|high risk| Act[(Queue: block / manual review)]
  Stream --> An[Analytics consumer]
  Stream --> Arch[Archive to S3 - training + compliance]
  Arch -. replay for improved models .-> Stream

3.3 Why Streaming

The choice of a stream (Kinesis) over a queue is central and follows the requirements. The transaction feed is continuous and high-volume; multiple independent consumers each need to process all of it (scoring, analytics, archival); ordering matters for analyzing a sequence of a customer’s transactions; and replay is essential - when the fraud model is improved, you reprocess recent transactions through the new model, which is only possible because the stream retains records. A queue, which deletes each message after one consumer processes it, couldn’t support multiple full-feed consumers or replay. Partitioning by account keeps each account’s transactions ordered on one shard while many shards scale throughput, with the key chosen to avoid hot shards. This is the archetypal case for streaming.

3.4 Low-Latency Scoring and Scaling

Real-time fraud decisions must be fast, so the scoring service reads from the stream continuously and evaluates each transaction with low latency, using fast enrichment stores (DynamoDB for account features, a cache for hot data) rather than slow queries, so a scoring decision doesn’t wait on a heavy database. The service scales with the stream - more shards and more consumer capacity as volume grows - and is stateless so it scales horizontally. High-risk outcomes are pushed asynchronously to action workflows so scoring throughput isn’t blocked by the downstream action. The design balances real-time low latency (fast reads, streaming) with the throughput to handle the full transaction volume continuously.

3.5 Evolvability, Security, and Trade-Offs

A key requirement is that fraud models evolve, and the architecture supports it: because the stream is retained and transactions are archived to S3, an improved model can be backtested and the recent stream replayed through a new consumer without having lost data - the evolvability that streaming and archival provide. Security: the pipeline runs in private subnets with IAM roles, encryption throughout, and least privilege, handling sensitive transaction data carefully. Observability tracks scoring latency, throughput, and fraud-detection metrics. The main trade-offs: streaming adds complexity over simple request/response but is necessary for continuous multi-consumer real-time processing with replay; and fraud scoring runs alongside (not blocking) the payment path - the payment system can proceed while scoring happens in near-real-time, with high-risk transactions acted on quickly - trading a strictly-synchronous block for throughput, with the action workflow catching fraud fast.

3.6 Banking Production Notes

In production, this pipeline scores every transaction in near-real-time, flags or blocks fraud quickly, feeds analytics and model training, and retains everything for compliance. When the data-science team ships an improved model, they replay recent transactions through it to validate and backfill - a direct benefit of the streaming and archival design. The pipeline scales with transaction volume via shards and stateless consumers, stays available across AZs, and keeps sensitive data secure. It complements the payment system from the previous case: payments publish transactions that this pipeline consumes, showing how the case studies interconnect into a larger banking platform.

3.7 Troubleshooting the Design

Fraud-pipeline design weaknesses are recognizable. Using a queue instead of a stream would prevent multiple full-feed consumers and replay - use a stream for continuous, multi-consumer, replayable data. Doing slow database lookups during scoring would blow the latency budget - use fast enrichment stores. A poor partition key would create a hot shard throttling throughput or break per-account ordering - choose the key for both. Not archiving transactions would prevent model retraining and replay - archive to S3. Blocking the scoring throughput on downstream actions would limit capacity - push actions asynchronously. The design’s essence is streaming for continuous multi-consumer real-time processing with replay, fast enrichment for low-latency scoring, good partitioning for ordering and scale, and archival for evolvability.

Interview Question

Design a real-time fraud detection system. Why streaming, and how do you support evolving models?

I’d design it around a streaming architecture because the defining requirements - analyzing a high, continuous volume of transactions in real time, with multiple consumers, ordering, and the ability to reprocess history when models improve - point directly to a stream rather than simple request/response or a queue. The architecture: transactions flow into a Kinesis stream as they occur - an ordered, retained, high-throughput feed - and multiple consumers process it independently. A real-time scoring service evaluates each transaction against fraud models and rules to produce a risk score, using fast enrichment stores like DynamoDB and a cache for low-latency lookups of account history and features rather than slow database queries, so the scoring decision is fast; high-risk transactions are routed asynchronously to blocking or manual-review workflows; and other consumers feed analytics and archive transactions to S3 for training and compliance. Why streaming specifically: the transaction feed is continuous and high-volume, multiple independent consumers each need to process all of it (scoring, analytics, archival), ordering matters for analyzing a customer’s sequence of transactions, and replay is essential - when the fraud model is improved, I reprocess recent transactions through the new model, which is only possible because the stream retains records and I’ve archived them. A queue couldn’t do this, because it deletes each message after one consumer processes it, so it can’t support multiple full-feed consumers or replay - which is exactly why a stream, not a queue, is the right tool for this workload. I partition the stream by account so each account’s transactions stay ordered on one shard while many shards scale throughput, choosing the partition key to avoid a hot shard. Supporting evolving models is a first-class requirement met by the retained stream plus S3 archival: an improved model can be backtested against archived transactions and the recent stream replayed through a new consumer without having lost data, so the fraud logic can keep improving and be validated on real history - the evolvability streaming and archival provide. For low latency and scale, the stateless scoring service reads continuously, uses fast enrichment stores, scales with the stream, and pushes high-risk outcomes asynchronously so downstream actions don’t block scoring throughput. Security keeps the sensitive pipeline in private subnets with IAM roles, encryption, and least privilege, and observability tracks scoring latency, throughput, and detection metrics. The main trade-off I’d name is that streaming adds complexity over request/response but is necessary for continuous, multi-consumer, real-time processing with replay, and that fraud scoring runs alongside rather than strictly blocking the payment path, trading a hard synchronous block for throughput while still acting on high-risk transactions quickly. So streaming is chosen because the workload is continuous, multi-consumer, ordered, and needs replay, and evolving models are supported by the retained stream and S3 archive that let improved models be backtested and recent data reprocessed.

Chapter Revision Notes

  • Requirements (continuous high-volume data, multiple consumers, ordering, replay for improved models) point to streaming (Kinesis), not a queue.
  • A stream lets scoring, analytics, and archival each process the full ordered feed and replay it; a queue (delete-on-consume) can’t.
  • Low-latency scoring uses fast enrichment stores (DynamoDB, cache), not slow queries; the stateless scorer scales with the stream.
  • Partition by account for per-account ordering and even shard distribution; archive to S3 for training, compliance, and replay.
  • Trade-off: streaming’s complexity is justified by real-time multi-consumer processing with replay; scoring runs alongside the payment path, acting on high risk fast.