[release-2.8] backend: migrate avro library from hamba/avro to twmb/avro - #2620
Open
r-vasquez wants to merge 1 commit into
Open
[release-2.8] backend: migrate avro library from hamba/avro to twmb/avro#2620r-vasquez wants to merge 1 commit into
r-vasquez wants to merge 1 commit into
Conversation
Replace hamba/avro and linkedin/goavro with twmb/avro v1.8.0 across the serde and schema packages. The serde now decodes with Schema.Decode and renders payloads with the schema-aware Schema.EncodeJSON: bytes and fixed fields encode as \u00XX strings, NaN and Infinity encode as strings instead of failing, and logical-type durations keep their original millis or micros values. JSON input is serialized through Schema.DecodeJSON, removing the goavro codec. Schema references now parse into a per-call avro.SchemaCache rather than a process-global cache, with a cycle guard and support for diamond-shaped reference graphs. Schemas that under-declare references and only parsed through global cache pollution now fail deterministically. The frontend JSON viewer gains an escapeLatin1 prop, enabled for avro payloads, so \u00XX byte escapes survive display and copy-paste instead of being converted to UTF-8 glyphs. GetAvroSchemaByID returns *avro.Schema and ParseAvroSchemaWithReferences drops its schemaCache parameter.
Mateoc
approved these changes
Sep 2, 2026
graham-rp
approved these changes
Sep 2, 2026
| }) | ||
|
|
||
| actual, err := s.GetAvroSchemaByID(context.Background(), 1000) | ||
| expectedSchemaString := "{\"name\":\"parent.schema\",\"type\":\"record\",\"fields\":[{\"name\":\"reference\",\"type\":{\"name\":\"referenced.schema\",\"type\":\"enum\",\"symbols\":[\"FOO\"]}}]}" |
Contributor
There was a problem hiding this comment.
why change this? Is this a real difference in the libraries?
Contributor
Author
There was a problem hiding this comment.
Yes, twmb/avro does a key reordering alphabetically (fields > name > type)
{
"fields": [
{
"name": "reference",
"type": {
"name": "schema",
"namespace": "referenced",
"symbols": [
"FOO"
],
"type": "enum"
}
}
],
"name": "parent.schema",
"type": "record"
}While hamba/avro does not, it's always name>type>fields for them:
{
"name": "parent.schema",
"type": "record",
"fields": [
{
"name": "reference",
"type": {
"name": "referenced.schema",
"type": "enum",
"symbols": [
"FOO"
]
}
}
]
}
r-vasquez
enabled auto-merge
September 2, 2026 17:18
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace hamba/avro and linkedin/goavro with twmb/avro v1.8.0 across the serde and schema packages.
The serde now decodes with Schema.Decode and renders payloads with the schema-aware Schema.EncodeJSON: bytes and fixed fields encode as \u00XX strings, NaN and Infinity encode as strings instead of failing, and logical-type
durations keep their original millis or micros values. JSON input is serialized through Schema.DecodeJSON, removing the goavro codec.
Schema references now parse into a per-call avro.SchemaCache rather than a process-global cache, with a cycle guard and support for diamond-shaped reference graphs. Schemas that under-declare references and only parsed through global cache pollution now fail deterministically.
The frontend JSON viewer gains an escapeLatin1 prop, enabled for avro payloads, so \u00XX byte escapes survive display and copy-paste instead of being converted to UTF-8 glyphs.
GetAvroSchemaByID returns *avro.Schema and ParseAvroSchemaWithReferences drops its schemaCache parameter.
Functional ports of #2271, #2351, #2606, and #2425
Example
Using rpk to show that the messages are serialized, and next to it Console successfully deserializing the payload