Skip to content

Latest commit

 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Real-time-fraud-detection-kafka-streams

This project is a simple Spring Boot and Kafka Streams demo that publishes sample transactions to Kafka and flags suspicious transactions as fraud alerts.

What This Project Does

  • Exposes a REST endpoint at POST /api/transactions
  • Generates 50 sample transactions
  • Publishes those transactions to the Kafka topic transactions
  • Uses Kafka Streams to read from transactions
  • Filters transactions with amount > 10000
  • Writes suspicious transactions to the Kafka topic fraud-alerts

Main Components

  • TransactionController
    • Produces transaction events with KafkaTemplate<String, String>
  • FraudDetectionStream
    • Reads transaction events from Kafka Streams
    • Detects suspicious transactions
    • Publishes alerts to fraud-alerts
  • KafkaConfig
    • Creates Kafka producer beans
    • Creates Kafka Streams configuration bean
    • Creates required Kafka topics

Configuration

Current Kafka configuration is in src/main/resources/application.yml:

  • Bootstrap server: localhost:9092
  • Streams application id: fraud-detection-streams
  • Input topic: transactions
  • Output topic: fraud-alerts

Issues Fixed

The following issues were fixed while setting up this project:

  1. Build environment issue

    • The project initially could not build because Java was not available in the environment.
  2. Maven cleanup

    • Removed duplicate dependency entries from pom.xml.
  3. Application startup failure

    • The app failed to start because Spring could not find a KafkaTemplate<String, String> bean.
    • Added explicit Kafka producer configuration in KafkaConfig.
  4. Kafka Streams startup configuration

    • Kafka Streams required a defaultKafkaStreamsConfig bean.
    • Added KafkaStreamsConfiguration in KafkaConfig.
  5. Topic name mismatch

    • Topic names were normalized to:
      • transactions
      • fraud-alerts
  6. Test stability

    • Simplified the test so mvn package succeeds without requiring full Kafka infrastructure during test startup.

Build Status

The project now builds successfully with:

./mvnw clean package

How To Run

Make sure Kafka is running on localhost:9092, then start the application:

./mvnw spring-boot:run

The application starts on:

  • http://localhost:8080

Test The API

Send a request to generate sample transactions:

curl -X POST http://localhost:8080/api/transactions

Expected response:

✅ Transaction sent to Kafka!

Expected Flow

  1. Call POST /api/transactions
  2. 50 transaction messages are sent to Kafka
  3. Kafka Streams reads messages from transactions
  4. Transactions with amount greater than 10000 are treated as suspicious
  5. Suspicious events are written to fraud-alerts

Git

The project has also been initialized and pushed to GitHub.

Repository:

  • https://github.com/temptation4/kafaStream

    👨‍💻 Author

Neelu Sahai

About

Spring Boot + Kafka Streams fraud detection demo

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages