A complete real-time sentiment analysis pipeline that streams live tweets, processes them through Apache Kafka and Apache Spark MLlib, stores results in MongoDB, and visualizes outcomes via a Flask frontend.
-
Twitter Tweets → Streamed via API to Kafka Producer.
-
Kafka Broker → Buffers and distributes tweets to Spark consumers.
-
Spark MLlib →
- Model training (offline).
- Real-time prediction (online).
-
MongoDB → Stores classified tweets (positive, negative, neutral).
-
Flask App → Fetches sentiment data from MongoDB for visualization.
- Docker & Docker Compose
- Python 3.x
- Apache Kafka
- Apache Spark
- MongoDB
- Flask
BDS_Assignment/
│
├── Kafka-Streaming.py # Spark Streaming consumer
├── Spark/ # Jupyter workspace (for model training)
├── Application-FLASK/
│ └── main.py # Flask backend
├── docker-compose.yml
├── Dockerfile # Spark-Jupyter image
└── README.md
docker-compose up -ddocker build -t spark-jupyter:latest .docker run -e MONGO_USERNAME="" -e MONGO_PASSWORD="" \
-p 8888:8888 \
-v B:\BDS_Assignment\Spark:/home/xyz/work \
--network bds_assignment_kafka-net \
spark-jupyter:latestOpen the Jupyter notebook from the browser using the token printed in the container logs.
docker exec -it <jupyter-container-id> /bin/bash
cd home/xyz/workspark-submit Kafka-Streaming.pycd Application-FLASK
python main.pyThe app exposes endpoints to visualize tweet sentiments and trends.
- Use Jupyter Notebook inside the
Spark/directory to train sentiment analysis models with Spark MLlib. - Save the trained model and load it in the streaming job (
Kafka-Streaming.py).
All classified tweets are stored in MongoDB, including:
- Tweet text
- Timestamp
- Sentiment label
- Confidence score
The Flask app fetches data from MongoDB and renders:
- Real-time sentiment count charts
- Historical trend lines
- Word clouds or hashtags (optional)
| Component | Technology |
|---|---|
| Data Streaming | Apache Kafka |
| Real-time Processing | Apache Spark (PySpark) |
| ML Model | Spark MLlib |
| Database | MongoDB |
| API Backend | Flask |
| Frontend | HTML / JS / Charts.js |
| Containerization | Docker |
All containers (Kafka, Spark, MongoDB, Flask) communicate on the same Docker network:
bds_assignment_kafka-net
- Shrey Vyas – Project Developer
- Integration with Twitter API v2 for live streams
- Dashboard for real-time analytics
- Model fine-tuning using BERT or LSTM
🎯 Goal: Deliver live tweet sentiment insights using scalable big data technologies.
