A real-time streaming firewall built using Apache Kafka and Apache Spark Structured Streaming. The system validates incoming event logs, enforces schema and rule-based checks, and routes traffic into clean and quarantine streams for downstream consumption and monitoring.
This project focuses on stream processing and data quality enforcement, not batch analytics.
-
A Python producer generates both valid and malicious events.
-
Events are published to Kafka via the
firewall-logstopic. -
Spark Structured Streaming consumes the stream and applies firewall validation rules.
-
Events are split and routed:
- Valid events →
firewall-clean - Invalid events →
firewall-quarantine
- Valid events →
-
A lightweight UI consumer visualizes both streams in real time.
streaming-firewall/
├── consumer/
│ ├── consumer.py # Spark streaming firewall (core logic)
│ └── ui_consumer.py # Streamlit UI for clean vs quarantine
├── producer/
│ └── producer.py # Event producer (good + malicious)
├── docker-compose.yml # Kafka + Zookeeper + Spark cluster
└── event_format.txt # Event schema contract
An event is quarantined if any of the following conditions fail:
event_idis missing or nulllevelis not one of:INFO,WARN,ERRORtimestampis not valid ISO-8601sourceis not a known service
Each rejected event is tagged with:
is_valid = falsereject_reasonindicating the violated rule
| Topic | Purpose |
|---|---|
firewall-logs |
Raw incoming events |
firewall-clean |
Validated clean events |
firewall-quarantine |
Rejected or malicious events |
docker compose up -ddocker exec -it kafka kafka-topics \
--create --topic firewall-logs \
--bootstrap-server localhost:9092 \
--partitions 1 --replication-factor 1
docker exec -it kafka kafka-topics \
--create --topic firewall-clean \
--bootstrap-server localhost:9092 \
--partitions 1 --replication-factor 1
docker exec -it kafka kafka-topics \
--create --topic firewall-quarantine \
--bootstrap-server localhost:9092 \
--partitions 1 --replication-factor 1docker exec -it spark-master bashInside the container:
spark-submit /opt/spark/work/consumer/consumer.pypython3 producer/producer.pystreamlit run consumer/ui_consumer.py