Chapter 7 of 12
Course Progress0 of 12 completed (0%)

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.

Data Quality, Schema Evolution & Anomaly AlertsBuild production data trust frameworks: Great Expectations / Soda contracts, breaking vs non-breaking schema evolution, drift detection, freshness SLAs, and automated circuit breakers.UNDERSTANDData QualityFOLLOW THE FLOWSchema EvolutionAPPLY ITAnomaly AlertsData Quality, Schema Evolution & Anomaly AlertsBuild production data trust frameworks: Great Expectations / Soda contracts, breaking vs non-breaking schema evolution, drift detection, freshness SLAs, and automated circuit breakers.UNDERSTANDData QualityFOLLOW THE FLOWSchema EvolutionAPPLY ITAnomaly Alerts

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.

Silent Data Corruption

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.

Defensive Engineering

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).

Concept Check

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

Upstream adds `discount_code` → row[3] now reads discount instead of address!Positional parsing fragility · Unannounced schema breaking changes

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

Schema Registry v2 → Backward-compatible → Consumers ingest without interruptionSelf-describing records · Safe non-breaking schema evolution

Using Avro or Protobuf schema registries with backward compatibility. New optional fields receive default values and consumer parsers ignore unmapped fields gracefully.

Concept Check

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:

Contract Gate: Great Expectations v0.18

Data Quality Gate & Quarantine Visualizer

Evaluate batch contracts against incoming data. Watch invalid records get quarantined into a Dead-Letter Queue (DLQ).

Total Ingested
10,000
Incoming batch rows
Clean Orders Table
10,000
analytics.orders
Quarantined (DLQ)
0
quarantine.orders_dlq
Volume Z-Score
0.12 σ
Normal distribution
1. Ingestion Stream
Staging

Raw webhook orders arriving from Stripe API. Payload schema: order_id, user_id, amount, currency.

2. Contract Gates
IDLE
expect_column_to_exist("order_id")
expect_column_values_to_not_be_null("user_id")
expect_column_values_to_be_between("amount", 0)
3. Destination Routing
Serving
Clean Mart: 10000 rows promoted to analytics.orders
Quarantine DLQ: 0 rows isolated in dlq.corrupted_orders
Concept Check

What 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:

Data Quality · Assertion Contracts & Quarantine Routing
Python

🎯 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 >= 0 before appending to clean_records.
  • Append rejected rows to quarantine_records instead of using pass.
  • 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:

Enjoying this free lesson? Your support helps us build more free animated chapters.

Support Us