Data Engineering · Chapter 7 · ~15 min · Intermediate
Data Quality, Schema Evolution & Anomaly Alerts
Build production data trust frameworks: Great Expectations / Soda contracts, breaking vs non-breaking schema evolution, drift detection, freshness SLAs, and automated circuit breakers.
- Implement automated data quality gates using declarative assertion contracts
- Classify backward, forward, and full schema evolution compatibility rules
- Detect statistical data drift, distribution skew, and sudden volume anomalies
- Design automated pipeline circuit breakers to quarantine corrupted partitions before serving
Data Quality, Schema Evolution & Anomaly Alerts: learn it visually
Build production data trust frameworks: Great Expectations / Soda contracts, breaking vs non-breaking schema evolution, drift detection, freshness SLAs, and automated circuit breakers.
1Everyday Intuition: The Municipal Water Treatment Plant
Municipal water utilities do not test water purity when it flows out of kitchen sinks. If water is tested only at the customer tap, an entire neighborhood could be poisoned before the laboratory results come back.
Instead, water plants install inline sensor gates at the river intake, after the sand filtration beds, and before chemical chlorination. If a turbidity sensor detects chemical contamination, an automatic circuit breaker valve trips instantly, diverting the dirty river water into a quarantine holding basin while keeping the clean city reservoir safe.
The Invisible Pipeline Killer
A pipeline completes with exit code 0 (success). However, a third of the rows contain negative payment amounts, null customer IDs, or future timestamps. Downstream ML models train on corrupt values and executives report incorrect financials.
Declarative Data Contracts
Teams define explicit expectations (contracts) on schemas and distributions. If incoming batches violate contracts, automated circuit breakers halt promotion and route dirty rows to a Dead-Letter Queue (DLQ).
What is 'Silent Data Corruption' in enterprise data pipelines?
2Under the Hood: Schema Evolution & Contract Rules
As upstream application microservices evolve, database schemas will inevitably change. Understanding compatibility types is vital to prevent breaking downstream pipelines:
1. Backward Compatibility
Consumers using the new schema can read data produced with older schemas. Example: adding an optional column with a default value.
2. Forward Compatibility
Consumers using older schemas can read data produced with the new schema. Example: deleting an optional column.
3. Breaking Changes
Renaming fields, deleting required columns, or altering data types (e.g. changing string to integer). Requires coordinated migration or consumer versioning.
Wrong idea: Hardcode rigid positional column indices in consumers
Accessing row tuples by integer index (e.g. row[3]). When an upstream microservice adds an optional 'discount_code' field, the ingestion pipeline crashes or writes discounts into customer names.
Real system: Enforce explicit schema registry compatibility rules
Using Avro or Protobuf schema registries with backward compatibility. New optional fields receive default values and consumer parsers ignore unmapped fields gracefully.
Which schema modification is strictly backward compatible?
3Hands-On: Test Quality Gates & Circuit Breakers
Inject corrupted records below and execute the quality contract gate. Watch how the automated circuit breaker isolates defective partitions into the Dead-Letter Queue while protecting clean marts:
Data Quality Gate & Quarantine Visualizer
Evaluate batch contracts against incoming data. Watch invalid records get quarantined into a Dead-Letter Queue (DLQ).
Raw webhook orders arriving from Stripe API. Payload schema: order_id, user_id, amount, currency.
analytics.ordersdlq.corrupted_ordersWhat action does an automated pipeline 'Circuit Breaker' take upon detecting critical contract failure?
4Bug Hunt: Fix Ingestion Quality & Quarantine Logic
The ingestion script below drops corrupt records without auditing them, allows negative prices into clean tables, and crashes when upstream services send new optional attributes. Fix the validation function:
🎯 Find and fix the bugs in the code above, then press Run & verify to test your solution.
Need a hint?
- Add a check for
amount >= 0before appending toclean_records. - Append rejected rows to
quarantine_recordsinstead of usingpass. - Access optional fields safely with
row.get('discount_code').
5Recap
- Silent Data Corruption happens when pipelines run without crashing but produce skewed or invalid numbers.
- Shift-Left Quality places assertions (non-null, range, uniqueness) immediately at the staging layer before records enter production marts.
- Schema Evolution requires strict compatibility management: adding optional fields with defaults is safe; renaming or deleting required fields breaks downstream models.
- Automated Circuit Breakers halt promotions and route tainted batches to Dead-Letter Queues (DLQs) for forensic audit.
Ready for Chapter 8? Mark this chapter as complete to proceed: