Crypto Data Pipeline: Idempotency, Airflow & Docker
Designing production-grade data pipelines with a focus on idempotency, automated orchestration with Airflow, and containerization with Docker.
Crypto Data Pipeline
Data pipeline design Data Engineering
A data pipeline is a series of steps that moves data from a source to a destination in a usable form. In this project: CoinGecko API → PostgreSQL → dbt transformations → Metabase dashboard. Each step has one job and hands off cleanly to the next.
The three-layer architecture used here maps directly to the dbt pattern, but applied to a live API instead of event data:
# Layer 1: Ingestion (Python) # Fetch from API, write raw rows to PostgreSQL # Layer 2: Staging (dbt views) # stg_coin_prices: clean, rename, cast types # Layer 3: Marts (dbt tables) # mart_daily_prices: OHLC + 7-day rolling avg
Why separate ingestion from transformation?
- Raw data is preserved unchanged
- Can rerun transformations without re-fetching
- Bugs in transformation don't lose raw data
ELT vs ETL
- This project uses ELT: Extract → Load raw → Transform in DB.
- ELT is now standard because modern warehouses are cheap and fast.
Idempotency Data Engineering
Idempotency means: running the same operation twice produces the same result as running it once. This is one of the most important properties in data engineering.
In the crypto pipeline this was achieved with a single SQL clause:
-- With idempotency: running twice = same result INSERT INTO raw.coin_prices (coin_id, fetched_at, price) VALUES ('bitcoin', '2026-01-01', 95000) ON CONFLICT (coin_id, fetched_at) DO NOTHING;
Why does this matter? Pipelines fail. If ingestion isn't idempotent, a retry fills the database with duplicate rows and every downstream metric is wrong.
Orchestration & Apache Airflow Data Engineering
Orchestration is the scheduling and coordination of pipeline steps. Airflow lets you define a DAG (Directed Acyclic Graph), a set of tasks with dependencies, and schedules it automatically.
# A DAG defines tasks and their order from airflow import DAG with DAG('crypto_pipeline', schedule_interval='30 3 * * *') as dag: ingest = PythonOperator(task_id='ingest_from_api', ...) transform = PythonOperator(task_id='run_dbt_models', ...) ingest >> transform
What Airflow gives you
- Automatic scheduling via cron
- Retry logic on failure
- Task dependency management
- Visual DAG UI
LocalExecutor
- Runs tasks as subprocesses on one machine.
- Simple setup, correct for single-machine pipelines.
Docker: why it matters for data pipelines Infrastructure
Docker packages your code and all its dependencies into a container, a self-contained unit that runs the same way on any machine.
# Start PostgreSQL via Docker docker run --name crypto-db -p 5432:5432 -d postgres:15
Containers are ephemeral
Data written inside a container disappears when it stops, unless you use volumes. Always mount a volume for
databases: -v postgres_data:/var/lib/postgresql/data.
Resources: Data Engineering
Covers containers, images, volumes, and compose.
Covers DAGs, operators, and scheduling.
O'Reilly. Best big-picture book on the field.
Decision framework
Choosing the right architecture for Data Engineering.
Simplicity vs robustness
A cron job is simple. Airflow is robust. Choose based on the cost of failure, if data delay is a minor issue, cron is fine. If it's business-critical, use Airflow.