A production-grade streaming data pipeline that ingests real-time Bitcoin trades from Binance, processes them via Kafka and Snowflake, transforms them using dbt (SCD Type 2), and orchestrates the entire workflow with Airflow in Docker.
This project demonstrates an end-to-end Data Engineering solution for financial market data. It handles high-velocity streams, ensures data quality through "Silver/Gold" layers, tracks historical changes (SCD2), and provides an analytics-ready Star Schema for BI tools like Power BI.
- Source: Binance WebSocket API (Real-time Trade Data)
- Ingestion: Apache Kafka (Dockerized)
- Loading: Snowpipe Streaming (Kafka Connect)
- Warehouse: Snowflake
- Transformation: dbt (Data Build Tool) with Incremental Models & Snapshots
- Orchestration: Apache Airflow (running inside Docker)
- Infrastructure: Docker Compose (Fully Containerized)
-
Ingestion Layer (
producer.py):- Connects to Binance WebSocket (
wss://stream.binance.com:9443). - Standardizes raw JSON keys (e.g.,
p->price,q->quantity). - Publishes messages to the
stock_tradesKafka topic.
- Connects to Binance WebSocket (
-
Message Broker (Kafka & Zookeeper):
- Buffers streaming data to decouple producers from consumers.
- Managed via Docker containers.
-
Loading Layer (Kafka Connect):
- Uses the Snowflake Sink Connector in Streaming mode.
- Ingests data directly into the
STOCK_TRADES_RAWtable in Snowflake with low latency (~1s).
-
Transformation Layer (dbt):
- Bronze (View): Parses the raw
RECORD_CONTENTJSON blob into structured columns. - Silver (Table): Incremental loads with deduplication and quality checks.
- Gold (Star Schema):
DIM_SYMBOL: SCD Type 2 Dimension tracking Symbol metadata (Risk, Sector).FACT_TRADES: Transactional fact table linked to specific Dimension versions via Surrogate Keys.
- Bronze (View): Parses the raw
-
Orchestration (Airflow):
- DAG runs every minute.
- Triggers
dbt snapshot(for history tracking) followed bydbt runanddbt test.
- Language: Python 3.9, SQL (Jinja)
- Streaming: Apache Kafka, Binance WebSocket API
- Database: Snowflake (Data Warehouse)
- Transformation: dbt (Data Build Tool)
- Orchestration: Apache Airflow 2.7+
- Containerization: Docker & Docker Compose
- Docker & Docker Compose installed.
- A Snowflake Account.
- Python 3.9+ (for local testing, optional).
git clone https://github.com/your-username/crypto-streaming-pipeline.git
cd crypto-streaming-pipelineUpdate the connector_config.json with your Snowflake private key and user details.
(Note: Ensure dbt_profiles/profiles.yml is also updated with your credentials, but do not commit these to Git! Use environment variables in production.)
Run the entire stack (Kafka, Airflow, Zookeeper, Producer) with one command:
docker compose up -d --buildRun the bootstrap SQL script in your Snowflake worksheet to create the database, schema, and roles:
-- See 'scripts/snowflake_bootstrap.sql'
USE ROLE SECURITYADMIN;
CREATE ROLE kafka_role;
-- ... (rest of the setup)Once Docker is up, submit the connector configuration to Kafka Connect:
curl -i -X POST -H "Content-Type: application/json" -d @connector_config.json http://localhost:8083/connectors- Type: View
- Function: Raw JSON extraction. No transformations.
- Type: Incremental Table
- Function: Deduplication, Type Casting, Filtering (Price > 0).
DIM_SYMBOL(SCD Type 2): Tracks changes in risk levels or sectors over time usingdbt snapshot.- Columns:
symbol_key(PK),ticker,sector,risk_level,valid_from,valid_to.
- Columns:
FACT_TRADES: Connects trades to the correct dimension version.- Columns:
fact_id(PK),symbol_key(FK),price,quantity,total_amount_usd.
- Columns:
- Airflow UI:
http://localhost:8080(User:admin/ Pass:admin) - Kafka UI (Optional): Add
provectus/kafka-uito docker-compose for visual Kafka monitoring. - Snowflake: Query the
STREAMING_DB.PUBLIC.CONSUMPTION_TRADESview for analytics.
Feel free to open issues or submit PRs if you want to add more crypto exchanges or advanced analytics models!
MIT License.