How would you test a data pipeline against upstream schema drift and contract changes?
Answer
Treat the producer schema and compatibility policy as a versioned contract, including field names, types, nullability, defaults and semantic meaning. Exercise additive, removed, renamed and incompatible changes against old and new consumers, and verify whether the pipeline accepts, transforms, quarantines or rejects each version deliberately. Add contract checks before deployment and production monitoring for unexpected shapes so silent data corruption cannot pass as a successful job.
Strong answer includes
- checks structural and semantic compatibility
- covers mixed producer and consumer versions
- prevents silent corruption with early validation and monitoring
Practical example
The example assumes PostgreSQL's public schema conventions and PostgreSQL-style information_schema type names.
WITH expected(column_name, data_type, is_nullable) AS (
VALUES
('user_id', 'bigint', 'NO'),
('email', 'text', 'YES'),
('created_at', 'timestamp with time zone', 'NO')
),
actual AS (
SELECT column_name, data_type, is_nullable
FROM information_schema.columns
WHERE table_schema = 'public'
AND table_name = 'users'
)
SELECT
COALESCE(e.column_name, a.column_name) AS column_name,
e.data_type AS expected_type,
a.data_type AS actual_type,
e.is_nullable AS expected_nullable,
a.is_nullable AS actual_nullable
FROM expected e
FULL OUTER JOIN actual a ON a.column_name = e.column_name
WHERE e.column_name IS NULL
OR a.column_name IS NULL
OR e.data_type <> a.data_type
OR e.is_nullable <> a.is_nullable;Schema drift is a contract problem, not only a parser error. Compare field presence, types and nullability before data processing, then separately test semantic changes, renamed fields, defaults and mixed producer/consumer versions.
Expected result: Zero rows when the physical schema matches the expected structural contract.