A production-grade streaming data pipeline that detects fraudulent job postings in real time.
Features β’ Architecture β’ Quick Start β’ ML Model β’ API Docs β’ Contributing
Job boards are flooded with fraudulent postings designed to steal personal data or money. This system automatically flags fake jobs the moment they are posted β no manual review required.
Every job posting flows through a Kafka queue β Spark ML pipeline β PostgreSQL β FastAPI β live Next.js dashboard. Fraud decisions happen in under 5 seconds with 100% precision (zero false alarms).
| Feature | Description |
|---|---|
| β‘ Real-time streaming | Kafka β Spark micro-batches every 5 seconds |
| π€ ML inference at scale | TF-IDF + Random Forest UDF runs across Spark workers |
| π Anomaly detection | EMA-based spike detection flags unusual fraud surges |
| π Fraud clustering | Cosine similarity groups related fake jobs (β₯ 0.8 threshold) |
| βοΈ Human corrections | Manual override system with full correction audit trail |
| π‘ Live dashboard | WebSocket-powered Next.js frontend with real-time charts |
| πͺ¦ Dead letter queue | Failed events captured for manual investigation |
| π³ One-command deploy | Full Docker Compose stack β 7 services, one command |
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β DATA FLOW β
β β
β CSV Dataset β
β β β
β βΌ β
β ββββββββββββββββ ββββββββββββββββββββ β
β β Kafka ββββββΊβ Kafka Topic β β
β β Producer β β (jobs) β β
β ββββββββββββββββ ββββββββββ¬ββββββββββ β
β β β
β βΌ β
β βββββββββββββββββββββββββββ β
β β Spark Structured β β
β β Streaming β β
β β ββ TF-IDF + RF model β β
β β ββ Anomaly detection β β
β β ββ Fraud clustering β β
β ββββββββββββββ¬βββββββββββββ β
β β β
β βΌ β
β βββββββββββββββββββββββββββ β
β β PostgreSQL β β
β β ββ job_predictions β β
β β ββ job_clusters β β
β β ββ job_corrections β β
β β ββ pipeline_metrics β β
β ββββββββββββββ¬βββββββββββββ β
β β β
β βΌ β
β βββββββββββββββββββββββββββ β
β β FastAPI β β
β β REST + WebSocket β β
β ββββββββββββββ¬βββββββββββββ β
β β β
β βΌ β
β βββββββββββββββββββββββββββ β
β β Next.js Dashboard β β
β β Live charts & alerts β β
β βββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
| Service | Image | Port | Role |
|---|---|---|---|
fraud-postgres |
postgres:16-alpine | 5432 | Predictions database |
fraud-kafka |
apache/kafka:3.8 | 9092 | KRaft message broker |
fraud-spark-master |
custom | 7077 / 8080 | Spark cluster coordinator |
fraud-spark-worker |
custom | 8081 | ML inference executor |
fraud-spark-stream |
custom | 4040 | Streaming driver |
fraud-api |
custom | 8000 | FastAPI REST + WebSocket |
fraud-dashboard |
custom | 3001 | Next.js frontend |
- Docker Desktop 24+
- 6 GB RAM available
- 10 GB free disk space
# 1. Clone the repo
git clone https://github.com/Veladicodes/Realtime-Fake-Job-Predictor.git
cd Realtime-Fake-Job-Predictor
# 2. Set up environment
cp .env.example .env
# β οΈ Edit .env and set a strong POSTGRES_PASSWORD
# 3. Launch everything
docker compose up --build| Service | URL |
|---|---|
| π Live Dashboard | http://localhost:3001 |
| π API Docs (Swagger) | http://localhost:8000/docs |
| β‘ Spark Master UI | http://localhost:8080 |
| π§ Spark Worker UI | http://localhost:8081 |
# Stop everything
docker compose down
# Also start the Kafka CSV producer (streams dataset into pipeline)
docker compose --profile producer upcd fake_job_detector
python -m venv venv && venv\Scripts\activate
pip install -r requirements.txt
python ../start_system.pyTrained on the Kaggle Fake Job Postings dataset β 17,880 job postings, 866 fraudulent (4.8%).
| Metric | Score |
|---|---|
| β Accuracy | 98.0% |
| π― Precision | 100% |
| π Recall | 60.2% |
| βοΈ F1-Score | 75.2% |
Model selected: Random Forest (beat Logistic Regression on F1-score)
100% Precision means zero false alarms β every job the model flags as fake is genuinely fraudulent. The trade-off is 60% recall: it misses ~40% of fakes, but never incorrectly flags a real job.
- Text preprocessing β job title + company profile + description + requirements are combined and cleaned
- TF-IDF vectorization β converts text into 5,000 numerical features (rare, distinctive words score highest)
- Feature engineering β adds
has_company_profile,has_salary_range,text_length - Random Forest β 100 decision trees vote on the final prediction
To retrain from scratch:
cd fake_job_detector
python ml/train_model.pyBase URL: http://localhost:8000
| Method | Endpoint | Description |
|---|---|---|
GET |
/health |
System health (Kafka, Spark, DB, ML status) |
GET |
/dashboard |
Aggregated stats snapshot |
GET |
/jobs/latest |
Last 50 processed predictions |
GET |
/jobs/fake |
All flagged fake jobs |
GET |
/alerts |
Top alerts sorted by risk score |
GET |
/trends |
Hourly fake/real job trend (24h window) |
GET |
/clusters/top |
High-pressure fraud clusters |
GET |
/corrections |
Manual human overrides |
POST |
/jobs/ingest |
Submit a new job posting for analysis |
WS |
/ws |
WebSocket β live prediction stream |
Full interactive docs: http://localhost:8000/docs
Realtime-Fake-Job-Predictor/
βββ docker-compose.yml # Orchestrates all 7 services
βββ .env.example # Environment variable template
βββ start_system.py # Windows local dev launcher
βββ DOCKER_SETUP.md # Detailed Docker guide
β
βββ fake_job_detector/
βββ api/ # FastAPI backend
β βββ Dockerfile
β βββ app.py # REST endpoints + WebSocket
β
βββ dashboard/ # Next.js real-time frontend
β βββ app/ # Pages: dashboard, alerts, analytics, trends
β βββ components/ # UI components
β βββ context/ # Dashboard state (WebSocket + polling)
β βββ services/ # API client
β
βββ kafka/ # Kafka CSV replay producer
β βββ producer.py
β
βββ ml/ # Model training pipeline
β βββ preprocess.py
β βββ train_model.py
β βββ saved_model/ # fraud_model.pkl + tfidf.pkl
β
βββ spark/ # Spark Structured Streaming job
β βββ spark_stream.py # Main streaming driver
β βββ model_loader.py # ML inference UDF
β βββ Dockerfile
β
βββ utils/ # DB writer, config, helpers
βββ data/raw/ # fake_job_postings.csv (17,880 rows)
| Variable | Default | Description |
|---|---|---|
POSTGRES_PASSWORD |
(required) | Database password |
SPARK_TRIGGER_INTERVAL |
5 seconds |
Spark micro-batch cadence |
SPARK_MAX_OFFSETS_PER_TRIGGER |
700 |
Records per Spark batch |
ANOMALY_EMA_ALPHA |
0.2 |
EMA smoothing factor |
ANOMALY_SPIKE_MULTIPLIER |
2.2 |
Spike threshold multiplier |
DASHBOARD_PORT |
3001 |
Host port for Next.js dashboard |
REPLAY_SPEED |
10.0 |
CSV replay speed (10x = 10Γ faster) |
MAX_KAFKA_LAG |
5000 |
Producer throttle threshold |
See .env.example for the full list.
python fake_job_detector/load_test.py \
--total-events 10000 \
--concurrency 40 \
--api-base-url http://127.0.0.1:8000Contributions are welcome! Please open an issue first to discuss what you'd like to change.
- Fork the repo
- Create a feature branch:
git checkout -b feature/your-feature - Commit your changes:
git commit -m 'Add your feature' - Push and open a Pull Request
This project is licensed under the MIT License.
If you found this useful, please consider giving it a β