Skip to content

[release-2.8] backend: migrate avro library from hamba/avro to twmb/avro - #2620

Open
r-vasquez wants to merge 1 commit into
release-2.8from
2.8-migrate-avro
Open

[release-2.8] backend: migrate avro library from hamba/avro to twmb/avro#2620
r-vasquez wants to merge 1 commit into
release-2.8from
2.8-migrate-avro

Conversation

@r-vasquez

@r-vasquez r-vasquez commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

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

image

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.
@r-vasquez r-vasquez changed the title backend: migrate avro library from hamba/avro to twmb/avro [release-2.8] backend: migrate avro library from hamba/avro to twmb/avro Aug 28, 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\"]}}]}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why change this? Is this a real difference in the libraries?

@r-vasquez r-vasquez Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
r-vasquez enabled auto-merge September 2, 2026 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants