Data Reliability — Quality, CDC, Idempotency, Backfill
Purpose: reliability rules for quality gates, CDC selection, idempotency, backfill, replay, and rollback planning.
Contents
- Three-layer quality model
- CDC pattern selection
- Idempotency patterns
- Backfill and rollback
Three-Layer Quality Model
| Layer | Required checks |
|---|---|
| Source | freshness, volume, schema |
| Transform | uniqueness, completeness, validity, consistency |
| Sink | reconciliation, business rules, anomaly detection |
Use all three layers when the pipeline affects analytics, billing, or user-facing metrics.
Example Gate
def run_quality_gate(**context):
result = context.run_checkpoint(checkpoint_name="orders_checkpoint")
if not result["success"]:
raise AirflowException(f"Quality check failed: {result['run_results']}")
return resultCDC Pattern Selection
| Pattern | Latency | Complexity | Use Case |
|---|---|---|---|
| Timestamp-based | minutes to hours | low | simple incremental loads |
| Trigger-based | seconds | medium | legacy DBs without log access |
Log-based (Debezium) |
sub-second | high | real-time sync with minimal DB impact |
Use log-based CDC for low-latency, replay-friendly pipelines. Keep schema and delivery settings versioned.
Idempotency Patterns
Preferred options:
- deterministic idempotency keys
- Redis or state-store deduplication
- sink-side
UPSERT - Kafka transactions only when the end-to-end path justifies them
Deterministic Key
def generate_idempotency_key(event: dict) -> str:
components = [
event["source"],
event["entity_type"],
event["entity_id"],
event["event_type"],
event["timestamp"][:19],
]
return hashlib.sha256("|".join(components).encode()).hexdigest()Backfill And Rollback
Backfill Decision Matrix
| Scenario | Strategy | Risk |
|---|---|---|
| Schema change only | reprocess all | low |
| Recent bug fix | reprocess affected window | low |
| Logic change | full historical reprocess | medium |
| New source | incremental from source start | low |
Pre-Backfill Checklist
- production pipeline paused if required
- downstream consumers notified
- target-table or partition backup created
- monitoring thresholds adjusted
Minimal Backfill Runbook
- Pause the production DAG or consumer if needed.
- Clear or isolate the target range.
- Run the backfill command.
- Verify counts and quality checks.
- Resume normal processing.
airflow dags backfill \
--start-date YYYY-MM-DD \
--end-date YYYY-MM-DD \
--reset-dagruns \
pipeline_nameRollback Notes
Every backfill plan must include:
- restore path from backup tables, snapshots, or time-travel features
- resume path from checkpoint or retained event log
- downstream notification steps