> ## Content Index
> Fetch the complete content index at: https://datajutsu.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# An Avro Reader Matches Fields by Name (and the Long That Fits in an Int Still Throws)
- URL: https://datajutsu.com/avro-schema-evolution/
- Published: 2026-10-23T23:10:21.000Z
- Updated: 2026-10-23T23:10:21.000Z
- Author: Data Jutsu

A record does not stay the same shape for long. Someone adds a field, the old writers keep running, and the new reader has to read bytes the old writer never had to produce. Avro has a name for this and a mechanism for it: the reader and writer schemas are matched by field name, and the match is what decides what you get. I measured it both directions. The writer has name and age, the reader adds email with a default of none, and the decode comes back with email filled in as none from the reader's own schema. The reader adds score instead, with no default, and the decode throws, no matching field for default-less U.score, naming the field. So the addition rule is one sentence: a new field may join the schema, but only if it carries a default, and the default is what gets written into the record the old writer left behind. An addition without a default is not a guess, it is an error.

The removal side does the opposite of throwing. The writer carries a field the reader has dropped, and the value is still sitting in the bytes, and the decode simply does not include it. I wrote a record with a secret field set to s3cret, decoded it under a reader schema with no secret, and the object that came back was just a:1, no key, no placeholder, and the JSON form of it is the same, the field is gone. So the two directions fail in different voices: a field the reader wants but the writer lacks is loud, a field the writer had but the reader lost is silent. That asymmetry is the one to remember when a record in production stops carrying something nobody remembers removing. The bytes still have it. The reader just does not.

When the field name matches but the type changed, the resolver is not a type system, and the only conversions it allows are widenings inside a family. I measured the whole table. int to long works, 123456789 round trips, float to double works, int to double works. Everything else throws with the two type names in the message. long to int throws, and that is the one that surprises people, because I used 300, a value that fits inside an int with room to spare, and it still says cannot read long as int. The resolver does not check the value, it checks the declared type, so a narrowing that would survive is refused along with the one that would overflow. double to float throws, string to int throws, int to string throws, int to the enum throws, the enum to int throws, boolean to int throws. And a default does not rescue an incompatible type: the writer's int field matched by name to the reader's string field that has a default of dflt, and it still threw cannot read int as string. The default only applies when there is no field to read, not when the field is the wrong shape.

The same rules run inside nested things, because the matching walks the whole tree. A nested record with an inner field added and given a default decodes with the inner default filled in, the outer record matched by name without a hitch and the inner one did the same. The nested record with the inner field added and no default throws, no matching field for default-less I.b, and the outer match does not save it. An array of records behaves the same at the element level: the element schema gains a field without a default and the whole decode throws on the element, E.tag named in the message. Complex defaults work the same as scalar ones: an array of strings with a default of the empty array comes back empty, a nested record with a default of an object comes back as that object. The tree is walked to the bottom, and every level gets the same one-sentence rule.

What happens when the reader does not have the writer's schema is the answer to why the file format ships one in the header. Without the resolver, fields are matched by position, because the bytes carry no names. I wrote a record with a and b, both ints, a is 9 and b is 7, the bytes are 12 0e, and I decoded them under a reader schema that declares b first and a second. The object that came back is b:9, a:7, both values present, both swapped, no error. If the two reordered fields are different types, the framing does not line up and the decode throws truncated buffer instead. So the positional path swaps same types silently and only gets loud when the types disagree. In protobuf, the field number is the identity and it is on the wire, so a reorder shows up in a diff as a breaking change before anything is written. In Avro the identity is the name, the name is not in the bytes, and the only thing protecting you is the resolver running, which needs both schemas in front of it at once.

Union fields are where the matching is strictest, because the branch order is part of the type. A writer whose field is a union and a reader whose field is a plain string throws, cannot read null as string, whether the value that was written was on the set branch or the null branch. Reordering the branches of the same union fails before any bytes are read: the schema itself is rejected with a message that the union defaults must match the first branch's type, because the default is pinned to whatever branch is listed first, and moving the branches moves the default off its branch. The byte-level mechanics of the branch index, what a reordered union writes and why the index is the only self-describing thing in the stream, are in the [union post](https://datajutsu.com/avro-union-branch-index/), and the float and integer comparison of the same record across the two formats is in the [avro versus protobuf post](https://datajutsu.com/avro-vs-protobuf-bytes/). The protobuf side of this, at [proto.datajutsu.com](https://proto.datajutsu.com/?ref=datajutsu.com), is where the field-number version of this exact question gets answered against the real bytes.