# sun-9545sunoj/streaming-lakehouse-with-cdc-iceberg architecture

> Architecture diagram of the GitHub repository sun-9545sunoj/streaming-lakehouse-with-cdc-iceberg, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sun-9545sunoj/streaming-lakehouse-with-cdc-iceberg
- Repository: https://github.com/sun-9545sunoj/streaming-lakehouse-with-cdc-iceberg

## Overview

This repository demonstrates a Kafka-to-Iceberg CDC lakehouse and evaluates its behavior through three experiments. The main runtime flow generates keyed order events, streams them through Spark into an Iceberg table on HDFS, and exposes that table to ClickHouse for queries. Separate experiment branches measure file-planning and compaction, compare copy-on-write with merge-on-read, and test recovery after driver failures. Maintenance and verification support table operations and correctness checks. Edges reflect the sampled source and README; experiment internals not sampled are represented only at their documented harness level.

Main entry points: [`src/ingest_kafka.py`](https://github.com/sun-9545sunoj/streaming-lakehouse-with-cdc-iceberg/blob/main/src/ingest_kafka.py) (Kafka ingestion), [`src/spark_session.py`](https://github.com/sun-9545sunoj/streaming-lakehouse-with-cdc-iceberg/blob/main/src/spark_session.py) (Spark session builder), [`src/query_clickhouse.py`](https://github.com/sun-9545sunoj/streaming-lakehouse-with-cdc-iceberg/blob/main/src/query_clickhouse.py) (ClickHouse query), [`src/verify.py`](https://github.com/sun-9545sunoj/streaming-lakehouse-with-cdc-iceberg/blob/main/src/verify.py) (Correctness verifier)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_generation["CDC generation"]
  node_file_producer["File CDC producer<br/>[producer.py]"]
  node_bulk_generator["Bulk generator<br/>[generate_bulk.py]"]
  node_kafka_producer["Kafka CDC producer<br/>[producer_kafka.py]"]
  node_kafka["Kafka topic"]
end

subgraph group_pipeline["Ingestion and storage"]
  node_file_ingest["File ingestion<br/>[ingest.py]"]
  node_kafka_ingest["Kafka ingestion<br/>[ingest_kafka.py]"]
  node_p2_ingest["Small-file ingestion<br/>[ingest_p2.py]"]
  node_spark_session["Spark session builder<br/>[spark_session.py]"]
  node_hdfs[("HDFS storage")]
  node_iceberg[("Iceberg table")]
end

subgraph group_operations["Table operations"]
  node_maintain["Iceberg maintenance<br/>[maintain.py]"]
  node_reset["Trial reset<br/>[reset_e3.py]"]
  node_verifier["Correctness verifier<br/>[verify.py]"]
end

subgraph group_experiments["Evaluation and query"]
  node_e1["Planning experiment<br/>[e1_planning.py]"]
  node_e2["COW/MOR experiment<br/>[e2_cow_mor.py]"]
  node_e3["Failure experiment<br/>[e3_chaos.sh]"]
  node_clickhouse_query["ClickHouse query"]
  node_clickhouse[("ClickHouse")]
end

node_operator(("Operator"))

node_operator -->|"starts"| node_kafka_producer
node_kafka_producer -->|"publishes events"| node_kafka
node_kafka -->|"streams events"| node_kafka_ingest
node_kafka_ingest -->|"builds session"| node_spark_session
node_kafka_ingest -->|"merges batches"| node_iceberg
node_file_ingest -->|"reads CDC files"| node_hdfs
node_file_ingest -->|"merges batches"| node_iceberg
node_p2_ingest -->|"merges batches"| node_iceberg
node_kafka_ingest -->|"checkpoints stream"| node_hdfs
node_maintain -->|"builds session"| node_spark_session
node_maintain -->|"runs procedures"| node_iceberg
node_verifier -->|"builds session"| node_spark_session
node_verifier -->|"checks table"| node_iceberg
node_reset -->|"builds session"| node_spark_session
node_reset -->|"drops table"| node_iceberg
node_operator -->|"runs"| node_e1
node_operator -->|"runs"| node_e2
node_operator -->|"runs"| node_e3
node_e3 -->|"uses verifier"| node_verifier
node_operator -->|"runs"| node_clickhouse_query
node_clickhouse_query -->|"queries table"| node_clickhouse
node_clickhouse_query -->|"reads Iceberg"| node_hdfs

click node_file_producer "https://github.com/sun-9545sunoj/streaming-lakehouse-with-cdc-iceberg/blob/main/src/producer.py"
click node_bulk_generator "https://github.com/sun-9545sunoj/streaming-lakehouse-with-cdc-iceberg/blob/main/src/generate_bulk.py"
click node_kafka_producer "https://github.com/sun-9545sunoj/streaming-lakehouse-with-cdc-iceberg/blob/main/src/producer_kafka.py"
click node_file_ingest "https://github.com/sun-9545sunoj/streaming-lakehouse-with-cdc-iceberg/blob/main/src/ingest.py"
click node_kafka_ingest "https://github.com/sun-9545sunoj/streaming-lakehouse-with-cdc-iceberg/blob/main/src/ingest_kafka.py"
click node_p2_ingest "https://github.com/sun-9545sunoj/streaming-lakehouse-with-cdc-iceberg/blob/main/src/ingest_p2.py"
click node_spark_session "https://github.com/sun-9545sunoj/streaming-lakehouse-with-cdc-iceberg/blob/main/src/spark_session.py"
click node_maintain "https://github.com/sun-9545sunoj/streaming-lakehouse-with-cdc-iceberg/blob/main/src/maintain.py"
click node_reset "https://github.com/sun-9545sunoj/streaming-lakehouse-with-cdc-iceberg/blob/main/src/reset_e3.py"
click node_verifier "https://github.com/sun-9545sunoj/streaming-lakehouse-with-cdc-iceberg/blob/main/src/verify.py"
click node_e1 "https://github.com/sun-9545sunoj/streaming-lakehouse-with-cdc-iceberg/blob/main/bench/e1_planning.py"
click node_e2 "https://github.com/sun-9545sunoj/streaming-lakehouse-with-cdc-iceberg/blob/main/bench/e2_cow_mor.py"
click node_e3 "https://github.com/sun-9545sunoj/streaming-lakehouse-with-cdc-iceberg/blob/main/bench/e3_chaos.sh"
click node_clickhouse_query "https://github.com/sun-9545sunoj/streaming-lakehouse-with-cdc-iceberg/blob/main/src/query_clickhouse.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_file_producer,node_bulk_generator,node_kafka_producer,node_kafka toneBlue
class node_file_ingest,node_kafka_ingest,node_p2_ingest,node_spark_session,node_hdfs,node_iceberg toneAmber
class node_maintain,node_reset,node_verifier toneMint
class node_e1,node_e2,node_e3,node_clickhouse_query,node_clickhouse toneRose
class node_operator toneIndigo
```

## Components

### CDC generation

- [File CDC producer](https://github.com/sun-9545sunoj/streaming-lakehouse-with-cdc-iceberg/blob/main/src/producer.py): `src/producer.py`
- [Bulk generator](https://github.com/sun-9545sunoj/streaming-lakehouse-with-cdc-iceberg/blob/main/src/generate_bulk.py): `src/generate_bulk.py`
- [Kafka CDC producer](https://github.com/sun-9545sunoj/streaming-lakehouse-with-cdc-iceberg/blob/main/src/producer_kafka.py): `src/producer_kafka.py`
- **Kafka topic**

### Ingestion and storage

- [File ingestion](https://github.com/sun-9545sunoj/streaming-lakehouse-with-cdc-iceberg/blob/main/src/ingest.py): `src/ingest.py`
- [Kafka ingestion](https://github.com/sun-9545sunoj/streaming-lakehouse-with-cdc-iceberg/blob/main/src/ingest_kafka.py): `src/ingest_kafka.py`
- [Small-file ingestion](https://github.com/sun-9545sunoj/streaming-lakehouse-with-cdc-iceberg/blob/main/src/ingest_p2.py): `src/ingest_p2.py`
- [Spark session builder](https://github.com/sun-9545sunoj/streaming-lakehouse-with-cdc-iceberg/blob/main/src/spark_session.py): `src/spark_session.py`
- **HDFS storage**
- **Iceberg table**

### Table operations

- [Iceberg maintenance](https://github.com/sun-9545sunoj/streaming-lakehouse-with-cdc-iceberg/blob/main/src/maintain.py): `src/maintain.py`
- [Trial reset](https://github.com/sun-9545sunoj/streaming-lakehouse-with-cdc-iceberg/blob/main/src/reset_e3.py): `src/reset_e3.py`
- [Correctness verifier](https://github.com/sun-9545sunoj/streaming-lakehouse-with-cdc-iceberg/blob/main/src/verify.py): `src/verify.py`

### Evaluation and query

- [Planning experiment](https://github.com/sun-9545sunoj/streaming-lakehouse-with-cdc-iceberg/blob/main/bench/e1_planning.py): `bench/e1_planning.py`
- [COW/MOR experiment](https://github.com/sun-9545sunoj/streaming-lakehouse-with-cdc-iceberg/blob/main/bench/e2_cow_mor.py): `bench/e2_cow_mor.py`
- [Failure experiment](https://github.com/sun-9545sunoj/streaming-lakehouse-with-cdc-iceberg/blob/main/bench/e3_chaos.sh): `bench/e3_chaos.sh`
- [ClickHouse query](https://github.com/sun-9545sunoj/streaming-lakehouse-with-cdc-iceberg/blob/main/src/query_clickhouse.py): `src/query_clickhouse.py`
- **ClickHouse**

### Other components

- **Operator**

## Connections

- Operator → Kafka CDC producer: starts (evidence: `README.md`)
- Kafka CDC producer → Kafka topic: publishes events (evidence: `src/producer_kafka.py`)
- Kafka topic → Kafka ingestion: streams events (evidence: `src/ingest_kafka.py`)
- Kafka ingestion → Spark session builder: builds session (evidence: `src/ingest_kafka.py`)
- Kafka ingestion → Iceberg table: merges batches (evidence: `src/ingest_kafka.py`)
- File ingestion → HDFS storage: reads CDC files (evidence: `src/ingest.py`)
- File ingestion → Iceberg table: merges batches (evidence: `src/ingest.py`)
- Small-file ingestion → Iceberg table: merges batches (evidence: `src/ingest_p2.py`)
- Kafka ingestion → HDFS storage: checkpoints stream (evidence: `src/ingest_kafka.py`)
- Iceberg maintenance → Spark session builder: builds session (evidence: `src/maintain.py`)
- Iceberg maintenance → Iceberg table: runs procedures (evidence: `src/maintain.py`)
- Correctness verifier → Spark session builder: builds session (evidence: `src/verify.py`)
- Correctness verifier → Iceberg table: checks table (evidence: `src/verify.py`)
- Trial reset → Spark session builder: builds session (evidence: `src/reset_e3.py`)
- Trial reset → Iceberg table: drops table (evidence: `src/reset_e3.py`)
- Operator → Planning experiment: runs (evidence: `README.md`)
- Operator → COW/MOR experiment: runs (evidence: `README.md`)
- Operator → Failure experiment: runs (evidence: `README.md`)
- Failure experiment → Correctness verifier: uses verifier (evidence: `README.md`)
- Operator → ClickHouse query: runs (evidence: `README.md`)
- ClickHouse query → ClickHouse: queries table (evidence: `src/query_clickhouse.py`)
- ClickHouse query → HDFS storage: reads Iceberg (evidence: `src/query_clickhouse.py`)
