# phnguynmkhoi/streaming_data_pipeline architecture

> Architecture diagram of the GitHub repository phnguynmkhoi/streaming_data_pipeline, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/phnguynmkhoi/streaming_data_pipeline
- Repository: https://github.com/phnguynmkhoi/streaming_data_pipeline

## Overview

##### Main Components
- Data Source: At the base is a Postgres database with change data capture enabled via a Debezium connector (referenced in the file “debezium-connector-postgres.json”).
- Ingestion Layer: Kafka serves as the backbone for data ingestion – it captures the events produced by Debezium.
- Processing Layer: Apache Spark is used to process and transform the streaming data from Kafka. This layer is triggered by scripts such as “spark_extract_data_script.sh” and uses additional Python scripts found in the “src/” directory (e.g., “main.py” for simulating transactions).
- Storage Layers:
- MinIO for archiving processed data (as described in the README and referenced in “apps/extract_data.py”).
- Apache Pinot for real-time analytics – with several Pinot configuration files (schemas and table definitions) under the “pinot” directory.
- Supporting/Orchestration Components: Additional scripts (within “script/”), Docker Compose configuration (“docker-compose.yml”), and container setups (e.g., “Dockerfile.spark”) orchestrate deployment and execution.

##### Understand Relationships and Data Flow
- Data flows into Kafka, serving as an intermediary message broker.
- Apache Spark reads from Kafka, performs necessary transformations, and may push transformed data back into Kafka for further processing or onward to storage.
- The processed data then:
- Is stored in MinIO for archival purposes.
- Is ingested by Apache Pinot to be made accessible for real-time query and analysis.
- Additional supporting scripts manage schema and table creation in Pinot (“create_all_schema.sh”, “create_all_table.sh”).

##### Architectural Patterns and Design Principles
- The architecture follows a streaming pipeline approach with decoupled components.
- There is a separation of concerns between the ingestion, processing, and storage layers, which is ideal for scalability and fault tolerance.
- The project uses containerization (Docker/Docker Compose) to manage dependencies and deploy the pipeline components.
- Scripts and configuration files split responsibilities into discrete tasks (data generation, schema/table management, data transformation, etc.).

##### Relevant Technologies
- Debezium for CDC (change data capture) from Postgres.
- Kafka for real-time messaging and data ingestion.
- Apache Spark as the distributed processing engine.
- MinIO as the object storage solution for archival.
- Apache Pinot as the realtime analytical data warehouse.
- Docker & Docker Compose for deployment orchestration.
- Python scripts (in “src” and “apps”) performing simulation and extraction tasks.

##### Elements
- “Postgres Database with Debezium” (source).
- “Kafka Broker” (ingestion).
- “MinIO Data Lake” (archival storage).
- “Apache Pinot” (realtime analytics and data modeling) – show separate schema/table definitions.
- From Postgres → Debezium → Kafka.
- From Kafka → Spark.
- From Spark → [MinIO and/or Kafka] → Pinot.
- Labels for containerization layers (Docker Compose) if relevant, to stress that this is a containerized environment.
- You might also note external dependencies like “aws-java-sdk” and “hadoop-aws” mentioned in the README, which are needed for MinIO integration.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Data Source Layer"
        PDB["Postgres DB with Debezium"] 
    end

    subgraph "Ingestion Layer"
        KAFKA["Kafka Broker"]
    end

    subgraph "Processing Layer"
        SPARK["Apache Spark Processing Engine"]
    end

    subgraph "Storage Layer"
        MINIO["MinIO Data Lake"]
        PINOT["Apache Pinot Analytics"]
    end

    subgraph "Orchestration & Management"
        DOCKER["Container Orchestration"]
        PMGMT["Pinot Schema/Table Management"]
    end

    %% Data Flow Connections
    PDB -->|"CDC_events"| KAFKA
    KAFKA -->|"Streaming_Data"| SPARK
    SPARK -->|"Archive_Data"| MINIO
    SPARK -->|"Processed_Data"| PINOT
    PMGMT -->|"Manage_Schema"| PINOT

    %% Orchestration influences all components
    DOCKER --> PDB
    DOCKER --> KAFKA
    DOCKER --> SPARK
    DOCKER --> MINIO
    DOCKER --> PINOT

    %% Styles
    classDef datasource fill:#f9c74f,stroke:#333,stroke-width:2px;
    classDef ingestion fill:#90be6d,stroke:#333,stroke-width:2px;
    classDef processing fill:#f9844a,stroke:#333,stroke-width:2px;
    classDef storage fill:#577590,stroke:#333,stroke-width:2px;
    classDef orchestration fill:#277da1,stroke:#333,stroke-width:2px;

    class PDB datasource;
    class KAFKA ingestion;
    class SPARK processing;
    class MINIO storage;
    class PINOT storage;
    class DOCKER orchestration;
    class PMGMT orchestration;

    %% Click Events for Data Source
    click PDB "https://github.com/phnguynmkhoi/streaming_data_pipeline/blob/main/debezium-connector-postgres.json"
    click PDB "https://github.com/phnguynmkhoi/streaming_data_pipeline/blob/main/sql/postgres.sql"
    click PDB "https://github.com/phnguynmkhoi/streaming_data_pipeline/blob/main/sql/trigger.sql"

    %% Click Events for Ingestion Layer
    click KAFKA "https://github.com/phnguynmkhoi/streaming_data_pipeline/blob/main/docker-compose.yml"

    %% Click Events for Processing Layer (Apache Spark)
    click SPARK "https://github.com/phnguynmkhoi/streaming_data_pipeline/blob/main/Dockerfile.spark"
    click SPARK "https://github.com/phnguynmkhoi/streaming_data_pipeline/blob/main/start-spark.sh"
    click SPARK "https://github.com/phnguynmkhoi/streaming_data_pipeline/blob/main/script/spark_extract_data_script.sh"
    click SPARK "https://github.com/phnguynmkhoi/streaming_data_pipeline/blob/main/src/main.py"
    click SPARK "https://github.com/phnguynmkhoi/streaming_data_pipeline/blob/main/src/data_generator.py"

    %% Click Events for Storage Components
    click MINIO "https://github.com/phnguynmkhoi/streaming_data_pipeline/blob/main/apps/extract_data.py"
    click PINOT "https://github.com/phnguynmkhoi/streaming_data_pipeline/tree/main/pinot/"

    %% Click Events for Orchestration & Management
    click DOCKER "https://github.com/phnguynmkhoi/streaming_data_pipeline/blob/main/docker-compose.yml"
    click PMGMT "https://github.com/phnguynmkhoi/streaming_data_pipeline/blob/main/script/create_all_schema.sh"
    click PMGMT "https://github.com/phnguynmkhoi/streaming_data_pipeline/blob/main/script/create_all_table.sh"
    click PMGMT "https://github.com/phnguynmkhoi/streaming_data_pipeline/blob/main/script/create_schema.sh"
    click PMGMT "https://github.com/phnguynmkhoi/streaming_data_pipeline/blob/main/script/create_table.sh"
    click PMGMT "https://github.com/phnguynmkhoi/streaming_data_pipeline/blob/main/script/script.sh"
```
