VAYULearn
Colour theme
Investigate a failure
VAYU Learn

Kafka & Streaming

Schema Evolution Without Breaking Downstream Systems

Every Schema Change Is a Potential Breaking Change for Downstream Teams. Here Is How to Evolve Schemas Without Incidents.

Kafka & StreamingData Architecture & Reliability
Schema evolution isn’t about changing fields safely - it’s about ensuring every downstream consumer keeps working. Compatibility checks, contract tests, and controlled migrations prevent deployments from becoming production incidents.

TL;DR

  • Backward and forward compatibility are precise, different guarantees — most teams use the terms loosely and end up enforcing neither
  • Avro was built for schema evolution and enforces compatibility rules at the format level; Parquet supports evolution with real caveats; JSON enforces nothing at all
  • A compatibility check belongs in CI, before a schema change reaches a deploy pipeline — not as a runtime surprise for whoever owns the consuming system
  • Consumer contract tests catch what a compatibility check on the schema alone cannot: a technically compatible schema change that still breaks a consumer’s actual logic
  • Dual-write with a defined deprecation window is the standard pattern for changes that are genuinely breaking and cannot be made compatible

A schema change that passes your own tests and breaks three other teams’ pipelines was never really tested — it was tested against the wrong consumer.


The producer team removed a field. legacy_region_code had been null for eight months in their own system — deprecated internally, unused, a clear candidate for cleanup. They removed it in a routine cleanup PR. Their own tests passed.
Three consuming pipelines broke that night. Two of them threw clear schema errors and failed loudly. The third didn’t fail at all — it had a .get(field, 'UNKNOWN') fallback, and silently started writing 'UNKNOWN' into a regional reporting table that finance used for tax jurisdiction calculations.
The two loud failures were fixed in an hour. The silent one ran for nine days before someone noticed a tax report with a suspicious number of transactions attributed to region ‘UNKNOWN’.
The field had been null in the producer’s system. It had not been unused everywhere else.

Every Schema Change Is a Potential Breaking Change

The producer team in the opening story did nothing careless by their own standards — the field was genuinely unused in their system, the change passed their tests, and the PR looked like routine cleanup. The failure wasn’t a lapse in diligence. It was the absence of a mechanism that would have surfaced the actual consumers of that field before the change shipped.

Schema evolution done safely isn’t about writing more careful code. It’s about having a system that makes the blast radius of a change visible before it happens, rather than discovering it from a downstream incident.


Forward and Backward Compatibility, Precisely Defined

These terms get used interchangeably in casual conversation and mean two specific, different things. Confusing them is how teams end up believing they’ve protected against breakage when they’ve only protected against half of it.

Backward Compatibility

A new schema is backward compatible if data written with the new schema can be read using the old schema. This is what protects existing consumers who haven’t upgraded yet — they keep working against new data without needing to change anything.

Old schema reads new data → backward compatible

Example: adding a field with a default value.
Old consumers ignore the new field entirely - they read
the fields they already know about, and the new field
simply doesn't exist from their point of view.

Forward Compatibility

A new schema is forward compatible if data written with the old schema can still be read using the new schema. This protects a consumer that upgrades before the producer has finished migrating — reading old data with new expectations and not breaking.

New schema reads old data → forward compatible

Example: a consumer upgrades to expect a new optional field.
It reads old records that don't have that field at all
and handles the absence gracefully rather than erroring.

Full Compatibility

Full compatibility requires both directions simultaneously — the safest and most restrictive guarantee, and the one worth defaulting to for any schema that has more than one consumer team.

Change type                          Backward  Forward  Full
Add field with default ✅ ✅ ✅
Add required field (no default) ❌ ✅ ❌
Remove field with a default ✅ ❌ ❌
Remove required field ❌ ❌ ❌
Widen numeric type (int → long) ✅ ✅ ✅
Narrow numeric type (long → int) ❌ ❌ ❌
Rename a field ❌ ❌ ❌

Removing legacy_region_code in the opening story falls into "remove field with a default" — backward compatible for the producer's own read path, but not forward compatible for any consumer whose logic depended on that field being present, even as a null.


Avro vs Parquet vs JSON for Schema Evolution

Avro - Built for Evolution

Avro was designed from the outset with schema evolution as a core requirement, and its compatibility rules are enforced structurally, not just by convention.

{
"type": "record",
"name": "PaymentEvent",
"fields": [
{"name": "event_id", "type": "string"},
{"name": "amount", "type": "double"},
{
"name": "risk_score",
"type": ["null", "double"],
"default": null
}
]
}

The ["null", "double"] union with an explicit default is Avro's idiomatic pattern for a safely-added optional field — old readers using a schema without risk_score simply never see it; new readers encountering old data get null rather than an error. Avro's schema resolution rules are well-specified and consistently implemented across the ecosystem, which is why it remains the default choice for Kafka-based event pipelines with many independent consumers.

Parquet - Evolution With Caveats

Parquet supports schema evolution, but the guarantees are looser and more implementation-dependent than Avro’s.

# Parquet schema merging — works, but has real limits
df_v1 = spark.read.parquet("s3://bucket/data/version=1/") # no risk_score column
df_v2 = spark.read.parquet("s3://bucket/data/version=2/") # has risk_score column

# mergeSchema handles the union of columns across files
combined = spark.read.option("mergeSchema", "true") \
.parquet("s3://bucket/data/")
# Rows from version=1 files show null for risk_score — this works

# What does NOT work cleanly: type changes across files
# If version=1 wrote amount as int and version=3 wrote it as string,
# mergeSchema does not resolve this gracefully — it typically fails
# or silently produces unexpected results depending on read order

mergeSchema handles additive changes reasonably well. It is not a substitute for a real compatibility contract — type changes, renames, and removals across a partitioned Parquet dataset can produce confusing failures that only surface when a query happens to touch files from both schema versions.

JSON - No Enforcement, All Risk

JSON has no schema at all unless one is imposed externally (JSON Schema, a Pydantic model, an Avro schema used alongside it). Every compatibility guarantee has to be built and enforced by the team using it — nothing in the format itself protects you.

# JSON gives you exactly this much protection: none
event = {"event_id": "abc123", "amount": 45.20}
# Nothing prevents the next event from being
# {"event_id": "abc123", "transaction_amount": 45.20}
# and nothing will tell you until a consumer breaks

If you are using JSON for event data with more than one downstream consumer, the compatibility enforcement described in the next section is not optional — it’s the only thing standing in for what Avro gives you natively.


Testing Schema Changes Before Deploying

Compatibility Checks in CI

The check that would have caught the opening story’s incident belongs in the producer’s CI pipeline, running against the actual consumer schemas — not just the producer’s own tests passing.

# ci/check_schema_compatibility.py
from confluent_kafka.schema_registry import SchemaRegistryClient

def check_compatibility(subject: str, new_schema_str: str) -> bool:
"""
Run in CI before a schema change is allowed to merge.
Checks the proposed schema against the registered compatibility
mode (BACKWARD, FORWARD, or FULL) for this subject.
"""

client = SchemaRegistryClient({"url": "http://schema-registry:8081"})

is_compatible = client.test_compatibility(
subject_name=subject,
schema=new_schema_str
)

if not is_compatible:
print(f"INCOMPATIBLE SCHEMA CHANGE for {subject}")
print("This change would break registered consumers.")
print("Review the change or coordinate a migration with consumer teams.")
return False

print(f"Schema change for {subject} is compatible — safe to deploy")
return True

# In the CI pipeline
with open("schemas/payment_event_v2.avsc") as f:
new_schema = f.read()

if not check_compatibility("payment-events-value", new_schema):
sys.exit(1) # block the merge

This single check, run automatically on every schema-touching PR, would have blocked the opening story’s field removal before it ever reached production — not because anyone was more careful, but because the check doesn’t rely on anyone remembering to be careful.

Consumer Contract Tests

A compatibility check on the schema alone confirms the schema is structurally compatible. It does not confirm a consumer’s actual business logic still behaves correctly — the exact gap that let the silent 'UNKNOWN' fallback in the opening story slip through undetected, since removing a field the schema marks as optional passes a structural compatibility check every time.

# consumer_contract_test.py — run in the CONSUMER's CI, using schemas
# published by the producer team, not just the producer's own tests

def test_regional_reporting_handles_missing_legacy_region_code():
"""
Explicitly test what THIS consumer does when a field
it depends on is absent — not just whether the schema allows it.
"""

event_without_field = {
"event_id": "test-1", "amount": 100.0
# legacy_region_code intentionally absent
}

result = process_regional_report(event_without_field)

# This is the test that would have caught the incident —
# asserting on ACTUAL behavior, not just "no exception was thrown"
assert result["region"] != "UNKNOWN", (
"Missing legacy_region_code should trigger a fallback lookup "
"by IP or account region, not a silent UNKNOWN — this field "
"is load-bearing for tax jurisdiction reporting"
)

This test lives with the consumer, runs against schemas the producer publishes, and is the layer that catches “structurally fine, functionally broken” — the failure category that a registry compatibility check alone will never see.


Migration Strategies for Breaking Changes

Some changes are genuinely breaking and cannot be made compatible — a field rename, a fundamental type change, a required semantic shift. These need an explicit migration, not a workaround.

Dual-Write Migration

# Phase 1: producer writes both old and new field simultaneously
event = {
"event_id": event_id,
"region_code": region, # new field name
"legacy_region_code": region, # old field name, kept during migration
}

# Phase 2: consumers migrate to the new field at their own pace,
# each team's migration independent of the others'

# Phase 3: once all registered consumers have confirmed migration
# (tracked explicitly — see below), the old field is dropped

The Deprecation Window

A dual-write migration only works if there’s a mechanism to know when it’s safe to stop. Without one, “temporary” dual-writing becomes permanent because nobody can confirm every consumer has moved on.

# Track consumer migration status explicitly — don't rely on tribal knowledge
CONSUMER_MIGRATION_STATUS = {
"fraud-model-pipeline": {"migrated": True, "confirmed_date": "2026-04-02"},
"regional-reporting": {"migrated": True, "confirmed_date": "2026-04-15"},
"legacy-analytics-batch": {"migrated": False, "confirmed_date": None},
}

def safe_to_drop_legacy_field() -> bool:
unmigrated = [
name for name, status in CONSUMER_MIGRATION_STATUS.items()
if not status["migrated"]
]
if unmigrated:
print(f"Cannot drop legacy field — pending consumers: {unmigrated}")
return False
return True

The opening story’s field removal happened precisely because no such tracking existed — the producer team had no visibility into who was still depending on legacy_region_code, and the only way to find out was for it to break in production.


The Schema Evolution Checklist

Compatibility understanding
□ Team knows the difference between backward and forward compatibility
□ Full compatibility is the default requirement for any multi-consumer schema
□ Compatibility mode is explicitly configured in the schema registry, not assumed
Format choice
□ Avro (or an equivalent enforced schema) is used for any event stream with more than one independent consumer
□ Parquet mergeSchema is treated as additive-only, not a substitute
for a real compatibility contract
□ JSON payloads have an externally enforced schema if used for
multi-consumer event data
Testing□ Schema compatibility check runs in CI, blocking incompatible  merges
□ Consumer contract tests exist for load-bearing fields, not just
structural schema checks
□ A "removed field" change is never treated as automatically safe
just because it's technically backward compatible
Migration
□ Breaking changes use dual-write with an explicit deprecation window
□ Consumer migration status is tracked explicitly, not assumed
□ A field is never dropped until every registered consumer
has confirmed migration

Final Takeaway

A schema change that passes the producer’s own tests has been tested against exactly one consumer — the producer itself. Every other team depending on that schema is a blast radius the producer can’t see without a mechanism designed specifically to make it visible.

Backward and forward compatibility are precise guarantees, not a vibe. Enforcing them — with a real compatibility check in CI, consumer contract tests for the fields that actually matter, and a tracked migration path for genuinely breaking changes — is what turns “we’ll be careful” into something that survives contact with a team that was, by their own account, being careful.

Core Principle

A field that is unused in your system is not the same claim as a field that is unused everywhere. Only the second one is safe to remove.

Next in Series

Building Data Contracts - A Practical Implementation Guide

Schema compatibility is enforced. Migrations are tracked.

Next: what a data contract actually contains beyond the schema itself — ownership, SLAs, semantic definitions, the tooling that exists today to implement one, and the harder problem underneath all of it: getting producer teams to actually adopt a contract instead of treating it as someone else’s process overhead.