Status: Enterprise-grade fraud detection system with real-time streaming analytics - production-ready Java application for financial security workflows.
๐ A high-performance, real-time anomaly detection system built in Java for detecting fraud and anomalies in streaming transaction data using Apache Kafka and statistical machine learning.
- ๐ Real-time Processing: Built on Apache Kafka Streams for low-latency stream processing
- ๐ค Statistical ML: Uses advanced statistical algorithms for anomaly detection
- ๐ Scalable Architecture: Horizontally scalable with Kafka's distributed processing
- ๐ง Adaptive Learning: Adapts to new patterns with continuous model updates
- ๐ฏ Multiple Anomaly Types: Detects various types of anomalies (fraud, unusual amounts, time patterns, etc.)
- โก High Throughput: Optimized for processing thousands of transactions per second
- ๐ Built-in Monitoring: Real-time metrics and comprehensive logging for observability
- ๐ง Easy Configuration: Environment variables and properties-based configuration
- ๐ก๏ธ Production Ready: Comprehensive error handling and graceful shutdown
- ๐จ Visual Demo: Beautiful colored output for presentations and demos
๐ก [Transaction Stream] โ ๐ฅ [Kafka Input Topic] โ ๐ [SlipStream Processor] โ ๐ค [Kafka Output Topics]
โ
๐ง [Statistical ML Engine]
โ
๐ฏ [Anomaly Classification]
โ
โ
[Normal Results] ๐จ [Anomaly Alerts]
- ๐จ Data Ingestion: Transactions stream into Kafka topics in real-time
- ๐ Feature Extraction: Extract relevant features (amount, location, time, velocity)
- ๐งฎ Statistical Analysis: Apply Z-score analysis and composite scoring
- ๐ฏ Anomaly Detection: Identify outliers using configurable thresholds
- ๐ Result Classification: Route normal vs anomalous transactions
- ๐จ Alert Generation: Send high-confidence anomalies to alert topics
- โ Java 17: Modern Java with performance optimizations and latest features
- ๐ Apache Kafka Streams: Stream processing framework for real-time data
- ๐ Apache Commons Math: Statistical functions for anomaly detection
- ๐ Jackson: High-performance JSON serialization/deserialization
- ๐ SLF4J + Logback: Comprehensive logging framework with file rotation
- โ JUnit 5: Modern testing framework with comprehensive test coverage
- ๐ง Maven: Build automation and dependency management
- ๐ณ Docker Compose: Containerized infrastructure setup
- ๐จ ANSI Colors: Beautiful terminal output for demos
Perfect for presentations and recording!
Experience SlipStream's real-time anomaly detection with our interactive visual demo:
# Quick visual demo (no Kafka required)
./visual-demo.sh
# Full interactive demo (with Kafka)
./demo.shThis launches a complete demonstration with:
- ๐ Colorful real-time transaction streams
- ๐จ Live anomaly alerts with visual highlighting
- ๐ Anomaly scoring and confidence levels
- ๐ฏ Multiple anomaly types (high amount, velocity, location, time)
Demo Resources:
- ๐ Complete Demo Guide - Setup and customization instructions
- ๐บ Visual Output Examples - See exactly what the demo looks like
- ๐ฌ Recording Tips - Perfect your demo recordings
- โ Java 17 or higher
- ๐ Apache Kafka 3.6+ running on localhost:9092
- ๐ง Maven 3.6+
- ๐ณ Docker & Docker Compose (for easy Kafka setup)
mvn clean compilemvn test# Start all services (Kafka, Zookeeper, UI)
docker compose up -d
# Or use Podman
podman compose up -d# The init-kafka container automatically creates these topics:
# - transactions (input)
# - anomalies (all results)
# - alerts (anomalies only)
# Verify topics were created
docker compose exec kafka kafka-topics --list --bootstrap-server localhost:9092mvn exec:java -Dexec.mainClass="com.slipstream.SlipStreamApplication"Or build and run the JAR:
mvn package
java -jar target/slipstream-anomaly-detector-1.0.0-SNAPSHOT.jar# Quick visual demo (no Kafka needed)
./visual-demo.sh
# Full interactive demo (with real Kafka)
./demo.sh| Variable | Description | Default | Example |
|---|---|---|---|
KAFKA_BOOTSTRAP_SERVERS |
๐ Kafka bootstrap servers | localhost:9092 |
kafka1:9092,kafka2:9092 |
KAFKA_INPUT_TOPIC |
๐ฅ Input topic for transactions | transactions |
payment-events |
KAFKA_OUTPUT_TOPIC |
๐ค Output topic for all results | anomalies |
fraud-results |
KAFKA_ALERTS_TOPIC |
๐จ Alerts topic for anomalies | alerts |
fraud-alerts |
KAFKA_NUM_THREADS |
๐ Number of stream threads | 1 |
4 |
KAFKA_STATE_DIR |
๐พ Directory for state stores | /tmp/kafka-streams |
/data/streams |
Configuration can also be set in src/main/resources/application.properties:
# ๐ Kafka Configuration
kafka.bootstrap.servers=localhost:9092
kafka.input.topic=transactions
kafka.output.topic=anomalies
kafka.alerts.topic=alerts
# ๐ง Statistical Detector Settings
detector.statistical.zscore_threshold=2.5
detector.statistical.anomaly_threshold=0.7
detector.statistical.min_samples=20
# ๐ Stream Processing
kafka.num.stream.threads=1
kafka.commit.interval.ms=10000{
"transaction_id": "tx_12345",
"user_id": "user_67890",
"merchant_id": "merchant_abc",
"amount": 150.75,
"currency": "USD",
"timestamp": "2024-01-15T14:30:00",
"location": {
"latitude": 40.7128,
"longitude": -74.0060,
"country": "USA",
"city": "New York"
},
"payment_method": "credit_card",
"merchant_category": "grocery",
"metadata": {
"device_id": "mobile_123",
"session_id": "sess_456"
}
}{
"transaction_id": "tx_12345",
"is_anomaly": true,
"anomaly_score": 0.85,
"confidence": 0.92,
"anomaly_type": "unusual_amount",
"detected_at": "2024-01-15T14:30:05",
"original_transaction": { ... },
"features_used": {
"amount": 150.75,
"hour_of_day": 14,
"amount_ratio": 3.2
},
"reason": "Anomaly score: 0.850, Type: unusual_amount, Large transaction amount: $150.75"
}You can use the Kafka console producer to send test transactions:
# Start the console producer
docker compose exec kafka kafka-console-producer --topic transactions --bootstrap-server localhost:9092
# Or use our demo transaction generator
mvn exec:java -Dexec.mainClass='com.slipstream.demo.TransactionGenerator' -Dexec.args="30"{
"transaction_id": "tx_001",
"user_id": "user_123",
"merchant_id": "merchant_grocery",
"amount": 50.0,
"currency": "USD",
"timestamp": "2024-01-15T14:30:00",
"location": {
"latitude": 40.7128,
"longitude": -74.0060,
"country": "USA",
"city": "New York"
},
"payment_method": "credit_card",
"merchant_category": "grocery",
"metadata": {}
}# ๐ Monitor all results
docker compose exec kafka kafka-console-consumer --topic anomalies --bootstrap-server localhost:9092 --from-beginning
# ๐จ Monitor alerts only
docker compose exec kafka kafka-console-consumer --topic alerts --bootstrap-server localhost:9092 --from-beginning
# ๐จ Use our beautiful anomaly monitor
mvn exec:java -Dexec.mainClass='com.slipstream.demo.AnomalyResultConsumer'SlipStream detects several types of anomalies using statistical analysis:
- ๐จ FRAUD: General fraud patterns and suspicious behavior
- ๐ฐ UNUSUAL_AMOUNT: Transactions with abnormally high amounts (>$5,000)
- โก VELOCITY: High frequency of transactions from same user (>3 in 5 minutes)
- ๐ LOCATION: Transactions from unusual or suspicious locations
- ๐ TIME_PATTERN: Transactions at unusual times (late night/early morning)
- ๐ช MERCHANT_PATTERN: Unusual merchant interaction patterns
- ๐ STATISTICAL_OUTLIER: General statistical anomalies using Z-score analysis
- Z-Score Analysis: Statistical outlier detection based on standard deviations
- Composite Scoring: Combines multiple factors for accurate detection
- Velocity Detection: Tracks transaction frequency per user
- Location Analysis: Identifies geographically suspicious transactions
- Time Pattern Recognition: Detects unusual timing patterns
# ๐ Increase processing threads for higher throughput
KAFKA_NUM_THREADS=4
# โฑ๏ธ Adjust commit interval for latency vs. throughput trade-off
kafka.commit.interval.ms=10000
# ๐๏ธ State store caching for better performance
kafka.cache.max.bytes.buffering=10485760
# ๐ Processing guarantee
kafka.processing.guarantee=at_least_once
# ๐ฆ Batch size optimization
kafka.batch.size=16384# ๐ Production JVM settings
java -Xmx4g -Xms2g \
-XX:+UseG1GC \
-XX:MaxGCPauseMillis=100 \
-XX:+UseStringDeduplication \
-jar slipstream.jar
# ๐ ๏ธ Development settings
java -Xmx1g -Xms512m \
-XX:+UseG1GC \
-jar slipstream.jarExpected performance on modern hardware:
- Throughput: 10,000+ transactions/second
- Latency: <50ms for anomaly detection
- Memory: 1-4GB depending on state store size
- CPU: 2-8 cores for optimal performance
SlipStream provides comprehensive observability:
- ๐ Stream Processing State: Current topology status
- ๐ Training Data Size: Number of samples in the statistical model
- ๐ง Model Status: Training completion and health
- ๐ Transaction Counters: Total processed, normal, anomalous
- ๐พ JVM Memory Usage: Heap and non-heap memory statistics
- โฑ๏ธ Processing Latency: Average and 99th percentile latencies
# ๐ Debug mode for development
logging.level.com.slipstream=DEBUG
# ๐ Info mode for production (default)
logging.level.com.slipstream=INFO
# ๐ Reduce Kafka noise
logging.level.org.apache.kafka=WARNThe application provides several health indicators:
- โ Kafka Connectivity: Connection to Kafka brokers
- ๐ Stream State: Kafka Streams topology health
- ๐ง Model Health: Statistical model training status
- ๐พ Memory Usage: JVM memory consumption
- ๐ Processing Rate: Transactions per second
src/
โโโ ๐ฑ main/java/com/slipstream/
โ โโโ ๐ SlipStreamApplication.java # Main application entry point
โ โโโ โ๏ธ config/
โ โ โโโ KafkaConfig.java # Kafka configuration management
โ โโโ ๐ง detector/
โ โ โโโ AnomalyDetector.java # Detector interface
โ โ โโโ StatisticalAnomalyDetector.java # Statistical ML detector
โ โโโ ๐ model/
โ โ โโโ TransactionEvent.java # Input transaction data model
โ โ โโโ AnomalyResult.java # Output anomaly result model
โ โโโ ๐จ demo/
โ โ โโโ TransactionGenerator.java # Demo transaction generator
โ โ โโโ AnomalyResultConsumer.java # Visual anomaly monitor
โ โโโ ๐ stream/
โ โโโ AnomalyDetectionStreams.java # Kafka Streams topology
โโโ ๐ main/resources/
โ โโโ application.properties # Application configuration
โ โโโ logback.xml # Logging configuration
โโโ โ
test/java/ # Comprehensive unit tests
โโโ StatisticalAnomalyDetectorTest.java
โโโ TransactionEventTest.java
# ๐ง Compile only
mvn compile
# โ
Run all tests
mvn test
# ๐ Run tests with coverage
mvn test jacoco:report
# ๐ฆ Create executable JAR
mvn package
# ๐ Run integration tests (requires running Kafka)
mvn verify
# ๐งน Clean build artifacts
mvn cleanIntelliJ IDEA:
# Import as Maven project
# Enable annotation processing
# Set Java 17 as project SDKVS Code:
# Install Java Extension Pack
# Install Maven for Java extension
# Configure Java 17 runtimeWe welcome contributions! Here's how you can help make SlipStream better:
- ๐ด Fork the repository
- ๐ฟ Create a feature branch:
git checkout -b feature/amazing-feature - ๐พ Commit your changes:
git commit -m 'Add amazing feature' - ๐ค Push to branch:
git push origin feature/amazing-feature - ๐ Open a Pull Request
- โ Follow Java coding standards and conventions
- ๐ Add comprehensive unit tests for new features
- ๐ Update documentation for any API changes
- ๐ฏ Ensure all tests pass before submitting
- ๐จ Include integration tests for stream processing changes
- ๐ Use meaningful commit messages
Found a bug? Please open an issue with:
- ๐ Clear description of the problem
- ๐ Steps to reproduce the issue
- ๐ป Your environment details (Java version, OS, etc.)
- ๐ Expected vs actual behavior
- ๐ Any error logs or stack traces
Have an idea? We'd love to hear it! Include:
- ๐ฏ Clear description of the proposed feature
- ๐ค Explanation of why it would be useful
- ๐ Examples of how it would be used
- ๐ ๏ธ Any implementation suggestions
# Run all tests before submitting
mvn clean test
# Check code coverage
mvn jacoco:report
# Run integration tests
mvn verify
# Performance tests
mvn test -Dtest=*PerformanceTest- All submissions require code review
- Maintainers will review and provide feedback
- Address any requested changes
- Once approved, your PR will be merged!
This project is licensed under the MIT License - see the LICENSE file for details.
- ๐ Documentation: Check our comprehensive docs above
- ๐ Issues: GitHub Issues
- ๐ฌ Discussions: GitHub Discussions
- ๐ง Email: For security issues, please email directly
- ๐บ Demo Videos: See our DEMO.md for recording tips
- โ Apache Kafka - For the incredible streaming platform
- ๐ Kafka Streams - For making stream processing accessible
- ๐ Apache Commons Math - For robust statistical functions
- ๐ณ Docker - For containerization magic
- ๐ฏ Maven - For dependency management
- ๐งช JUnit - For comprehensive testing framework
๐ Ready to detect anomalies in real-time? Let's get started! ๐
Made with โค๏ธ by the SlipStream team
โญ Don't forget to star this repo if you found it helpful! โญ
