# luke-who/pinterest-data-pipeline542 architecture

> Architecture diagram of the GitHub repository luke-who/pinterest-data-pipeline542, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/luke-who/pinterest-data-pipeline542
- Repository: https://github.com/luke-who/pinterest-data-pipeline542

## Overview

##### Main Components to Highlight
- Data Ingestion:
- MySQL database (either local or Amazon RDS)
- Extraction of different data types (Pinterest post, geolocation, user data)
- Batch Processing:
- Kafka REST Proxy hosted on an EC2 instance (with user_posting_emulation.py as the core script)
- Kafka Connect for moving data into S3
- Streaming Processing:
- Amazon Kinesis (managed by user_posting_emulation_streaming.py)
- Data Transformation & Analysis:
- Databricks, which uses notebooks for transformation (e.g., pinterest_data_pipeline.ipynb)
- Orchestration:
- Apache Airflow with its DAGs (as evident from the airflow/dags directory)
- Infrastructure & External Dependencies:
- Additional AWS services: API Gateway, S3 for the data lake, MWAA for managed Airflow, and AWS Cloud Services in general

##### Relationships and Data Flow
- Data is initialy extracted from the MySQL database.
- For batch processing, data flows from the database into Kafka via the REST proxy (running on EC2), which is then connected through Kafka Connect to S3 storage. Databricks then accesses and transforms the data.
- For real-time processing, the data is piped into Amazon Kinesis. Kinesis streams then directly integrate with Databricks for immediate processing.
- Airflow orchestrates the entire pipeline, triggering jobs, managing dependencies between batch and stream processing, and integrating with Databricks for transformation steps.

##### Important Architectural Patterns and Design Principles
- Separation of Concerns:
- Clearly separate ingestion, processing, transformation, and orchestration layers.
- Scalability & Fault Tolerance:
- Use managed services (like MWAA for Airflow, Kinesis for streaming) that provide scalability.
- Hybrid Setup:
- Modularity:
- Core scripts (Python scripts and Jupyter notebooks) handle specific tasks, making it easier to update or extend individual components.

##### Relevant Technologies and Frameworks
- Python (as the central programming language)
- MySQL (for the database)
- Apache Kafka (batch ingestion)
- Amazon Kinesis (streaming data)
- Apache Airflow (workflow orchestration)
- Databricks (data transformation and analysis)
- AWS services like S3, EC2, API Gateway, and MWAA

##### Detailed Elements
- Clear component labeling for every piece of the system.
- Data Sources
- Processing Layers (batch vs. streaming)
- Orchestration Modules
- External/Managed Services
- If possible, include a mini-overview of the hybrid architecture showing both local (e.g., local Apache Airflow, local MySQL) and cloud-based components (AWS services and Databricks).

##### Final Advice
- Maintain simplicity in visuals while ensuring all critical components and interactions are represented.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Source Layer
    subgraph "Data Source Layer"
        mysql["MySQL Database"]:::source
    end

    %% Batch Processing Layer
    subgraph "Batch Processing"
        kafkaEC2["EC2 (Kafka REST Proxy)"]:::aws
        kafkaConnect["Kafka Connect"]:::aws
        s3["S3 Storage (Data Lake)"]:::aws
    end

    %% Streaming Processing Layer
    subgraph "Streaming Processing"
        kinesis["Amazon Kinesis"]:::aws
    end

    %% Data Transformation & Analysis Layer
    subgraph "Data Transformation & Analysis"
        databricksOutput["Databricks Notebook (Output)"]:::transformation
        databricksSource["Databricks Notebook (Source)"]:::transformation
    end

    %% Orchestration Layer
    subgraph "Orchestration"
        airflow["Apache Airflow DAGs (MWAA)"]:::orchestration
    end

    %% Infrastructure & External Dependencies
    subgraph "Infrastructure & External Dependencies"
        apiGateway["API Gateway"]:::aws
        awsServices["AWS Cloud Services"]:::aws
        diagrams["Infrastructure Diagrams (Reference)"]:::external
    end

    %% Data Flow Relationships
    mysql -->|"extracts"| kafkaEC2
    mysql -->|"extracts"| kinesis

    kafkaEC2 -->|"processes"| kafkaConnect
    kafkaConnect -->|"transfers"| s3
    s3 -->|"supplies"| databricksOutput
    kinesis -->|"streams"| databricksSource

    %% Orchestration Connections
    airflow -->|"triggers"| kafkaEC2
    airflow -->|"triggers"| kinesis
    airflow -->|"orchestrates"| databricksOutput
    airflow -->|"orchestrates"| databricksSource

    %% AWS Integration Connections
    apiGateway -->|"manages"| s3
    awsServices -->|"supports"| apiGateway

    %% External Reference Connection
    diagrams ---|"reference"| airflow

    %% Styling: Define Classes
    classDef source fill:#A7C7E7,stroke:#333,stroke-width:2px;
    classDef aws fill:#FFD580,stroke:#333,stroke-width:2px;
    classDef transformation fill:#C1FFC1,stroke:#333,stroke-width:2px;
    classDef orchestration fill:#DDA0DD,stroke:#333,stroke-width:2px;
    classDef external fill:#F0E68C,stroke:#333,stroke-width:2px;

    %% Click Events for Component Mapping
    click mysql "https://github.com/luke-who/pinterest-data-pipeline542/blob/main/pinterest_data_db.sql"
    click kafkaEC2 "https://github.com/luke-who/pinterest-data-pipeline542/blob/main/user_posting_emulation.py"
    click kinesis "https://github.com/luke-who/pinterest-data-pipeline542/blob/main/user_posting_emulation_streaming.py"
    click databricksOutput "https://github.com/luke-who/pinterest-data-pipeline542/blob/main/databricks_notebook_output/pinterest_data_pipeline.ipynb"
    click databricksSource "https://github.com/luke-who/pinterest-data-pipeline542/blob/main/pinterest_data_pipeline.ipynb"
    click diagrams "https://github.com/luke-who/pinterest-data-pipeline542/tree/main/img"
```
