Blog

How to read Protobuf messages in Kafka, with or without a registry

Why Protobuf records in Kafka look like unreadable bytes, how the Schema Registry wire format frames them, and how to decode them from local .proto files.

· 6 min read

KafkaProtobufSchema RegistrySerialization

You open a topic to check one order, and the value column shows a few readable letters between control characters. The record is fine. It's Protobuf, and Protobuf is a binary format that doesn't carry its own field names. To read it properly, you need the schema it was written with.

That schema reaches a reader in one of two ways: through a Schema Registry, or as .proto files you have on disk. This post explains what's in the bytes in each case, how to decode them from the command line, and the traps that make a decoded record look right when it isn't.

Protobuf stores field numbers, not names

Each field in an encoded Protobuf message is a tag and a value. The tag is the field's number and its wire type. The names in your .proto file, and the name of the message itself, aren't in the bytes at all. The Protobuf docs say a field's name and declared type can only be determined on the decoding end.

So the three bytes 08 96 01 only say "field 1 is the number 150". Whether that's an order ID or an amount depends on the message you decode it as.

The same bytes decode as either message. Only the schema tells you which one they are.

Leaving names out keeps Protobuf compact, and it's why decoding with the wrong message can succeed without an error. Keep it in mind for the rest of this post.

Records written through a Schema Registry

If your producers use Confluent's Protobuf serializer, or one compatible with it, by default each record starts with a few bytes before the Protobuf payload:

  • Byte 0 is 0. Confluent's docs call it the version byte; most tools call it the magic byte.
  • Bytes 1–4 are the schema ID the registry assigned, big-endian.
  • Then, for Protobuf only, the message indexes: which message in the schema file this record is. They're zigzag varints, and the common case, the first message in the file, is written as a single 0.
A framed record names its schema and message. A plain one is just the payload.

These bytes are why a registry-aware reader needs no setup per topic: it reads the ID, fetches that schema from the registry, follows the message index and decodes.

The schema ID finds the schema, the message index finds the message, and the payload becomes JSON.

By default the serializer registers schemas under the subject <topic>-value (and <topic>-key for keys).

To see whether a topic is framed, look at the first bytes of one record:

kcat -b broker:9092 -C -t orders -c 1 -e -f '%s' | xxd | head -n 1
A value that starts with 00 and four more bytes was most likely written through a registry. kcat starts from the oldest record unless you pass -o.

Confluent's kafka-protobuf-console-consumer prints framed records as JSON when you pass --property schema.registry.url=<your registry>.

Records written without a registry

Some teams skip the registry and send the bytes their generated classes produce, such as toByteArray() in Java or proto.Marshal in Go. Those records are the payload alone. Nothing in them says which message they are, so the reader has to know, and has to have the right .proto files.

With protoc you can decode one record by naming the message:

kcat -b broker:9092 -C -t orders -c 1 -e -f '%s' \
  | protoc --proto_path=protos --decode=shop.v1.Order protos/shop/v1/order.proto
protoc prints the message in Protobuf's text format. --decode_raw prints field numbers and values, with no names.

This only works on records written without a registry. protoc doesn't know about the registry's bytes at the start of a framed record and fails on them, or decodes nonsense.

Web UIs that run on a server can also read .proto files. In Kafbat UI you point the ProtobufFile serde at a directory and map topics to messages with protobufMessageNameByTopic. In Redpanda Console you list paths or a Git repository under serde.protobuf and add a mapping per topic. Both are set in the server's config by whoever runs it (as documented on 2026-10-31).

Three things that go wrong

  • Imports. A schema that says import "common/money.proto"; only compiles if the decoder finds that file under that path. Point the include path at the root your build uses, not at the folder of one file. Google's well-known types, such as google/protobuf/timestamp.proto, are found automatically when protoc is installed with its include folder.
  • The wrong message. If you decode a Refund as an Order, matching field numbers fill in the wrong names, and the rest become unknown fields. Most JSON output leaves unknown fields out, so you see a tidy record that's wrong.
  • Stale files. A producer that added field 9 last week writes bytes your older .proto doesn't know. The parser keeps them as unknown fields, which is safe for reading, but JSON output leaves them out, so the field is missing from what you see. Decode with the files the producer was built from.

Reading Protobuf in Offvio

Offvio decodes both kinds of record on your computer, with nothing to configure on a server.

With a Schema Registry

Add the registry to the connection, and Offvio reaches it on the same route as the brokers, SSH tunnels included. Choose Show as → Schema Registry in the messages view. Keys and values are decoded separately by their schema ID, the message index is followed into nested messages, and schema references resolve as imports. A record that can't be decoded shows why in its own row, and the other rows still read.

The same switch reads Avro and JSON Schema, and it works with Redpanda's built-in registry, which has no GET /schemas endpoint. Offvio reads the schema ID from the start of the record; it doesn't read the newer __value_schema_id header, so records written that way aren't decoded through the registry.

With local .proto files

For topics written without a registry, choose Show as → Protobuf (.proto), then Import .proto Files… and pick every file the schema imports. Offvio compiles them together and lists the messages they define; pick the one the topic holds. The files are kept with the connection, so the next time you open it they're already there.

  • Imports across folders. Offvio keeps each picked file by its name. If order.proto imports common/money.proto, the money.proto you picked from any folder fills that import, so two picked files can't share a name. Well-known types are built in.
  • A warning for the wrong message. When the bytes contain fields the chosen message doesn't define, the row shows a warning instead of the record: it was decoded as that message, but some fields aren't in it, so it may be the wrong message type. Offvio can't catch a message whose field numbers all happen to fit, so no warning isn't proof.
  • Errors you can act on. If the files you pick don't compile, Offvio shows the compiler's error and keeps the files you had before.
  • Live tail keeps its place. Switching a Live tail to Schema Registry or to a .proto message restarts it from where it was, and says so. Rows already on screen keep the old decoding.
You don't have to rebuild the folder layout: a picked file fills the import that names it.

Producing Protobuf

In the Produce dialog, choose a registry subject or a local message as the value's schema, and type the value as JSON. Offvio checks it against the message and encodes it, with the registry's bytes in front when you chose a subject. With a subject, it encodes the first message in that schema. Local .proto messages encode values; keys take registry subjects.

More on reading messages in Offvio.

What about Avro?

Avro records written through a registry start with the same five bytes, without a message index, and Offvio decodes them with the same Show as → Schema Registry. Values show as plain JSON in the schema's field order, without Avro's {"string": …} wrappers around union values, so the same record always reads the same way. Separately, exports can be saved as an Avro container file. That file uses Offvio's own record layout (topic, partition, offset, timestamp, headers, and the key and value as raw bytes), not your topic's schema, and Offvio can import it again.

Recap

  • Protobuf bytes hold field numbers, not names. You need the schema to read them.
  • By default, a registry-framed record starts with 0, a 4-byte schema ID and, for Protobuf, a message index. Newer Confluent clients can put the schema in a header instead.
  • A record written without a registry is the payload alone; the reader must know the message.
  • Decoding with the wrong message or stale files can succeed and still be wrong.
  • Offvio reads both from your computer: through the connection's registry, or from .proto files you pick.

Sources

Early access

Be first on version 1.0. We'll email you when it ships.