name: avro-schema-evolution-audit
description: Audit Apache Avro writer-reader schema compatibility offline with binary encoding/decoding across defaults, numeric promotions, unions, aliases, enums, and direction rules.
category: Document Processing
source: antigravity
tags: [python, ai, agent, design, document, aws, cro]
url: https://github.com/sickn33/antigravity-awesome-skills/tree/main/skills/avro-schema-evolution-audit
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, and VARIANT semi-structured queries rather than Avro binary schema resolution.
data-engineer and data-engineering-data-pipeline: provide broad ETL, Kafka, and lakehouse architecture patterns without executable Avro wire-compatibility checks.
event-sourcing-architect and event-store-design: model CQRS aggregates, projections, and snapshotting without testing Avro writer/reader binary evolution rules.
When to Use
- Reviewing an Avro
.avsc schema 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, and enum symbol evolution (default fallback 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 Python 3.12.10, fastavro==1.13.1, and pytest==9.1.1).
- Synthetic or sanitized writer/reader
.avsc JSON 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 using fastavro.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: raises SchemaResolutionError on 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).
- Numeric promotions & narrowing:
- Avro
1.12.0 permits int -> long/float/double, long -> float/double, float -> double; narrowing (long -> int, double -> float, double -> long) must raise SchemaResolutionError.
- Unions (
[...]):
- Test every relevant union branch independently (
null branch passing never proves non-null branches like long vs. string resolve!).
- Aliases & enums:
- Verify
aliases remaps renamed fields during binary resolution.
- Verify enum symbol additions and reader enum
default fallback ("default": "UNKNOWN") vs. SchemaResolutionError when an unmapped symbol arrives.
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 genuine fastavro.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 => backward PASS, forward NOT_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 genuine SchemaResolutionError compatibility failures (invalid_inputs vs resolution_errors).
Explicitly note:
- Pairwise sample-only limitation preserved: a passing test on a single schema pair
(v1, v2) or subset of sample records **ca
1---2name: avro-schema-evolution-audit3description: Audit Apache Avro writer-reader schema compatibility offline with binary encoding/decoding across defaults, numeric promotions, unions, aliases, enums, and dire4---5---6name: avro-schema-evolution-audit7description: Audit Apache Avro writer-reader schema compatibility offline with binary encoding/decoding across defaults, numeric promotions, unions, aliases, enums, and direction rules. 8category: Document Processing9source: antigravity10tags: [python, ai, agent, design, document, aws, cro]11url: https://github.com/sickn33/antigravity-awesome-skills/tree/main/skills/avro-schema-evolution-audit12---131415# Avro Schema Evolution Audit1617## Overview1819Verify 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.2021Distinction from existing data and event-sourcing skills:22- `snowflake-development`: covers Snowflake SQL, Snowpark, and `VARIANT` semi-structured queries rather than Avro binary schema resolution.23- `data-engineer` and `data-engineering-data-pipeline`: provide broad ETL, Kafka, and lakehouse architecture patterns without executable Avro wire-compatibility checks.24- `event-sourcing-architect` and `event-store-design`: model CQRS aggregates, projections, and snapshotting without testing Avro writer/reader binary evolution rules.2526## When to Use2728- Reviewing an Avro `.avsc` schema change before publishing producers or upgrading consumers.29- Testing added fields with/without defaults, removed fields, numeric widening vs. disallowed narrowing, union branch evolution, field `aliases`, and `enum` symbol evolution (`default` fallback vs. resolution error).30- Verifying backward (`old writer -> new reader`) and forward (`new writer -> old reader`) behavior locally before CI or staging rollout.31- Do **not** use this skill to connect to production Confluent/AWS Glue Schema Registries or modify live compatibility settings.3233## Prerequisites3435- Python 3.10+ with `fastavro` (tested with Python `3.12.10`, `fastavro==1.13.1`, and `pytest==9.1.1`).36- Synthetic or sanitized writer/reader `.avsc` JSON schemas and representative sample records covering every union branch and enum symbol under test.37- **No production schema registry access, network requests, or live brokers required.**3839## How It Works4041### 1. Encode and decode real Avro binary frames42431. Parse both schemas with `fastavro.parse_schema(...)` so invalid JSON or unknown types raise structured parse errors (`SchemaParseException` / `UnknownType` / `ValueError`).442. Encode each sample record with `fastavro.schemaless_writer(buf, writer_schema, record)` and decode using `fastavro.schemaless_reader(buf, writer_schema, reader_schema)`.4546### 2. Test both evolution directions and union branches4748Run the local verification suite in [avro evolution harness](references/avro-evolution-harness.md):49501. **Field addition & removal:**51 - Added reader field with valid `default`: decodes old writer bytes with exact default (**backward compatible**).52 - Added required field without `default`: raises `SchemaResolutionError` on old writer data.53 - Removed field: new reader drops absent field cleanly (**backward**), while old reader without a default fails on new writer data (**forward broken**).542. **Numeric promotions & narrowing:**55 - Avro `1.12.0` permits `int -> long/float/double`, `long -> float/double`, `float -> double`; narrowing (`long -> int`, `double -> float`, `double -> long`) must raise `SchemaResolutionError`.563. **Unions (`[...]`):**57 - Test **every relevant union branch** independently (`null` branch passing never proves non-null branches like `long` vs. `string` resolve!).584. **Aliases & enums:**59 - Verify `aliases` remaps renamed fields during binary resolution.60 - Verify enum symbol additions and reader enum `default` fallback (`"default": "UNKNOWN"`) vs. `SchemaResolutionError` when an unmapped symbol arrives.6162### 3. Classify compatibility honestly (never overclaim transitivity)6364Represent **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:6566- **`PASS`**: valid schema + ≥1 tested sample in that direction + every tested sample resolved.67- **`FAIL`**: valid schema + ≥1 tested sample produced a genuine `fastavro.read.SchemaResolutionError`, no invalid inputs.68- **`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 => backward `PASS`, forward `NOT_TESTED`.69- **`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 genuine `SchemaResolutionError` compatibility failures** (`invalid_inputs` vs `resolution_errors`).7071Explicitly note:72- **Pairwise sample-only limitation preserved:** a passing test on a single schema pair `(v1, v2)` or subset of sample records **ca