Design an ETL pipeline

Difficulty: MEDIUMCategory: HLDFrequency: 1Asked On 2020-07-01

Problem Statement

Design a scalable, reliable, and fault-tolerant ETL (Extract-Transform-Load) pipeline that ingests raw data from multiple sources, processes and transforms it into a structured format, and loads it into a data warehouse or analytics system for reporting and business intelligence.


The system should efficiently handle high-volume, real-time or batch data, ensure data quality, and be extensible for new data sources and transformations.


📋 Functional Requirements


1.Data Extraction
•Support multiple input sources:
•Relational databases (e.g., MySQL, PostgreSQL)
•APIs / event streams (e.g., Kafka, webhooks)
•Flat files (CSV, JSON, Parquet) from storage (S3, GCS, etc.)
•Support both batch and streaming ingestion.
2.Data Transformation
•Clean and normalize data (handle missing values, duplicates, type mismatches).
•Apply business logic transformations (aggregations, joins, filtering, enrichment).
•Support schema evolution and data validation.
3.Data Loading
•Load processed data into target systems:
•Data warehouse (e.g., Snowflake, Redshift, BigQuery)
•Data lake (S3, HDFS)
•Support incremental updates (change data capture) and full reloads.
4.Workflow Orchestration
•Manage job scheduling, dependency resolution, and retry logic.
•Support DAG (Directed Acyclic Graph)-based workflows.
5.Monitoring & Logging
•Provide metrics for throughput, latency, error rates.
•Expose logs and alerts for job failures.
6.Schema & Metadata Management
•Track schema versions, source metadata, and lineage for traceability.
7.Security & Access Control
•Encrypt data in transit and at rest.
•Control access via IAM roles or API tokens.


⚙️ Non-Functional Requirements


AspectRequirement


Scalability

Handle terabytes of data daily and scale horizontally for new sources.


Fault Tolerance

Resume from last successful checkpoint in case of failures.


Data Integrity

Guarantee exactly-once or at-least-once processing semantics.


Performance

Low latency for streaming data; efficient resource usage for batch.


Observability

Expose job metrics, lineage, and audit logs.


Extensibility

Easily add new data sources, transformation steps, or sinks.


🧠 Key Components


1.Data Source Connectors
•Modules to pull data from databases, APIs, message queues, or storage.
2.Ingestion Layer
•Handles batch/stream ingestion using systems like Kafka, Flink, or Spark Streaming.
3.Transformation Engine
•Applies cleaning, enrichment, aggregation, and joins using a compute framework (e.g., Spark, Beam, Flink).
4.Data Loader
•Writes transformed data to the target store (data warehouse/lake) with schema validation.
5.Metadata & Schema Registry
•Maintains schema versions, job definitions, and data lineage.
6.Workflow Orchestrator
•Manages job execution, retries, dependencies (Airflow, Dagster, Prefect).
7.Monitoring & Alerting
•Tracks job health, throughput, latency, and errors; sends alerts via email or Slack.
8.Storage Layer
•Raw zone (unprocessed), staging zone (transformed), and curated zone (final data).


🏗️ High-Level Architecture Overview

1 2 +---------------------+ 3 | Data Sources | 4 | (DBs, APIs, Files) | 5 +----------+----------+ 6 | 7 ▼ 8 +---------------------+ 9 | Ingestion Layer | 10 | (Kafka / Spark / S3)| 11 +----------+----------+ 12 | 13 ▼ 14 +---------------------+ 15 | Transformation Engine| 16 | (Spark / Beam / Flink)| 17 +----------+----------+ 18 | 19 ▼ 20 +---------------------+ 21 | Data Loader | 22 | (Warehouse / Lake) | 23 +----------+----------+ 24 | 25 ▼ 26 +----------------------+ 27 | Metadata & Monitoring| 28 | (Airflow, Prometheus)| 29 +----------------------+


🔍 Design Discussion Points


•Should the pipeline be batch, real-time, or hybrid?
•How to ensure idempotency and exactly-once delivery?
•How will schema evolution (e.g., new columns) be handled?
•How to manage data partitioning and checkpointing?
•What trade-offs exist between cost, latency, and freshness?
•How can data lineage and auditing be built into the system?


✅ Summary

Design a scalable ETL pipeline that ingests raw data from diverse sources, applies transformations for quality and business logic, and loads it into a centralized data warehouse — with strong guarantees for reliability, scalability, and observability.


Solution

Comments