avro-schema-evolution-audit
Audit Apache Avro writer-reader schema compatibility offline with binary encoding/decoding across defaults, numeric promotions, unions, aliases, enums, and direction rules.
Try your first task
A source-grounded starter task has not been verified for this skill yet.
SKILL.md
name: avro-schema-evolution-auditdescription: "Audit Apache Avro writer-reader schema compatibility offline with binary encoding/decoding across defaults, numeric promotions, unions, aliases, enums, and direction rules."category: datarisk: safesource: selfsource_type: selfdate_added: "2026-12-01"author: Koushik-Katkamtags: [avro, schema-evolution, serialization, compatibility, fastavro, testing]Avro Schema Evolution Audit
Overview
Verify Apache Avro writer-reader schema evolution offline using real binary encoding and decoding (fastavro.schemaless_writer and fastavro.schemaless_reader) grounded in the Apache Avro 1.12.0 schema resolution specification. Tests concrete schema changes in both directions (old writer -> new reader and new writer -> old reader), asserts exact decoded payloads and SchemaResolutionError failures, and separates pairwise compatibility checks from transitive registry guarantees.
Distinction from existing data and event-sourcing skills:
snowflake-development: covers Snowflake SQL, Snowpark, andVARIANTsemi-structured queries rather than Avro binary schema resolution.data-engineeranddata-engineering-data-pipeline: provide broad ETL, Kafka, and lakehouse architecture patterns without executable Avro wire-compatibility checks.event-sourcing-architectandevent-store-design: model CQRS aggregates, projections, and snapshotting without testing Avro writer/reader binary evolution rules.
When to Use
- Reviewing an Avro
.avscschema change before publishing producers or upgrading consumers. - Testing added fields with/without defaults, removed fields, numeric widening vs. disallowed narrowing, union branch evolution, field
aliases, andenumsymbol evolution (defaultfallback vs. resolution error). - Verifying backward (
old writer -> new reader) and forward (new writer -> old reader) behavior locally before CI or staging rollout. - Do not use this skill to connect to production Confluent/AWS Glue Schema Registries or modify live compatibility settings.
Prerequisites
- Python 3.10+ with
fastavro(tested with Python3.12.10,fastavro==1.13.1, andpytest==9.1.1). - Synthetic or sanitized writer/reader
.avscJSON schemas and representative sample records covering every union branch and enum symbol under test. - No production schema registry access, network requests, or live brokers required.
How It Works
1. Encode and decode real Avro binary frames
- Parse both schemas with
fastavro.parse_schema(...)so invalid JSON or unknown types raise structured parse errors (SchemaParseException/UnknownType/ValueError). - Encode each sample record with
fastavro.schemaless_writer(buf, writer_schema, record)and decode usingfastavro.schemaless_reader(buf, writer_schema, reader_schema).
2. Test both evolution directions and union branches
Run the local verification suite in avro evolution harness:
- Field addition & removal:
- Added reader field with valid
default: decodes old writer bytes with exact default (backward compatible). - Added required field without
default: raisesSchemaResolutionErroron old writer data. - Removed field: new reader drops absent field cleanly (backward), while old reader without a default fails on new writer data (forward broken).
- Added reader field with valid
- Numeric promotions & narrowing:
- Avro
1.12.0permitsint -> long/float/double,long -> float/double,float -> double; narrowing (long -> int,double -> float,double -> long) must raiseSchemaResolutionError.
- Avro
- Unions (
[...]):- Test every relevant union branch independently (
nullbranch passing never proves non-null branches likelongvs.stringresolve!).
- Test every relevant union branch independently (
- Aliases & enums:
- Verify
aliasesremaps renamed fields during binary resolution. - Verify enum symbol additions and reader enum
defaultfallback ("default": "UNKNOWN") vs.SchemaResolutionErrorwhen an unmapped symbol arrives.
- Verify
3. Classify compatibility honestly (never overclaim transitivity)
Represent each direction separately as PASS, FAIL, NOT_TESTED, or INVALID_INPUT (backward_status, forward_status); classification is a truthful pairwise "<backward>/<forward> (pairwise samples only)" summary:
PASS: valid schema + ≥1 tested sample in that direction + every tested sample resolved.FAIL: valid schema + ≥1 tested sample produced a genuinefastavro.read.SchemaResolutionError, no invalid inputs.NOT_TESTED: no samples provided in that direction. Absent evidence is not failed compatibility; do not classify untested directions as incompatible. Both lists empty =>NOT_TESTED/NOT_TESTED; valid old + no new => backwardPASS, forwardNOT_TESTED.INVALID_INPUT: invalid schema (SchemaParseException/UnknownType/ValueError/KeyError/TypeError) or invalid record input (not a valid record for the writer schema;ValidationError/TypeError/ValueError/KeyError). Invalid schema/record inputs are distinguished from genuineSchemaResolutionErrorcompatibility failures (invalid_inputsvsresolution_errors).
Explicitly note:
- Pairwise sample-only limitation preserved: a passing test on a single schema pair
(v1, v2)or subset of sample records cannot prove structural compatibility across all possible records or untested union branches, nor transitive compatibility (BACKWARD_TRANSITIVE,FORWARD_TRANSITIVE,FULL_TRANSITIVE) across[v0, v1, v2, ...]histories. Do not claim structural or transitive compatibility.
Examples
Run the self-contained suite in avro evolution harness:
User request: "Check whether adding 'currency' and renaming 'amount' breaks our order-event Avro consumers."
Inputs: Pairwise writer/reader .avsc schemas and representative union/enum samples.
Expected result: Backward checks decode defaults and aliased fields cleanly; missing defaults and incompatible
numeric narrowing raise SchemaResolutionError; union checks test both null and non-null branches separately;
report labels output as pairwise sample compatibility only (not universal or transitive).
Limitations
- Pairwise binary sample testing only proves resolution for the inspected schema pair and exercised branches; schema registries (
BACKWARD_TRANSITIVE,FORWARD_TRANSITIVE,FULL_TRANSITIVE) check full structural equivalence rules across every prior version. - Uses
fastavro(1.13.1) Python resolution; language bindings (Java Apache AvroSchemaCompatibility, C++, Go) may enforce subtle default-type or logical-type validations differently. - Logical types (
decimal,timestamp-millis,uuid) and schema-fingerprint wire framing (e.g., Confluent 5-byte magic prefix) are outside the rawschemaless_*resolution scope unless explicitly wrapped.
Safety and Side Effects
- Strictly offline and read-only over local/synthetic schemas and in-memory
BytesIObuffers. - Never connects to production schema registries, alters subject compatibility policies (
PUT /config), or outputs unredacted private schemas/records.