How ton-studio/ton-etl works
Project Type and Purpose
• The project is an indexing and decoding pipeline for the TON blockchain.
• Its goal is to ingest raw blockchain data (using a TON node and an indexer worker), store the data in a Postgres database, capture changes via Debezium into Kafka topics, process events with specialized parsers, and then export the processed data to an AWS S3-backed Data Lake (using AVRO file formatting).
• The README outlines components such as the TON node/indexer, DB setup, Debezium/Kafka integration, parser pipelines, and data lake exports.
File Structure for Architectural Clues
• Top-level directories:
• “database”: Contains configuration (e.g., docker-compose.yml, createdb.sql) for orchestrating the Postgres DB, Debezium, and Kafka.
• “indexer”: Contains docker-compose for running the TON index-worker component.
• “parser”: Extensive parser code modules, Docker configuration, and models for handling multiple event types (e.g., NFTs, jettons, swaps, gas trades, etc.).
• “datalake”: Contains scripts (main.py, generate_schema.py) and Dockerfiles for exporting processed data to an S3 Data Lake using AVRO serialized files.
• Other notable files:
• .github/workflows for CI/CD tests.
• Multiple docker-compose files that highlight the containerized deployment structure.
Core Components
a. TON Node + Indexer
• External TON Node (as per official documentation) connected to the TON indexer.
• TON indexer worker (from ton-index-worker) that ingests and indexes blockchain data.
b. Postgres Database
• Stores raw blockchain data (block, transactions, messages, jetton, NFT tables, etc.).
• Includes multiple schemas such as “public” for raw data, “parsed” for processed outputs, and “prices” for market metrics.
c. Change Data Capture with Debezium
• A Debezium connector (configured to capture changes in the Postgres DB) responsible for publishing change events.
d. Kafka Topics
• Kafka acts as the event streaming backbone.
• Change events from the database are sent to Kafka topics.
e. Parser Modules
• A suite of parsers (found in the “parser” directory) that subscribe to specific Kafka topics.
• They transform raw messages into domain-specific events (such as NFT events, jetton events, swaps, etc.) and update the parsed tables.
• They may also support recovery and state rebuilding functionalities.
f. Datalake Exporter
• Listens to specific Kafka topics.
• Exports processed data to an external destination – AWS S3 – using AVRO serialization.
• Relies on schema discovery (using scripts like generate_schema.py and schemas located in the datalake folder).
Relationships and Data Flow
• Data flows from the TON Node to the Indexer, which writes data to the Postgres DB.
• Debezium monitors the Postgres DB for changes and publishes the changes into Kafka topics.
• Parsers consume Kafka messages, process and transform the data, and then store the results (either back into the DB or forwarding them to separate services).
• Parallelly, the Datalake Exporter consumes topics from Kafka and sends data to S3.
• Deployment and orchestration are containerized using multiple docker-compose configurations (for database, indexer, parser, and data lake).
Architectural Patterns and Technologies
• Microservice-like modularization: Each component (indexer, parser, datalake exporter) is standalone.
• Event-driven architecture: Decouples components via Kafka topics and Debezium’s change data capture.
• Containerization: Each section is built and deployed using Docker (Dockerfiles and multiple docker-compose files).
• Data serialization: AVRO is used for exporting data to the data lake, showing an emphasis on schema management.
• Observability: Monitoring practices (like JMX exporter for Kafka) are part of the architecture.