advanced24 min studyLesson 331 in Engineering

Check schema compatibility in the actual reading direction

Build reader-writer compatibility tests while separating structural decoding, default values, and the meaning of AI training features.

On this page

What you’ll understand

  • Specify which readers must consume which writer versions.
  • Explain directional type promotion and reader defaults using Avro.
  • Distinguish decoding compatibility from a stable feature interpretation.

A training pipeline adds a feature, widens an integer, and announces that its schema is compatible. Compatible with which reader and which stored data? A rolling deployment may contain several reader versions while an archive retains several writer versions. The contract must describe that matrix, not just approve the newest pair. Structural decoding is also only the beginning: a feature can retain its type while changing units, meaning, or missing-value behavior in a way that invalidates a model.

Name both sides of the contract

The writer schema describes how a record was encoded; the reader schema describes what the consuming application expects. In Avro, resolution relates those two schemas according to explicit rules. For example, a writer int can be promoted to a reader long, but a writer long is not generally compatible with a reader int merely because one sample happens to fit. Field names, unions, enum symbols, and defaults have their own rules. Pin the format version and implementation behavior used by your pipeline rather than assuming every serialization format gives the same meaning to adding or removing a field.

Backward compatibility commonly means that a new reader accepts older written data, while forward compatibility commonly means an older reader accepts new data. State those directions explicitly because terminology and transitive policies differ between tools. A canary that exercises only the newest writer and newest reader can miss failures in archived shards or lagging consumers. Inventory the writer versions actually present and the reader versions still supported. Compatibility is a property of each required pair, so an old reader that is deliberately retired should leave the support policy through an explicit migration rather than disappear from a test accidentally.

Cr,w=1{reader r resolves writer w}C_{r,w}=\mathbf1\{\text{reader }r\text{ resolves writer }w\}
C is a dimensionless compatibility indicator for a specified format and schema-resolution contract. Required reader-writer pairs must be checked individually; a sample record decoding successfully is weaker than schema-level compatibility.↔ Scroll wide equations horizontally.

Defaults do not supply missing scientific meaning

An Avro reader default supplies a value when an expected reader field is absent from the writer schema. It does not make that field optional when encoding against a writer schema that declares it. A nullable type, an absent field, and a default are therefore distinct concepts. Other validation systems have different semantics; for example, JSON Schema's default annotation should not be assumed to insert data during validation. Test the actual reader and validator instead of relying on a generic intuition that the word default guarantees a value appears everywhere.

A structurally valid default can still distort learning. Filling an unknown account age with zero can make missing history look like a new account; replacing a missing region with the most common region can alter cohort statistics. Record units, allowed values, null meaning, feature provenance, and semantic version alongside types. A change from seconds to milliseconds retains an integer type but changes values by a factor of one thousand. Likewise, reusing a category code for a new class may decode perfectly while silently changing labels. Contract review must include representative downstream calculations and quality checks, not only parser acceptance.

xmilliseconds=1000 xsecondsx_{\mathrm{milliseconds}}=1000\,x_{\mathrm{seconds}}
The numeric conversion assumes both fields measure the same duration and the stated units. An unchanged integer schema does not encode or enforce this semantic conversion.↔ Scroll wide equations horizontally.

Deploy a migration that includes stored history

Keep immutable copies of supported writer schemas and pair them with archived files or a reliable schema identifier. Plan a rollout order, such as readers able to consume both forms before switching writers, with rollback behavior for the archive already produced. If a change cannot preserve required pairs, publish a new dataset or explicitly transform history instead of labeling an incompatible file as the old version. Test extreme numeric values and enum symbols in addition to typical samples. A parser success rate should identify which writer versions were exercised and which failures were excluded.

The probability lab illustrates limited test discovery, not schema resolution. For each separate configuration, Reset, set both success probability p and trial count n, predict the zero-discovery bar, then inspect. Interpret success as an independently selected test exposing a defect, and compare p=0.1, n=10 with p=0.1, n=30. More trials reduce the modeled chance of missing the defect, but do not establish that untested writer-reader pairs are compatible. Real test selection is rarely independent with a known discovery probability; deterministic required-pair tests remain the direct evidence for the migration contract.

A widening change has two directions

An archive has 600 Avro records from writer W1 with an int feature, and 400 from W2 with a long feature plus a new source field. Reader R1 expects the int feature; R2 expects long and defines a valid source default for old data. Assume matching record names and no other differences.

  1. R2 can read W1 by promoting int to long and supplying its reader default for the absent source field. The default addresses decoding, not whether the substituted source is scientifically appropriate.

  2. R2 can read W2 directly. R1 can read W1, but the stated long-to-int direction for W2 is not an allowed general promotion, even if all 400 observed values happen to be small.

  3. R1 therefore lacks support for 400 of the 1000 archived records, or 40%, under this schema policy. R2 covers all 1000 required records structurally; downstream semantic checks remain separate.

The result

A directional compatibility matrix exposes the old reader’s unsupported 40% of the archive, while a newest-reader-only test would hide that migration problem.

Explore the model

Interactive lab

Interactive lab · probability

Discovery probability is not schema compatibility

For each separate view: Reset, set both p and n, predict the zero-discovery bar, then inspect. Compare p=0.1, n=10 and p=0.1, n=30. This exact binomial model assumes independent tests with a common hypothetical defect-discovery probability; it does not decode schemas or generate random tests.

Discovery probability is not schema compatibilityThese are exact binomial probabilities for independent trials with one fixed success probability. Playback tours the distribution; it does not resample outcomes. Current readings: Mean · np: 5; Variance · np(1−p): 2.5; Total probability: 1. All parameters are adjustable with the labeled controls below.03581000.070.150.220.3Successes kP(X = k)k = 0 · P = 9.77e-4
Exact probabilityHighlighted outcomeMean np
Mean · np
5
Variance · np(1−p)
2.5
Total probability
1
t = 0 s

These are exact binomial probabilities for independent trials with one fixed success probability. Playback tours the distribution; it does not resample outcomes. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forTesting more examples can reduce a modeled miss probability without covering an omitted reader-writer pair or proving unchanged feature meaning.

Check your understanding

An Avro writer changes int to long. Which claim is justified by the stated promotion rule?

Try it yourself

A field keeps the integer type but changes from seconds to milliseconds. An old consumer interprets stored value 5000 as seconds although the writer meant 5 seconds. What factor is the interpretation error, and what contract information would catch it?

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

Compare 5000 seconds with 5 seconds rather than only checking that both are valid integers.

Compare with the solution

The interpreted duration is 1000 times the intended duration. Explicit units, semantic versioning, conversion tests, and downstream feature checks would expose the change; structural integer validation alone would not.

Take it with you

  • Compatibility is a relation between supported readers and actual writer versions.
  • Defaults, nullability, and absent fields have format-specific meanings.
  • Successful decoding does not prove stable units, categories, or training semantics.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.