Skill — Data Pipeline Design
When this skill activates
Any task involving designing data ingestion, transformation, or delivery pipelines.
Includes ETL/ELT architecture, batch vs streaming decisions, schema management,
data quality enforcement, and pipeline orchestration.
Mandatory actions when this skill is active
Before writing any code
- Define data contract (schema, freshness SLA, volume, sources, consumers).
- Decide batch vs streaming (latency requirement is the primary driver).
- Identify exactly-once requirements (financial data = must, analytics = can relax).
- Plan schema evolution strategy (backward-compatible changes only).
During implementation
- Implement data quality gates before consumers see data.
- Use schema registry for all structured data exchange.
- Make all transformations idempotent (safe to re-run).
- Include dead-letter queues for malformed/failed records.
- Add lineage tracking (where did this data come from?).
- Monitor freshness SLA with alerting.
After implementation
- Verify backfill capability (can we reprocess historical data?).
- Test schema evolution (add column, change type) without breaking consumers.
- Confirm quality gates catch known bad data patterns.
- Validate freshness SLA is met under normal load.
- Document data lineage for every output table.
ETL vs ELT Decision
ETL (Extract → Transform → Load)
- Transform before loading into destination.
- Best for: structured sources, known transformations, data quality at boundary.
- Tools: Airflow + Python, Spark, custom processors.
- Advantage: Clean data in warehouse, fewer warehouse compute costs.
ELT (Extract → Load → Transform)
- Load raw data, transform in the warehouse/lakehouse.
- Best for: diverse sources, evolving transformations, exploratory analysis.
- Tools: Fivetran/Airbyte (extract+load) + dbt (transform).
- Advantage: Raw data preserved, transformations versioned and testable.
Decision Matrix
| Factor |
ETL |
ELT |
| Source diversity |
Low (known schema) |
High (many sources) |
| Transformation stability |
Stable, well-defined |
Evolving, experimental |
| Data volume |
Moderate |
Very high |
| Warehouse compute cost |
Sensitive |
Acceptable |
| Need raw data access |
No |
Yes |
Batch vs Streaming
Batch Processing
- Process data in scheduled intervals (hourly, daily).
- Simpler implementation, easier debugging.
- Cheaper for high-volume, latency-tolerant workloads.
- Tools: Airflow, Spark Batch, dbt.
Stream Processing
- Process events as they arrive (real-time or near-real-time).
- Complex: windowing, ordering, late-arriving data.
- Required when business needs data in <5 minutes.
- Tools: Kafka Streams, Flink, Spark Structured Streaming.
Decision: Use streaming only when
- Business requires <5 minute data freshness.
- Events must trigger immediate actions (fraud, alerts).
- Source naturally produces events (clickstream, IoT).
Otherwise, batch is simpler and cheaper.
Exactly-Once Processing
Why It's Hard
Network failures + retries = potential duplicates.
Strategies
- Idempotent sinks: Write operations produce same result regardless of repetition (UPSERT, conditional write).
- Deduplication keys: Assign unique ID to each record, deduplicate at sink.
- Checkpointing: Record progress markers, resume from checkpoint on failure.
- Transactional outbox: Atomic write to source + outbox table, separate relay.
Practical Guarantees
| Guarantee |
Cost |
Use When |
| At-most-once |
Lowest |
Metrics where loss is acceptable |
| At-least-once + idempotent sink |
Medium |
Most pipelines |
| Exactly-once (Kafka transactions) |
Highest |
Financial, billing |
Schema Registry
Purpose
- Central source of truth for data schemas.
- Enforce compatibility between producers and consumers.
- Enable schema evolution without breaking downstream.
Compatibility Modes
- Backward compatible: New schema can read old data (add optional fields).
- Forward compatible: Old schema can read new data (remove optional fields).
- Full compatible: Both backward and forward (safest, most restrictive).
Rules
- All structured data exchange goes through schema registry.
- Use Avro or Protobuf (self-describing, compact, evolvable).
- Test schema changes against compatibility rules in CI.
- Never break backward compatibility without coordinated migration.
Data Quality Gates
Checks to Implement
| Check |
Example |
Severity |
| Not null |
Primary keys must exist |
CRITICAL |
| Uniqueness |
No duplicate records |
CRITICAL |
| Range |
Age between 0-150 |
HIGH |
| Freshness |
Data < 1 hour old |
HIGH |
| Volume |
Row count ±10% of expected |
MEDIUM |
| Referential |
Foreign keys resolve |
MEDIUM |
| Format |
Email matches pattern |
LOW |
Implementation
- Run quality checks BEFORE exposing data to consumers.
- Quarantine failing records in dead-letter table.
- Alert on quality degradation trends.
- Track quality metrics over time (quality score per table).
Pipeline Orchestration
Airflow DAG Best Practices
- One DAG per logical pipeline.
- Idempotent tasks (re-runnable without side effects).
- Explicit dependencies (no implicit ordering).
- SLA alerts for late-running pipelines.
- Backfill support (catchup=True with idempotent tasks).
- Retry with exponential backoff for transient failures.
Monitoring
- Freshness SLA: alert when data is older than threshold.
- Pipeline duration: alert on >2x normal runtime.
- Record count: alert on ±20% deviation from expected.
- Error rate: alert on >1% record failures.
Backfill Strategy
Requirements
- Every pipeline must support historical reprocessing.
- Backfill must be idempotent (running twice = same result).
- Partition by date for efficient backfill of specific ranges.
- Backfill should not interfere with production pipeline runs.
Self-check
1---2name: data-pipeline-design3description: Skill — Data Pipeline Design4---56# Skill — Data Pipeline Design78## When this skill activates9Any task involving designing data ingestion, transformation, or delivery pipelines.10Includes ETL/ELT architecture, batch vs streaming decisions, schema management,11data quality enforcement, and pipeline orchestration.1213## Mandatory actions when this skill is active1415### Before writing any code161. Define data contract (schema, freshness SLA, volume, sources, consumers).172. Decide batch vs streaming (latency requirement is the primary driver).183. Identify exactly-once requirements (financial data = must, analytics = can relax).194. Plan schema evolution strategy (backward-compatible changes only).2021### During implementation22- Implement data quality gates before consumers see data.23- Use schema registry for all structured data exchange.24- Make all transformations idempotent (safe to re-run).25- Include dead-letter queues for malformed/failed records.26- Add lineage tracking (where did this data come from?).27- Monitor freshness SLA with alerting.2829### After implementation30- Verify backfill capability (can we reprocess historical data?).31- Test schema evolution (add column, change type) without breaking consumers.32- Confirm quality gates catch known bad data patterns.33- Validate freshness SLA is met under normal load.34- Document data lineage for every output table.3536## ETL vs ELT Decision3738### ETL (Extract → Transform → Load)39- Transform before loading into destination.40- Best for: structured sources, known transformations, data quality at boundary.41- Tools: Airflow + Python, Spark, custom processors.42- Advantage: Clean data in warehouse, fewer warehouse compute costs.4344### ELT (Extract → Load → Transform)45- Load raw data, transform in the warehouse/lakehouse.46- Best for: diverse sources, evolving transformations, exploratory analysis.47- Tools: Fivetran/Airbyte (extract+load) + dbt (transform).48- Advantage: Raw data preserved, transformations versioned and testable.4950### Decision Matrix51| Factor | ETL | ELT |52|--------|-----|-----|53| Source diversity | Low (known schema) | High (many sources) |54| Transformation stability | Stable, well-defined | Evolving, experimental |55| Data volume | Moderate | Very high |56| Warehouse compute cost | Sensitive | Acceptable |57| Need raw data access | No | Yes |5859## Batch vs Streaming6061### Batch Processing62- Process data in scheduled intervals (hourly, daily).63- Simpler implementation, easier debugging.64- Cheaper for high-volume, latency-tolerant workloads.65- Tools: Airflow, Spark Batch, dbt.6667### Stream Processing68- Process events as they arrive (real-time or near-real-time).69- Complex: windowing, ordering, late-arriving data.70- Required when business needs data in <5 minutes.71- Tools: Kafka Streams, Flink, Spark Structured Streaming.7273### Decision: Use streaming only when74- Business requires <5 minute data freshness.75- Events must trigger immediate actions (fraud, alerts).76- Source naturally produces events (clickstream, IoT).7778Otherwise, batch is simpler and cheaper.7980## Exactly-Once Processing8182### Why It's Hard83Network failures + retries = potential duplicates.8485### Strategies861. **Idempotent sinks**: Write operations produce same result regardless of repetition (UPSERT, conditional write).872. **Deduplication keys**: Assign unique ID to each record, deduplicate at sink.883. **Checkpointing**: Record progress markers, resume from checkpoint on failure.894. **Transactional outbox**: Atomic write to source + outbox table, separate relay.9091### Practical Guarantees92| Guarantee | Cost | Use When |93|-----------|------|----------|94| At-most-once | Lowest | Metrics where loss is acceptable |95| At-least-once + idempotent sink | Medium | Most pipelines |96| Exactly-once (Kafka transactions) | Highest | Financial, billing |9798## Schema Registry99100### Purpose101- Central source of truth for data schemas.102- Enforce compatibility between producers and consumers.103- Enable schema evolution without breaking downstream.104105### Compatibility Modes106- **Backward compatible**: New schema can read old data (add optional fields).107- **Forward compatible**: Old schema can read new data (remove optional fields).108- **Full compatible**: Both backward and forward (safest, most restrictive).109110### Rules111- All structured data exchange goes through schema registry.112- Use Avro or Protobuf (self-describing, compact, evolvable).113- Test schema changes against compatibility rules in CI.114- Never break backward compatibility without coordinated migration.115116## Data Quality Gates117118### Checks to Implement119| Check | Example | Severity |120|-------|---------|----------|121| Not null | Primary keys must exist | CRITICAL |122| Uniqueness | No duplicate records | CRITICAL |123| Range | Age between 0-150 | HIGH |124| Freshness | Data < 1 hour old | HIGH |125| Volume | Row count ±10% of expected | MEDIUM |126| Referential | Foreign keys resolve | MEDIUM |127| Format | Email matches pattern | LOW |128129### Implementation130- Run quality checks BEFORE exposing data to consumers.131- Quarantine failing records in dead-letter table.132- Alert on quality degradation trends.133- Track quality metrics over time (quality score per table).134135## Pipeline Orchestration136137### Airflow DAG Best Practices138- One DAG per logical pipeline.139- Idempotent tasks (re-runnable without side effects).140- Explicit dependencies (no implicit ordering).141- SLA alerts for late-running pipelines.142- Backfill support (catchup=True with idempotent tasks).143- Retry with exponential backoff for transient failures.144145### Monitoring146- Freshness SLA: alert when data is older than threshold.147- Pipeline duration: alert on >2x normal runtime.148- Record count: alert on ±20% deviation from expected.149- Error rate: alert on >1% record failures.150151## Backfill Strategy152153### Requirements154- Every pipeline must support historical reprocessing.155- Backfill must be idempotent (running twice = same result).156- Partition by date for efficient backfill of specific ranges.157- Backfill should not interfere with production pipeline runs.158159## Self-check160- [ ] Data contract defined (schema, freshness, volume).161- [ ] Batch vs streaming decision justified by latency requirement.162- [ ] Quality gates implemented before consumer access.163- [ ] Schema registered and compatibility mode set.164- [ ] All transformations are idempotent.165- [ ] Dead-letter queue configured for failures.166- [ ] Backfill capability tested.167- [ ] Freshness SLA monitored with alerting.168- [ ] Data lineage documented.